1 /**
2 * Copyright 2005-2012 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.edl.impl.xml.export;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import javax.xml.namespace.QName;
22
23 import org.kuali.rice.core.api.impex.ExportDataSet;
24 import org.kuali.rice.edl.impl.bo.EDocLiteAssociation;
25
26 /**
27 * A utility class for managing an {@link ExportDataSet} containing EDocLite
28 * data. Provides a mechanism to convert instances of this class to a
29 * populated {@link ExportDataSet}.
30 *
31 * @see ExportDataSet
32 *
33 * @author Kuali Rice Team (rice.collab@kuali.org)
34 */
35 public class EdlExportDataSet {
36
37 public static final QName EDOCLITES = new QName("EDL", "eDocLites");
38
39 private List<EDocLiteAssociation> edocLites = new ArrayList<EDocLiteAssociation>();
40
41 public List<EDocLiteAssociation> getEdocLites() {
42 return edocLites;
43 }
44
45 /**
46 * Populates the given {@link ExportDataSet} with the data from this data set.
47 *
48 * @param exportDataSet the data set to populate the data into
49 */
50 public void populateExportDataSet(ExportDataSet exportDataSet) {
51 if (edocLites != null && !edocLites.isEmpty()) {
52 exportDataSet.addDataSet(EDOCLITES, edocLites);
53 }
54 }
55
56 /**
57 * Converts this data set to a standard {@link ExportDataSet}, populating
58 * it with the data from this data set.
59 *
60 * @return the populated ExportDataSet
61 */
62 public ExportDataSet createExportDataSet() {
63 ExportDataSet exportDataSet = new ExportDataSet();
64 populateExportDataSet(exportDataSet);
65 return exportDataSet;
66 }
67
68 /**
69 * A static utility for creating a {@link EdlExportDataSet} from an
70 * {@link ExportDataSet}. This method will only populate the returned
71 * EdocLite data set with EdocLite data from the given export data set. The
72 * rest of the data in the given export data set will be ignored.
73 *
74 * @param exportDataSet the ExportDataSet to pull EdocLite data from
75 * @return a StyleExportDataSet with any EdocLite data from the given exportDataSet populated
76 */
77 public static EdlExportDataSet fromExportDataSet(ExportDataSet exportDataSet) {
78 EdlExportDataSet edlExportDataSet = new EdlExportDataSet();
79
80 List<EDocLiteAssociation> edocLites = (List<EDocLiteAssociation>)exportDataSet.getDataSets().get(EDOCLITES);
81 if (edocLites != null) {
82 edlExportDataSet.getEdocLites().addAll(edocLites);
83 }
84
85 return edlExportDataSet;
86 }
87
88 }