View Javadoc

1   /**
2    * Copyright 2005-2012 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  
37  /**
38   * Concrete model object implementation of KRMS Repository AgendaTreeDefinition
39   * immutable. 
40   * Instances of Agenda can be (un)marshalled to and from XML.
41   *
42   * @see AgendaDefinitionContract
43   *
44   * @author Kuali Rice Team (rice.collab@kuali.org)
45   */
46  @XmlRootElement(name = AgendaTreeDefinition.Constants.ROOT_ELEMENT_NAME)
47  @XmlAccessorType(XmlAccessType.NONE)
48  @XmlType(name = AgendaTreeDefinition.Constants.TYPE_NAME, propOrder = {
49  		AgendaTreeDefinition.Elements.AGENDA_ID,
50  		AgendaTreeDefinition.Elements.ENTRIES,
51  		CoreConstants.CommonElements.FUTURE_ELEMENTS
52  })
53  public final class AgendaTreeDefinition extends AbstractDataTransferObject {
54  	
55  	private static final long serialVersionUID = 3355519740298280591L;
56  
57  	@XmlElement(name = Elements.AGENDA_ID, required = false)
58  	private final String agendaId;
59  	
60  	@XmlElements(value = {
61              @XmlElement(name = Elements.RULE, type = AgendaTreeRuleEntry.class, required = false),
62              @XmlElement(name = Elements.SUB_AGENDA, type = AgendaTreeSubAgendaEntry.class, required = false)
63  	})
64  	private final List<AgendaTreeEntryDefinitionContract> entries;
65  		
66  	@SuppressWarnings("unused")
67      @XmlAnyElement
68      private final Collection<org.w3c.dom.Element> _futureElements = null;
69  	
70  	/** 
71       * This constructor should never be called.  
72       * It is only present for use during JAXB unmarshalling. 
73       */
74      private AgendaTreeDefinition() {
75      	this.agendaId = null;
76      	this.entries = null;
77      }
78  
79      /**
80       * Constructs a AgendaTreeDefinition from the given builder.
81       * This constructor is private and should only ever be invoked from the builder.
82       *
83       * @param builder the Builder from which to construct the AgendaTreeDefinition
84       */
85      private AgendaTreeDefinition(Builder builder) {
86      	this.agendaId = builder.getAgendaId();
87          this.entries = builder.getEntries();
88      }
89  
90      /**
91       * Returns the agendaId
92       * @return agendaId of the AgendaTreeDefinition
93       */
94      public String getAgendaId() {
95      	return agendaId;
96      }
97  
98      /**
99       * Returns the {@link AgendaTreeEntryDefinitionContract}s
100      * @return List<{@link AgendaTreeEntryDefinitionContract}>s
101      */
102 	public List<AgendaTreeEntryDefinitionContract> getEntries() {
103 		if (entries == null){
104 			return Collections.emptyList();
105 		}
106 		return Collections.unmodifiableList(entries);
107 	}
108 
109 
110     /**
111      * This builder is used to construct instances of AgendaTreeDefinition.
112      */
113     public static class Builder implements ModelBuilder, Serializable {
114 		        
115 		private static final long serialVersionUID = 7981215392039022620L;
116 		
117 		private String agendaId;
118 		private List<AgendaTreeEntryDefinitionContract> entries;
119 
120 		/**
121 		 * Private constructor for creating a builder with all of it's required attributes.
122 		 */
123         private Builder() {
124         	this.entries = new ArrayList<AgendaTreeEntryDefinitionContract>();
125         }
126 
127         /**
128          * Create a new Builder
129          * @return a new Builder
130          */
131         public static Builder create(){
132         	return new Builder();
133         }
134 
135         /**
136          * Sets the agendaId to the given parameter
137          * @param agendaId to set the apendaId value to, must not be null or blank
138          * @thows IllegalArgumentException if the agendaId is null or blank
139          */
140         public void setAgendaId(String agendaId) {
141 			if (StringUtils.isBlank(agendaId)) {
142 				throw new IllegalArgumentException("agendaItemId was null or blank");
143 			}
144         	this.agendaId = agendaId;
145         }
146 
147         /**
148          * Adds the given {@link AgendaTreeRuleEntry} to the entries.
149          * @param ruleEntry {@link AgendaTreeRuleEntry} to be added to the entries, must not be null
150          * @thows IllegalArgumentException if the ruleEntry is null
151          */
152         public void addRuleEntry(AgendaTreeRuleEntry ruleEntry) {
153         	if (ruleEntry == null) {
154         		throw new IllegalArgumentException("ruleEntry was null");
155         	}
156         	entries.add(ruleEntry);
157         }
158 
159         /**
160          * Adds the given {@link AgendaTreeSubAgendaEntry} to the entries.
161          * @param subAgendaEntry {@link AgendaTreeSubAgendaEntry} to add to the entries, must not be null
162          * @thows IllegalArgumentException if the subAgendaEntry is null
163          */
164         public void addSubAgendaEntry(AgendaTreeSubAgendaEntry subAgendaEntry) {
165         	if (subAgendaEntry == null) {
166         		throw new IllegalArgumentException("subAgendaEntry was null");
167         	}
168         	entries.add(subAgendaEntry);
169         }
170 
171         /**
172          * Returns the agendaId
173          * @return agendaId
174          */
175         public String getAgendaId() {
176         	return this.agendaId;
177         }
178 
179         /**
180          * Returns the list of {@link AgendaTreeEntryDefinitionContract}s entries
181          * @return List<{@link AgendaTreeEntryDefinitionContract}> of entries
182          */
183         public List<AgendaTreeEntryDefinitionContract> getEntries() {
184         	return this.entries;
185         }
186 
187         @Override
188         public AgendaTreeDefinition build() {
189             return new AgendaTreeDefinition(this);
190         }
191 		
192     }
193 	
194 	/**
195 	 * Defines some internal constants used on this class.
196 	 */
197 	static class Constants {
198 		final static String ROOT_ELEMENT_NAME = "agendaTreeDefinition";
199 		final static String TYPE_NAME = "AgendaTreeDefinition";
200 	}
201 	
202 	/**
203 	 * A private class which exposes constants which define the XML element names to use
204 	 * when this object is marshalled to XML.
205 	 */
206 	static class Elements {
207 		final static String AGENDA_ID = "agendaId";
208 		final static String ENTRIES = "entries";
209 		final static String RULE = "rule";
210 		final static String SUB_AGENDA = "subAgenda";
211 	}
212 
213 }