View Javadoc

1   /**
2    * Copyright 2005-2011 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   * This is a description of what this class does - ewestfal don't forget to fill this in. 
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   *
38   */
39  @XmlRootElement(name = AgendaTreeRuleEntry.Constants.ROOT_ELEMENT_NAME)
40  @XmlAccessorType(XmlAccessType.NONE)
41  @XmlType(name = AgendaTreeRuleEntry.Constants.TYPE_NAME, propOrder = {
42  		AgendaTreeRuleEntry.Elements.AGENDA_ITEM_ID,
43  		AgendaTreeRuleEntry.Elements.RULE_ID,
44  		AgendaTreeRuleEntry.Elements.IF_TRUE,
45  		AgendaTreeRuleEntry.Elements.IF_FALSE,
46  		CoreConstants.CommonElements.FUTURE_ELEMENTS
47  })
48  public final class AgendaTreeRuleEntry extends AbstractDataTransferObject implements AgendaTreeEntryDefinition {
49  
50  	private static final long serialVersionUID = 8594116503548506936L;
51  
52  	@XmlElement(name = Elements.AGENDA_ITEM_ID, required = true)
53  	private final String agendaItemId;
54  	
55  	@XmlElement(name = Elements.RULE_ID, required = true)
56  	private final String ruleId;
57  	
58  	@XmlElement(name = Elements.IF_TRUE, required = false)
59  	private final AgendaTreeDefinition ifTrue;
60  	
61  	@XmlElement(name = Elements.IF_FALSE, required = false)
62  	private final AgendaTreeDefinition ifFalse;
63  		
64  	@SuppressWarnings("unused")
65      @XmlAnyElement
66      private final Collection<org.w3c.dom.Element> _futureElements = null;
67  	
68  	/**
69  	 * Used only by JAXB.
70  	 */
71  	private AgendaTreeRuleEntry() {
72  		this.agendaItemId = null;
73  		this.ruleId = null;
74  		this.ifTrue = null;
75  		this.ifFalse = null;
76  	}
77  	
78  	private AgendaTreeRuleEntry(Builder builder) {
79  		this.agendaItemId = builder.getAgendaItemId();
80  		this.ruleId = builder.getRuleId();
81  		this.ifTrue = builder.getIfTrue() == null ? null : builder.getIfTrue().build();
82  		this.ifFalse = builder.getIfFalse() == null ? null : builder.getIfFalse().build();
83  	}
84  	
85  	@Override
86  	public String getAgendaItemId() {
87  		return agendaItemId;
88  	}
89  	
90  	public String getRuleId() {
91  		return this.ruleId;
92  	}
93  
94  	public AgendaTreeDefinition getIfTrue() {
95  		return this.ifTrue;
96  	}
97  
98  	public AgendaTreeDefinition getIfFalse() {
99  		return this.ifFalse;
100 	}
101 
102 	public static class Builder implements ModelBuilder, Serializable {
103         
104 		private static final long serialVersionUID = 3548736700798501429L;
105 		
106 		private String agendaItemId;
107 		private String ruleId;
108 		private AgendaTreeDefinition.Builder ifTrue;
109 		private AgendaTreeDefinition.Builder ifFalse;
110 
111 		/**
112 		 * Private constructor for creating a builder with all of it's required attributes.
113 		 */
114         private Builder(String agendaItemId, String ruleId) {
115         	setAgendaItemId(agendaItemId);
116         	setRuleId(ruleId);
117         }
118         
119         public static Builder create(String agendaItemId, String ruleId){
120         	return new Builder(agendaItemId, ruleId);
121         }
122         
123         public String getAgendaItemId() {
124 			return this.agendaItemId;
125 		}
126 
127 		public String getRuleId() {
128 			return this.ruleId;
129 		}
130 
131 		public AgendaTreeDefinition.Builder getIfTrue() {
132 			return this.ifTrue;
133 		}
134 
135 		public AgendaTreeDefinition.Builder getIfFalse() {
136 			return this.ifFalse;
137 		}
138 		
139 		public void setAgendaItemId(String agendaItemId) {
140 			if (StringUtils.isBlank(agendaItemId)) {
141 				throw new IllegalArgumentException("agendaItemId was null or blank");
142 			}
143 			this.agendaItemId = agendaItemId;
144 		}
145 
146 		public void setRuleId(String ruleId) {
147 			if (StringUtils.isBlank(ruleId)) {
148 				throw new IllegalArgumentException("ruleId was null or blank");
149 			}
150 			this.ruleId = ruleId;
151 		}
152 
153 		public void setIfTrue(AgendaTreeDefinition.Builder ifTrue) {
154 			this.ifTrue = ifTrue;
155 		}
156 
157 		public void setIfFalse(AgendaTreeDefinition.Builder ifFalse) {
158 			this.ifFalse = ifFalse;
159 		}
160 
161 		@Override
162         public AgendaTreeRuleEntry build() {
163             return new AgendaTreeRuleEntry(this);
164         }
165 		
166     }
167 	
168 	/**
169 	 * Defines some internal constants used on this class.
170 	 */
171 	static class Constants {
172 		final static String ROOT_ELEMENT_NAME = "agendaTreeRuleEntry";
173 		final static String TYPE_NAME = "AgendaTreeRuleEntryType";
174 	}
175 	
176 	/**
177 	 * A private class which exposes constants which define the XML element names to use
178 	 * when this object is marshalled to XML.
179 	 */
180 	static class Elements {
181 		final static String AGENDA_ITEM_ID = "agendaItemId";
182 		final static String RULE_ID = "ruleId";
183 		final static String IF_TRUE = "ifTrue";
184 		final static String IF_FALSE = "ifFalse";
185 	}
186 
187 }