View Javadoc

1   /**
2    * Copyright 2005-2013 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.krms.api.repository.agenda;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Collections;
22  import java.util.List;
23  
24  import javax.xml.bind.annotation.XmlAccessType;
25  import javax.xml.bind.annotation.XmlAccessorType;
26  import javax.xml.bind.annotation.XmlAnyElement;
27  import javax.xml.bind.annotation.XmlElement;
28  import javax.xml.bind.annotation.XmlElements;
29  import javax.xml.bind.annotation.XmlRootElement;
30  import javax.xml.bind.annotation.XmlType;
31  
32  import org.apache.commons.lang.StringUtils;
33  import org.kuali.rice.core.api.CoreConstants;
34  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
35  import org.kuali.rice.core.api.mo.ModelBuilder;
36  import org.kuali.rice.krms.api.KrmsConstants;
37  
38  /**
39   * Concrete model object implementation of KRMS Repository AgendaTreeDefinition
40   * immutable. 
41   * Instances of Agenda can be (un)marshalled to and from XML.
42   *
43   * @see AgendaDefinitionContract
44   *
45   * @author Kuali Rice Team (rice.collab@kuali.org)
46   */
47  @XmlRootElement(name = AgendaTreeDefinition.Constants.ROOT_ELEMENT_NAME)
48  @XmlAccessorType(XmlAccessType.NONE)
49  @XmlType(name = AgendaTreeDefinition.Constants.TYPE_NAME, propOrder = {
50  		AgendaTreeDefinition.Elements.AGENDA_ID,
51  		AgendaTreeDefinition.Elements.ENTRIES,
52  		CoreConstants.CommonElements.FUTURE_ELEMENTS
53  })
54  public final class AgendaTreeDefinition extends AbstractDataTransferObject {
55  	
56  	private static final long serialVersionUID = 3355519740298280591L;
57  
58  	@XmlElement(name = Elements.AGENDA_ID, required = false)
59  	private final String agendaId;
60  	
61  	@XmlElements(value = {
62              @XmlElement(name = Elements.RULE, type = AgendaTreeRuleEntry.class, required = false),
63              @XmlElement(name = Elements.SUB_AGENDA, type = AgendaTreeSubAgendaEntry.class, required = false)
64  	})
65  	private final List<AgendaTreeEntryDefinitionContract> entries;
66  		
67  	@SuppressWarnings("unused")
68      @XmlAnyElement
69      private final Collection<org.w3c.dom.Element> _futureElements = null;
70  	
71  	/** 
72       * This constructor should never be called.  
73       * It is only present for use during JAXB unmarshalling. 
74       */
75      private AgendaTreeDefinition() {
76      	this.agendaId = null;
77      	this.entries = null;
78      }
79  
80      /**
81       * Constructs a AgendaTreeDefinition from the given builder.
82       * This constructor is private and should only ever be invoked from the builder.
83       *
84       * @param builder the Builder from which to construct the AgendaTreeDefinition
85       */
86      private AgendaTreeDefinition(Builder builder) {
87      	this.agendaId = builder.getAgendaId();
88          this.entries = builder.getEntries();
89      }
90  
91      /**
92       * Returns the agendaId
93       * @return agendaId of the AgendaTreeDefinition
94       */
95      public String getAgendaId() {
96      	return agendaId;
97      }
98  
99      /**
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 }