Coverage Report - org.kuali.rice.kim.impl.jaxb.RolesXmlDTO
 
Classes in this File Line Coverage Branch Coverage Complexity
RolesXmlDTO
0%
0/28
0%
0/6
1.667
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * This class represents a <roles> element. 
 38  
  * 
 39  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
      * @see org.kuali.rice.core.util.jaxb.RiceXmlListAdditionListener#newItemAdded(java.lang.Object)
 74  
      */
 75  
     public void newItemAdded(RoleXmlDTO item) {
 76  
         // Persist the role if it has not already been persisted yet.
 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  
         // If a "roleMembers" element was present, remove any existing roles that do not match the new ones.
 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  
      * @see org.kuali.rice.core.util.jaxb.RiceXmlListGetterListener#gettingNextItem(java.lang.Object, int)
 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  
 }