1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.rice.kim.impl.jaxb;
20
21 import java.io.Serializable;
22 import java.util.List;
23 import java.util.Set;
24
25 import javax.xml.bind.Marshaller;
26 import javax.xml.bind.UnmarshalException;
27 import javax.xml.bind.Unmarshaller;
28 import javax.xml.bind.annotation.XmlAccessType;
29 import javax.xml.bind.annotation.XmlAccessorType;
30 import javax.xml.bind.annotation.XmlElement;
31 import javax.xml.bind.annotation.XmlType;
32
33 import org.kuali.rice.core.util.jaxb.RiceXmlExportList;
34 import org.kuali.rice.core.util.jaxb.RiceXmlImportList;
35 import org.kuali.rice.core.util.jaxb.RiceXmlListAdditionListener;
36 import org.kuali.rice.core.util.jaxb.RiceXmlListGetterListener;
37 import org.kuali.rice.kim.api.role.RoleContract;
38
39
40
41
42
43
44 @XmlAccessorType(XmlAccessType.FIELD)
45 @XmlType(name="RolesType", propOrder={"roles"})
46 public class RolesXmlDTO implements RiceXmlListAdditionListener<RoleXmlDTO>, RiceXmlListGetterListener<RoleXmlDTO,Object>, Serializable {
47
48 private static final long serialVersionUID = 1L;
49
50 @XmlElement(name="role")
51 private List<RoleXmlDTO> roles;
52
53 public RolesXmlDTO() {}
54
55 public RolesXmlDTO(List<? extends Object> rolesToExport) {
56 this.roles = new RiceXmlExportList<RoleXmlDTO,Object>(rolesToExport, this);
57 }
58
59 public List<RoleXmlDTO> getRoles() {
60 return roles;
61 }
62
63 public void setRoles(List<RoleXmlDTO> roles) {
64 this.roles = roles;
65 }
66
67 void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) {
68 roles = new RiceXmlImportList<RoleXmlDTO>(this);
69 }
70
71 void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
72 roles = null;
73 }
74
75
76
77
78 public void newItemAdded(RoleXmlDTO item) {
79
80 if (!item.isAlreadyPersisted()) {
81 try {
82 RoleXmlUtil.validateAndPersistNewRole(item);
83 } catch (UnmarshalException e) {
84 throw new RuntimeException(e);
85 }
86 }
87
88
89 Set<String> existingRoleMemberIds = item.getExistingRoleMemberIds();
90 if (existingRoleMemberIds != null) {
91 RoleXmlUtil.removeRoleMembers(item.getRoleId(), existingRoleMemberIds);
92 }
93 item.setExistingRoleMemberIds(null);
94 }
95
96 void afterMarshal(Marshaller marshaller) {
97 roles = null;
98 }
99
100
101
102
103 public RoleXmlDTO gettingNextItem(Object nextItem, int index) {
104 if (!(nextItem instanceof RoleContract)) {
105 throw new IllegalStateException("Object for exportation should have been a role");
106 }
107 RoleContract role = ((RoleContract)nextItem);
108 return new RoleXmlDTO(role, new RoleMembersXmlDTO.WithinRole(role.getId()), new RolePermissionsXmlDTO.WithinRole(role.getId()));
109 }
110 }