001 /** 002 * Copyright 2005-2013 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/ecl2.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 */ 016 package org.kuali.rice.krms.api.repository.agenda; 017 018 import java.io.Serializable; 019 import java.util.ArrayList; 020 import java.util.Collection; 021 import java.util.Collections; 022 import java.util.List; 023 024 import javax.xml.bind.annotation.XmlAccessType; 025 import javax.xml.bind.annotation.XmlAccessorType; 026 import javax.xml.bind.annotation.XmlAnyElement; 027 import javax.xml.bind.annotation.XmlElement; 028 import javax.xml.bind.annotation.XmlElements; 029 import javax.xml.bind.annotation.XmlRootElement; 030 import javax.xml.bind.annotation.XmlType; 031 032 import org.apache.commons.lang.StringUtils; 033 import org.kuali.rice.core.api.CoreConstants; 034 import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 035 import org.kuali.rice.core.api.mo.ModelBuilder; 036 import org.kuali.rice.krms.api.KrmsConstants; 037 038 /** 039 * Concrete model object implementation of KRMS Repository AgendaTreeDefinition 040 * immutable. 041 * Instances of Agenda can be (un)marshalled to and from XML. 042 * 043 * @see AgendaDefinitionContract 044 * 045 * @author Kuali Rice Team (rice.collab@kuali.org) 046 */ 047 @XmlRootElement(name = AgendaTreeDefinition.Constants.ROOT_ELEMENT_NAME) 048 @XmlAccessorType(XmlAccessType.NONE) 049 @XmlType(name = AgendaTreeDefinition.Constants.TYPE_NAME, propOrder = { 050 AgendaTreeDefinition.Elements.AGENDA_ID, 051 AgendaTreeDefinition.Elements.ENTRIES, 052 CoreConstants.CommonElements.FUTURE_ELEMENTS 053 }) 054 public final class AgendaTreeDefinition extends AbstractDataTransferObject { 055 056 private static final long serialVersionUID = 3355519740298280591L; 057 058 @XmlElement(name = Elements.AGENDA_ID, required = false) 059 private final String agendaId; 060 061 @XmlElements(value = { 062 @XmlElement(name = Elements.RULE, type = AgendaTreeRuleEntry.class, required = false), 063 @XmlElement(name = Elements.SUB_AGENDA, type = AgendaTreeSubAgendaEntry.class, required = false) 064 }) 065 private final List<AgendaTreeEntryDefinitionContract> entries; 066 067 @SuppressWarnings("unused") 068 @XmlAnyElement 069 private final Collection<org.w3c.dom.Element> _futureElements = null; 070 071 /** 072 * This constructor should never be called. 073 * It is only present for use during JAXB unmarshalling. 074 */ 075 private AgendaTreeDefinition() { 076 this.agendaId = null; 077 this.entries = null; 078 } 079 080 /** 081 * Constructs a AgendaTreeDefinition from the given builder. 082 * This constructor is private and should only ever be invoked from the builder. 083 * 084 * @param builder the Builder from which to construct the AgendaTreeDefinition 085 */ 086 private AgendaTreeDefinition(Builder builder) { 087 this.agendaId = builder.getAgendaId(); 088 this.entries = builder.getEntries(); 089 } 090 091 /** 092 * Returns the agendaId 093 * @return agendaId of the AgendaTreeDefinition 094 */ 095 public String getAgendaId() { 096 return agendaId; 097 } 098 099 /** 100 * Returns the {@link AgendaTreeEntryDefinitionContract}s 101 * @return List<{@link AgendaTreeEntryDefinitionContract}>s 102 */ 103 public List<AgendaTreeEntryDefinitionContract> getEntries() { 104 if (entries == null){ 105 return Collections.emptyList(); 106 } 107 return Collections.unmodifiableList(entries); 108 } 109 110 111 /** 112 * This builder is used to construct instances of AgendaTreeDefinition. 113 */ 114 public static class Builder implements ModelBuilder, Serializable { 115 116 private static final long serialVersionUID = 7981215392039022620L; 117 118 private String agendaId; 119 private List<AgendaTreeEntryDefinitionContract> entries; 120 121 /** 122 * Private constructor for creating a builder with all of it's required attributes. 123 */ 124 private Builder() { 125 this.entries = new ArrayList<AgendaTreeEntryDefinitionContract>(); 126 } 127 128 /** 129 * Create a new Builder 130 * @return a new Builder 131 */ 132 public static Builder create(){ 133 return new Builder(); 134 } 135 136 /** 137 * Sets the agendaId to the given parameter 138 * @param agendaId to set the apendaId value to, must not be null or blank 139 * @thows IllegalArgumentException if the agendaId is null or blank 140 */ 141 public void setAgendaId(String agendaId) { 142 if (StringUtils.isBlank(agendaId)) { 143 throw new IllegalArgumentException("agendaItemId was null or blank"); 144 } 145 this.agendaId = agendaId; 146 } 147 148 /** 149 * Adds the given {@link AgendaTreeRuleEntry} to the entries. 150 * @param ruleEntry {@link AgendaTreeRuleEntry} to be added to the entries, must not be null 151 * @thows IllegalArgumentException if the ruleEntry is null 152 */ 153 public void addRuleEntry(AgendaTreeRuleEntry ruleEntry) { 154 if (ruleEntry == null) { 155 throw new IllegalArgumentException("ruleEntry was null"); 156 } 157 entries.add(ruleEntry); 158 } 159 160 /** 161 * Adds the given {@link AgendaTreeSubAgendaEntry} to the entries. 162 * @param subAgendaEntry {@link AgendaTreeSubAgendaEntry} to add to the entries, must not be null 163 * @thows IllegalArgumentException if the subAgendaEntry is null 164 */ 165 public void addSubAgendaEntry(AgendaTreeSubAgendaEntry subAgendaEntry) { 166 if (subAgendaEntry == null) { 167 throw new IllegalArgumentException("subAgendaEntry was null"); 168 } 169 entries.add(subAgendaEntry); 170 } 171 172 /** 173 * Returns the agendaId 174 * @return agendaId 175 */ 176 public String getAgendaId() { 177 return this.agendaId; 178 } 179 180 /** 181 * Returns the list of {@link AgendaTreeEntryDefinitionContract}s entries 182 * @return List<{@link AgendaTreeEntryDefinitionContract}> of entries 183 */ 184 public List<AgendaTreeEntryDefinitionContract> getEntries() { 185 return this.entries; 186 } 187 188 @Override 189 public AgendaTreeDefinition build() { 190 return new AgendaTreeDefinition(this); 191 } 192 193 } 194 195 /** 196 * Defines some internal constants used on this class. 197 */ 198 static class Constants { 199 final static String ROOT_ELEMENT_NAME = "agendaTreeDefinition"; 200 final static String TYPE_NAME = "AgendaTreeDefinition"; 201 } 202 203 /** 204 * A private class which exposes constants which define the XML element names to use 205 * when this object is marshalled to XML. 206 */ 207 static class Elements { 208 final static String AGENDA_ID = "agendaId"; 209 final static String ENTRIES = "entries"; 210 final static String RULE = "rule"; 211 final static String SUB_AGENDA = "subAgenda"; 212 } 213 214 public static class Cache { 215 public static final String NAME = KrmsConstants.Namespaces.KRMS_NAMESPACE_2_0 + "/" + AgendaTreeDefinition.Constants.TYPE_NAME; 216 } 217 218 }