View Javadoc

1   /**
2    * Copyright 2005-2014 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.Collection;
20  
21  import javax.xml.bind.annotation.XmlAccessType;
22  import javax.xml.bind.annotation.XmlAccessorType;
23  import javax.xml.bind.annotation.XmlAnyElement;
24  import javax.xml.bind.annotation.XmlElement;
25  import javax.xml.bind.annotation.XmlRootElement;
26  import javax.xml.bind.annotation.XmlType;
27  
28  import org.apache.commons.lang.StringUtils;
29  import org.kuali.rice.core.api.CoreConstants;
30  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
31  import org.kuali.rice.core.api.mo.ModelBuilder;
32  
33  /**
34   * Concrete model object implementation of KRMS AgendaTreeRuleEntry
35   * immutable.
36   * Instances of AgendaTreeRuleEntry can be (un)marshalled to and from XML.
37   * 
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   *
40   */
41  @XmlRootElement(name = AgendaTreeRuleEntry.Constants.ROOT_ELEMENT_NAME)
42  @XmlAccessorType(XmlAccessType.NONE)
43  @XmlType(name = AgendaTreeRuleEntry.Constants.TYPE_NAME, propOrder = {
44  		AgendaTreeRuleEntry.Elements.AGENDA_ITEM_ID,
45  		AgendaTreeRuleEntry.Elements.RULE_ID,
46  		AgendaTreeRuleEntry.Elements.IF_TRUE,
47  		AgendaTreeRuleEntry.Elements.IF_FALSE,
48  		CoreConstants.CommonElements.FUTURE_ELEMENTS
49  })
50  public final class AgendaTreeRuleEntry extends AbstractDataTransferObject implements AgendaTreeEntryDefinitionContract {
51  
52  	private static final long serialVersionUID = 8594116503548506936L;
53  
54  	@XmlElement(name = Elements.AGENDA_ITEM_ID, required = true)
55  	private final String agendaItemId;
56  	
57  	@XmlElement(name = Elements.RULE_ID, required = true)
58  	private final String ruleId;
59  	
60  	@XmlElement(name = Elements.IF_TRUE, required = false)
61  	private final AgendaTreeDefinition ifTrue;
62  	
63  	@XmlElement(name = Elements.IF_FALSE, required = false)
64  	private final AgendaTreeDefinition ifFalse;
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 AgendaTreeRuleEntry() {
75  		this.agendaItemId = null;
76  		this.ruleId = null;
77  		this.ifTrue = null;
78  		this.ifFalse = null;
79  	}
80  
81      /**
82       * Constructs a AgendaTreeRuleEntry from the given builder.
83       * This constructor is private and should only ever be invoked from the builder.
84       *
85       * @param builder the Builder from which to construct the AgendaTreeRuleEntry
86       */
87  	private AgendaTreeRuleEntry(Builder builder) {
88  		this.agendaItemId = builder.getAgendaItemId();
89  		this.ruleId = builder.getRuleId();
90  		this.ifTrue = builder.getIfTrue() == null ? null : builder.getIfTrue().build();
91  		this.ifFalse = builder.getIfFalse() == null ? null : builder.getIfFalse().build();
92  	}
93  	
94  	@Override
95  	public String getAgendaItemId() {
96  		return agendaItemId;
97  	}
98  
99      /**
100      * Returns the rule id.
101      * @return ruleId of the AgendaTreeRuleEntry
102      */
103 	public String getRuleId() {
104 		return this.ruleId;
105 	}
106 
107     /**
108      * Returns the AgendaTreeDefinition for ifTrue.
109      * @return {@link AgendaTreeDefinition} for ifTrue
110      */
111 	public AgendaTreeDefinition getIfTrue() {
112 		return this.ifTrue;
113 	}
114 
115     /**
116      * Returns the AgendaTreeDefinition for ifFalse.
117      * @return {@link AgendaTreeDefinition} for ifFalse
118      */
119 	public AgendaTreeDefinition getIfFalse() {
120 		return this.ifFalse;
121 	}
122 
123     /**
124      * This builder is used to construct instances of AgendaTreeRuleEntry.
125      * It enforces the constraints of the {@link AgendaTreeEntryDefinitionContract}.
126      */
127 	public static class Builder implements AgendaTreeEntryDefinitionContract, Serializable {
128         
129 		private static final long serialVersionUID = 3548736700798501429L;
130 		
131 		private String agendaItemId;
132 		private String ruleId;
133 		private AgendaTreeDefinition.Builder ifTrue;
134 		private AgendaTreeDefinition.Builder ifFalse;
135 
136 		/**
137 		 * Private constructor for creating a builder with all of it's required attributes.
138          *
139          * @param agendaItemId the agendaItemId value to set, must not be null or blank
140          * @param ruleId the propId value to set, must not be null or blank
141          */
142         private Builder(String agendaItemId, String ruleId) {
143         	setAgendaItemId(agendaItemId);
144         	setRuleId(ruleId);
145         }
146 
147         /**
148          * Create a builder using the given values
149          *
150          * @param agendaItemId the agendaItemId value to set, must not be null or blank
151          * @param ruleId the propId value to set, must not be null or blank
152          * @return Builder with the given values set
153          */
154         public static Builder create(String agendaItemId, String ruleId){
155         	return new Builder(agendaItemId, ruleId);
156         }
157         
158         @Override
159         public String getAgendaItemId() {
160 			return this.agendaItemId;
161 		}
162 
163         /**
164          * Returns the rule id.
165          * @return ruleId of the AgendaTreeRuleEntry
166          */
167 		public String getRuleId() {
168 			return this.ruleId;
169 		}
170 
171         /**
172          * Returns the AgendaTreeDefinition.Builder for ifTrue.
173          * @return {@link AgendaTreeDefinition.Builder} for ifTrue
174          */
175 		public AgendaTreeDefinition.Builder getIfTrue() {
176 			return this.ifTrue;
177 		}
178 
179         /**
180          * Returns the AgendaTreeDefinition.Builder for ifFalse.
181          * @return {@link AgendaTreeDefinition.Builder} for ifFalse
182          */
183 		public AgendaTreeDefinition.Builder getIfFalse() {
184 			return this.ifFalse;
185 		}
186 
187         /**
188          * Sets the agendaItemId, cannot be null or blank.
189          * @param agendaItemId the agendaItemId value to set, must not be null or blank
190          * @throws IllegalArgumentException if agendaItemId is null or blank.
191          */
192 		public void setAgendaItemId(String agendaItemId) {
193 			if (StringUtils.isBlank(agendaItemId)) {
194 				throw new IllegalArgumentException("agendaItemId was null or blank");
195 			}
196 			this.agendaItemId = agendaItemId;
197 		}
198 
199         /**
200          * @param ruleId the propId value to set, must not be null or blank
201          * @throws IllegalArgumentException if ruleId is null or blank.
202          */
203 		public void setRuleId(String ruleId) {
204 			if (StringUtils.isBlank(ruleId)) {
205 				throw new IllegalArgumentException("ruleId was null or blank");
206 			}
207 			this.ruleId = ruleId;
208 		}
209 
210         /**
211          * Set the ifTrue {@link AgendaTreeDefinition.Builder}
212          * @param ifTrue {@link AgendaTreeDefinition.Builder} for ifTrue
213          */
214 		public void setIfTrue(AgendaTreeDefinition.Builder ifTrue) {
215 			this.ifTrue = ifTrue;
216 		}
217 
218         /**
219          * Set the ifFalse {@link AgendaTreeDefinition.Builder}
220          * @param ifFalse {@link AgendaTreeDefinition.Builder} for ifFalse
221          */
222 		public void setIfFalse(AgendaTreeDefinition.Builder ifFalse) {
223 			this.ifFalse = ifFalse;
224 		}
225 
226         /**
227          * Build the {@link AgendaTreeRuleEntry} with the builders values
228          * @return {@link AgendaTreeRuleEntry} with the builders values
229          */
230         public AgendaTreeRuleEntry build() {
231             return new AgendaTreeRuleEntry(this);
232         }
233 		
234     }
235 	
236 	/**
237 	 * Defines some internal constants used on this class.
238 	 */
239 	static class Constants {
240 		final static String ROOT_ELEMENT_NAME = "agendaTreeRuleEntry";
241 		final static String TYPE_NAME = "AgendaTreeRuleEntryType";
242 	}
243 	
244 	/**
245 	 * A private class which exposes constants which define the XML element names to use
246 	 * when this object is marshalled to XML.
247 	 */
248 	static class Elements {
249 		final static String AGENDA_ITEM_ID = "agendaItemId";
250 		final static String RULE_ID = "ruleId";
251 		final static String IF_TRUE = "ifTrue";
252 		final static String IF_FALSE = "ifFalse";
253 	}
254 
255 }