View Javadoc
1   /**
2    * Copyright 2005-2015 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/ecl2.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  
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   * This class represents a <permissions> element. 
37   * 
38   * @author Kuali Rice Team (rice.collab@kuali.org)
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       * @return the permissions
58       */
59      public List<PermissionXmlDTO> getPermissions() {
60          return this.permissions;
61      }
62  
63      /**
64       * @param permissions the permissions to set
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  }