1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.impl.jaxb;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.OutputStream;
21 import java.util.Collections;
22 import java.util.List;
23
24 import org.kuali.rice.core.framework.impex.xml.XmlLoader;
25 import org.kuali.rice.kim.api.permission.PermissionContract;
26 import org.kuali.rice.kim.api.role.RoleContract;
27 import org.kuali.rice.krad.bo.Exporter;
28 import org.kuali.rice.krad.exception.ExportNotSupportedException;
29 import org.kuali.rice.krad.util.KRADConstants;
30
31
32
33
34
35
36
37
38
39
40 public class KimImporterAndExporter implements XmlLoader, Exporter {
41
42 private final List<String> supportedFormats = Collections.singletonList(KRADConstants.XML_FORMAT);
43
44
45
46
47 @Override
48 public void loadXml(InputStream inputStream, String principalId) {
49 KimXmlUtil.parseKimXml(inputStream);
50 }
51
52
53
54
55 @Override
56 public void export(Class<?> dataObjectClass, List<? extends Object> dataObjects, String exportFormat,
57 OutputStream outputStream) throws IOException, ExportNotSupportedException {
58 if (!supportedFormats.contains(exportFormat)) {
59 throw new ExportNotSupportedException("The KimImporterAndExporter does not support the \"" + exportFormat + "\" export format");
60 }
61
62 if (PermissionContract.class.isAssignableFrom(dataObjectClass)) {
63 KimXmlUtil.exportKimXml(outputStream, dataObjects, null);
64 } else if (RoleContract.class.isAssignableFrom(dataObjectClass)) {
65 KimXmlUtil.exportKimXml(outputStream, null, dataObjects);
66 } else {
67 throw new ExportNotSupportedException("The KimImporterAndExporter cannot export non-permission and non-role objects");
68 }
69
70 }
71
72
73
74
75 @Override
76 public List<String> getSupportedFormats(Class<?> dataObjectClass) {
77 return supportedFormats;
78 }
79 }