| 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 | 0 | @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 | 0 | public RolesXmlDTO() {} |
| 51 | |
|
| 52 | 0 | public RolesXmlDTO(List<? extends Object> rolesToExport) { |
| 53 | 0 | this.roles = new RiceXmlExportList<RoleXmlDTO,Object>(rolesToExport, this); |
| 54 | 0 | } |
| 55 | |
|
| 56 | |
public List<RoleXmlDTO> getRoles() { |
| 57 | 0 | return roles; |
| 58 | |
} |
| 59 | |
|
| 60 | |
public void setRoles(List<RoleXmlDTO> roles) { |
| 61 | 0 | this.roles = roles; |
| 62 | 0 | } |
| 63 | |
|
| 64 | |
void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) { |
| 65 | 0 | roles = new RiceXmlImportList<RoleXmlDTO>(this); |
| 66 | 0 | } |
| 67 | |
|
| 68 | |
void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { |
| 69 | 0 | roles = null; |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
public void newItemAdded(RoleXmlDTO item) { |
| 76 | |
|
| 77 | 0 | if (!item.isAlreadyPersisted()) { |
| 78 | |
try { |
| 79 | 0 | RoleXmlUtil.validateAndPersistNewRole(item); |
| 80 | 0 | } catch (UnmarshalException e) { |
| 81 | 0 | throw new RuntimeException(e); |
| 82 | 0 | } |
| 83 | |
} |
| 84 | |
|
| 85 | |
|
| 86 | 0 | Set<String> existingRoleMemberIds = item.getExistingRoleMemberIds(); |
| 87 | 0 | if (existingRoleMemberIds != null) { |
| 88 | 0 | RoleXmlUtil.removeRoleMembers(item.getRoleId(), existingRoleMemberIds); |
| 89 | |
} |
| 90 | 0 | item.setExistingRoleMemberIds(null); |
| 91 | 0 | } |
| 92 | |
|
| 93 | |
void afterMarshal(Marshaller marshaller) { |
| 94 | 0 | roles = null; |
| 95 | 0 | } |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
public RoleXmlDTO gettingNextItem(Object nextItem, int index) { |
| 101 | 0 | if (!(nextItem instanceof RoleContract)) { |
| 102 | 0 | throw new IllegalStateException("Object for exportation should have been a role"); |
| 103 | |
} |
| 104 | 0 | RoleContract role = ((RoleContract)nextItem); |
| 105 | 0 | return new RoleXmlDTO(role, new RoleMembersXmlDTO.WithinRole(role.getId()), new RolePermissionsXmlDTO.WithinRole(role.getId())); |
| 106 | |
} |
| 107 | |
} |