001/* 002 * Copyright 2011 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl1.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kim.impl.jaxb; 017 018import java.io.Serializable; 019import java.util.List; 020 021import javax.xml.bind.Marshaller; 022import javax.xml.bind.UnmarshalException; 023import javax.xml.bind.Unmarshaller; 024import javax.xml.bind.annotation.XmlAccessType; 025import javax.xml.bind.annotation.XmlAccessorType; 026import javax.xml.bind.annotation.XmlElement; 027import javax.xml.bind.annotation.XmlType; 028 029import org.kuali.rice.core.util.jaxb.RiceXmlExportList; 030import org.kuali.rice.core.util.jaxb.RiceXmlImportList; 031import org.kuali.rice.core.util.jaxb.RiceXmlListAdditionListener; 032import org.kuali.rice.core.util.jaxb.RiceXmlListGetterListener; 033import org.kuali.rice.kim.api.permission.PermissionContract; 034 035/** 036 * This class represents a <permissions> element. 037 * 038 * @author Kuali Rice Team (rice.collab@kuali.org) 039 */ 040@XmlAccessorType(XmlAccessType.FIELD) 041@XmlType(name="PermissionsType", propOrder={"permissions"}) 042public class PermissionsXmlDTO implements RiceXmlListAdditionListener<PermissionXmlDTO>, 043 RiceXmlListGetterListener<PermissionXmlDTO,Object>, Serializable { 044 045 private static final long serialVersionUID = 1L; 046 047 @XmlElement(name="permission") 048 private List<PermissionXmlDTO> permissions; 049 050 public PermissionsXmlDTO() {} 051 052 public PermissionsXmlDTO(List<? extends Object> permissionsToExport) { 053 this.permissions = new RiceXmlExportList<PermissionXmlDTO,Object>(permissionsToExport, this); 054 } 055 056 /** 057 * @return the permissions 058 */ 059 public List<PermissionXmlDTO> getPermissions() { 060 return this.permissions; 061 } 062 063 /** 064 * @param permissions the permissions to set 065 */ 066 public void setPermissions(List<PermissionXmlDTO> permissions) { 067 this.permissions = permissions; 068 } 069 070 void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) { 071 permissions = new RiceXmlImportList<PermissionXmlDTO>(this); 072 } 073 074 void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { 075 permissions = null; 076 } 077 078 public void newItemAdded(PermissionXmlDTO item) { 079 try { 080 PermissionXmlUtil.validateAndPersistNewPermission(item); 081 } catch (UnmarshalException e) { 082 throw new RuntimeException(e); 083 } 084 } 085 086 void afterMarshal(Marshaller marshaller) { 087 permissions = null; 088 } 089 090 public PermissionXmlDTO gettingNextItem(Object nextItem, int index) { 091 if (!(nextItem instanceof PermissionContract)) { 092 throw new IllegalStateException("Object for exportation should have been a permission"); 093 } 094 return new PermissionXmlDTO((PermissionContract) nextItem); 095 } 096}