View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.rice.kim.impl.jaxb;
20  
21  import java.io.Serializable;
22  import java.util.List;
23  
24  import javax.xml.bind.Marshaller;
25  import javax.xml.bind.UnmarshalException;
26  import javax.xml.bind.Unmarshaller;
27  import javax.xml.bind.annotation.XmlAccessType;
28  import javax.xml.bind.annotation.XmlAccessorType;
29  import javax.xml.bind.annotation.XmlElement;
30  import javax.xml.bind.annotation.XmlType;
31  
32  import org.kuali.rice.core.util.jaxb.RiceXmlExportList;
33  import org.kuali.rice.core.util.jaxb.RiceXmlImportList;
34  import org.kuali.rice.core.util.jaxb.RiceXmlListAdditionListener;
35  import org.kuali.rice.core.util.jaxb.RiceXmlListGetterListener;
36  import org.kuali.rice.kim.api.permission.PermissionContract;
37  
38  /**
39   * This class represents a &lt;permissions&gt; element. 
40   * 
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   */
43  @XmlAccessorType(XmlAccessType.FIELD)
44  @XmlType(name="PermissionsType", propOrder={"permissions"})
45  public class PermissionsXmlDTO implements RiceXmlListAdditionListener<PermissionXmlDTO>,
46          RiceXmlListGetterListener<PermissionXmlDTO,Object>, Serializable {
47      
48      private static final long serialVersionUID = 1L;
49      
50      @XmlElement(name="permission")
51      private List<PermissionXmlDTO> permissions;
52      
53      public PermissionsXmlDTO() {}
54      
55      public PermissionsXmlDTO(List<? extends Object> permissionsToExport) {
56          this.permissions = new RiceXmlExportList<PermissionXmlDTO,Object>(permissionsToExport, this);
57      }
58      
59      /**
60       * @return the permissions
61       */
62      public List<PermissionXmlDTO> getPermissions() {
63          return this.permissions;
64      }
65  
66      /**
67       * @param permissions the permissions to set
68       */
69      public void setPermissions(List<PermissionXmlDTO> permissions) {
70          this.permissions = permissions;
71      }
72  
73      void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) {
74          permissions = new RiceXmlImportList<PermissionXmlDTO>(this);
75      }
76      
77      void afterUnmarshal(Unmarshaller unmarshaller, Object parent) {
78          permissions = null;
79      }
80      
81      public void newItemAdded(PermissionXmlDTO item) {
82          try {
83              PermissionXmlUtil.validateAndPersistNewPermission(item);
84          } catch (UnmarshalException e) {
85              throw new RuntimeException(e);
86          }
87      }
88  
89      void afterMarshal(Marshaller marshaller) {
90          permissions = null;
91      }
92      
93      public PermissionXmlDTO gettingNextItem(Object nextItem, int index) {
94          if (!(nextItem instanceof PermissionContract)) {
95              throw new IllegalStateException("Object for exportation should have been a permission");
96          }
97          return new PermissionXmlDTO((PermissionContract) nextItem);
98      }
99  }