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.Serializable;
19 import java.util.List;
20
21 import javax.xml.bind.Marshaller;
22 import javax.xml.bind.UnmarshalException;
23 import javax.xml.bind.Unmarshaller;
24 import javax.xml.bind.annotation.XmlAccessType;
25 import javax.xml.bind.annotation.XmlAccessorType;
26 import javax.xml.bind.annotation.XmlElement;
27 import javax.xml.bind.annotation.XmlType;
28
29 import org.kuali.rice.core.util.jaxb.RiceXmlExportList;
30 import org.kuali.rice.core.util.jaxb.RiceXmlImportList;
31 import org.kuali.rice.core.util.jaxb.RiceXmlListAdditionListener;
32 import org.kuali.rice.core.util.jaxb.RiceXmlListGetterListener;
33 import org.kuali.rice.kim.api.permission.PermissionContract;
34
35
36
37
38
39
40 @XmlAccessorType(XmlAccessType.FIELD)
41 @XmlType(name="PermissionsType", propOrder={"permissions"})
42 public class PermissionsXmlDTO implements RiceXmlListAdditionListener<PermissionXmlDTO>,
43 RiceXmlListGetterListener<PermissionXmlDTO,Object>, Serializable {
44
45 private static final long serialVersionUID = 1L;
46
47 @XmlElement(name="permission")
48 private List<PermissionXmlDTO> permissions;
49
50 public PermissionsXmlDTO() {}
51
52 public PermissionsXmlDTO(List<? extends Object> permissionsToExport) {
53 this.permissions = new RiceXmlExportList<PermissionXmlDTO,Object>(permissionsToExport, this);
54 }
55
56
57
58
59 public List<PermissionXmlDTO> getPermissions() {
60 return this.permissions;
61 }
62
63
64
65
66 public void setPermissions(List<PermissionXmlDTO> permissions) {
67 this.permissions = permissions;
68 }
69
70 void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) {
71 permissions = new RiceXmlImportList<PermissionXmlDTO>(this);
72 }
73
74 void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
75 permissions = null;
76 }
77
78 public void newItemAdded(PermissionXmlDTO item) {
79 try {
80 PermissionXmlUtil.validateAndPersistNewPermission(item);
81 } catch (UnmarshalException e) {
82 throw new RuntimeException(e);
83 }
84 }
85
86 void afterMarshal(Marshaller marshaller) {
87 permissions = null;
88 }
89
90 public PermissionXmlDTO gettingNextItem(Object nextItem, int index) {
91 if (!(nextItem instanceof PermissionContract)) {
92 throw new IllegalStateException("Object for exportation should have been a permission");
93 }
94 return new PermissionXmlDTO((PermissionContract) nextItem);
95 }
96 }