001/* 002 * The Kuali Financial System, a comprehensive financial management system for higher education. 003 * 004 * Copyright 2005-2014 The Kuali Foundation 005 * 006 * This program is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU Affero General Public License as 008 * published by the Free Software Foundation, either version 3 of the 009 * License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU Affero General Public License for more details. 015 * 016 * You should have received a copy of the GNU Affero General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package org.kuali.rice.kim.impl.jaxb; 020 021import java.io.Serializable; 022import java.util.List; 023 024import javax.xml.bind.Marshaller; 025import javax.xml.bind.UnmarshalException; 026import javax.xml.bind.Unmarshaller; 027import javax.xml.bind.annotation.XmlAccessType; 028import javax.xml.bind.annotation.XmlAccessorType; 029import javax.xml.bind.annotation.XmlElement; 030import javax.xml.bind.annotation.XmlType; 031 032import org.kuali.rice.core.util.jaxb.RiceXmlExportList; 033import org.kuali.rice.core.util.jaxb.RiceXmlImportList; 034import org.kuali.rice.core.util.jaxb.RiceXmlListAdditionListener; 035import org.kuali.rice.core.util.jaxb.RiceXmlListGetterListener; 036import org.kuali.rice.kim.api.permission.PermissionContract; 037 038/** 039 * This class represents a <permissions> element. 040 * 041 * @author Kuali Rice Team (rice.collab@kuali.org) 042 */ 043@XmlAccessorType(XmlAccessType.FIELD) 044@XmlType(name="PermissionsType", propOrder={"permissions"}) 045public class PermissionsXmlDTO implements RiceXmlListAdditionListener<PermissionXmlDTO>, 046 RiceXmlListGetterListener<PermissionXmlDTO,Object>, Serializable { 047 048 private static final long serialVersionUID = 1L; 049 050 @XmlElement(name="permission") 051 private List<PermissionXmlDTO> permissions; 052 053 public PermissionsXmlDTO() {} 054 055 public PermissionsXmlDTO(List<? extends Object> permissionsToExport) { 056 this.permissions = new RiceXmlExportList<PermissionXmlDTO,Object>(permissionsToExport, this); 057 } 058 059 /** 060 * @return the permissions 061 */ 062 public List<PermissionXmlDTO> getPermissions() { 063 return this.permissions; 064 } 065 066 /** 067 * @param permissions the permissions to set 068 */ 069 public void setPermissions(List<PermissionXmlDTO> permissions) { 070 this.permissions = permissions; 071 } 072 073 void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) { 074 permissions = new RiceXmlImportList<PermissionXmlDTO>(this); 075 } 076 077 void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { 078 permissions = null; 079 } 080 081 public void newItemAdded(PermissionXmlDTO item) { 082 try { 083 PermissionXmlUtil.validateAndPersistNewPermission(item); 084 } catch (UnmarshalException e) { 085 throw new RuntimeException(e); 086 } 087 } 088 089 void afterMarshal(Marshaller marshaller) { 090 permissions = null; 091 } 092 093 public PermissionXmlDTO gettingNextItem(Object nextItem, int index) { 094 if (!(nextItem instanceof PermissionContract)) { 095 throw new IllegalStateException("Object for exportation should have been a permission"); 096 } 097 return new PermissionXmlDTO((PermissionContract) nextItem); 098 } 099}