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