1 package org.kuali.rice.krms.api.repository;
2
3 import java.io.Serializable;
4 import java.util.Arrays;
5 import java.util.Collection;
6 import java.util.Collections;
7
8 import javax.xml.bind.annotation.XmlAccessType;
9 import javax.xml.bind.annotation.XmlAccessorType;
10 import javax.xml.bind.annotation.XmlAnyElement;
11 import javax.xml.bind.annotation.XmlElement;
12 import javax.xml.bind.annotation.XmlRootElement;
13 import javax.xml.bind.annotation.XmlType;
14
15 import org.apache.commons.lang.StringUtils;
16 import org.apache.commons.lang.builder.EqualsBuilder;
17 import org.apache.commons.lang.builder.HashCodeBuilder;
18 import org.apache.commons.lang.builder.ToStringBuilder;
19 import org.kuali.rice.core.api.CoreConstants;
20 import org.kuali.rice.core.api.mo.ModelBuilder;
21 import org.kuali.rice.core.api.mo.ModelObjectComplete;
22
23
24
25
26
27
28
29
30 @XmlRootElement(name = PropositionParameter.Constants.ROOT_ELEMENT_NAME)
31 @XmlAccessorType(XmlAccessType.NONE)
32 @XmlType(name = PropositionParameter.Constants.TYPE_NAME, propOrder = {
33 PropositionParameter.Elements.ID,
34 PropositionParameter.Elements.PROP_ID,
35 PropositionParameter.Elements.VALUE,
36 PropositionParameter.Elements.PARM_TYPE,
37 PropositionParameter.Elements.SEQUENCE,
38 CoreConstants.CommonElements.FUTURE_ELEMENTS
39 })
40 public final class PropositionParameter implements PropositionParameterContract, ModelObjectComplete{
41 private static final long serialVersionUID = 2783959459503209577L;
42
43 @XmlElement(name = Elements.ID, required=true)
44 private String id;
45 @XmlElement(name = Elements.PROP_ID, required=true)
46 private String propId;
47 @XmlElement(name = Elements.VALUE, required=true)
48 private String value;
49 @XmlElement(name = Elements.PARM_TYPE, required=true)
50 private String parameterType;
51 @XmlElement(name = Elements.SEQUENCE, required=true)
52 private Integer sequenceNumber;
53
54 @SuppressWarnings("unused")
55 @XmlAnyElement
56 private final Collection<org.w3c.dom.Element> _futureElements = null;
57
58
59
60
61
62 private PropositionParameter() {
63 this.id = null;
64 this.propId = null;
65 this.value = null;
66 this.parameterType = null;
67 this.sequenceNumber = null;
68 }
69
70
71
72
73
74
75
76 private PropositionParameter(Builder builder) {
77 this.id = builder.getId();
78 this.propId = builder.getPropId();
79 this.value = builder.getValue();
80 this.parameterType = builder.getParameterType();
81 this.sequenceNumber = builder.getSequenceNumber();
82 }
83
84 @Override
85 public String getId() {
86 return this.id;
87 }
88
89 @Override
90 public String getPropId() {
91 return this.propId;
92 }
93
94 @Override
95 public String getValue() {
96 return this.value;
97 }
98
99 @Override
100 public String getParameterType() {
101 return this.parameterType;
102 }
103 @Override
104 public Integer getSequenceNumber() {
105 return this.sequenceNumber;
106 }
107
108
109
110
111
112 public static class Builder implements PropositionParameterContract, ModelBuilder, Serializable {
113 private static final long serialVersionUID = -6889320709850568900L;
114
115 private String id;
116 private String propId;
117 private String value;
118 private String parameterType;
119 private Integer sequenceNumber;
120
121
122
123
124 private Builder(String id, String propId, String value, String parameterType, Integer sequenceNumber) {
125 setId(id);
126 setPropId(propId);
127 setValue(value);
128 setParameterType(parameterType);
129 setSequenceNumber(sequenceNumber);
130 }
131
132 public static Builder create(String id, String propId, String value, String parameterType, Integer sequenceNumber) {
133 return new Builder(id, propId, value, parameterType, sequenceNumber);
134 }
135
136
137
138
139
140
141
142 public static Builder create(PropositionParameterContract contract) {
143 if (contract == null) {
144 throw new IllegalArgumentException("contract is null");
145 }
146 Builder builder = new Builder(contract.getId(), contract.getPropId(), contract.getValue(), contract.getParameterType(), contract.getSequenceNumber());
147 return builder;
148 }
149
150
151
152
153
154
155
156 public void setId(String id) {
157 if (StringUtils.isBlank(id)) {
158 throw new IllegalArgumentException("id is blank");
159 }
160 this.id = id;
161 }
162
163 public void setPropId(String propId) {
164 if (StringUtils.isBlank(propId)) {
165 throw new IllegalArgumentException("propId is blank");
166 }
167 this.propId = propId;
168 }
169
170 public void setValue(String value) {
171
172 if (StringUtils.isBlank(value)) {
173 throw new IllegalArgumentException("value is blank");
174 }
175 this.value = value;
176 }
177
178 public void setParameterType(String parameterType) {
179 if (StringUtils.isBlank(parameterType)){
180 throw new IllegalArgumentException("parameter type is null or blank");
181 }
182 if (!PropositionParameter.ParameterTypes.VALID_TYPE_CODES.contains(parameterType)){
183 throw new IllegalArgumentException("parameter type is invalid");
184 }
185
186 this.parameterType = parameterType;
187 }
188
189 public void setSequenceNumber(Integer sequenceNumber) {
190 if (sequenceNumber == null) {
191 throw new IllegalArgumentException("parameter type is blank");
192 }
193 this.sequenceNumber = sequenceNumber;
194 }
195
196 @Override
197 public String getId() {
198 return id;
199 }
200
201 @Override
202 public String getPropId() {
203 return propId;
204 }
205
206 @Override
207 public String getValue() {
208 return value;
209 }
210
211 @Override
212 public String getParameterType() {
213 return parameterType;
214 }
215
216 @Override
217 public Integer getSequenceNumber() {
218 return sequenceNumber;
219 }
220
221
222
223
224
225
226 @Override
227 public PropositionParameter build() {
228 return new PropositionParameter(this);
229 }
230
231 }
232 @Override
233 public int hashCode() {
234 return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE);
235 }
236
237 @Override
238 public boolean equals(Object obj) {
239 return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE);
240 }
241
242 @Override
243 public String toString() {
244 return ToStringBuilder.reflectionToString(this);
245 }
246
247
248
249
250 static class Constants {
251 final static String ROOT_ELEMENT_NAME = "PropositionParameter";
252 final static String TYPE_NAME = "PropositionParameterType";
253 final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS };
254 }
255
256
257
258
259
260 public static class Elements {
261 final static String ID = "id";
262 final static String PROP_ID = "propId";
263 final static String VALUE = "value";
264 final static String PARM_TYPE = "parameterType";
265 final static String SEQUENCE = "sequenceNumber";
266 }
267
268
269
270
271 public enum ParameterTypes {
272 CONSTANT("C"),
273 TERM("T"),
274 FUNCTION("F");
275
276 private final String code;
277 private ParameterTypes(String code){
278 this.code = code;
279 }
280 public static final Collection<PropositionParameter.ParameterTypes> VALID_TYPES =
281 Collections.unmodifiableCollection(Arrays.asList(CONSTANT, TERM, FUNCTION));
282
283 public static final Collection<String> VALID_TYPE_CODES =
284 Collections.unmodifiableCollection(Arrays.asList(CONSTANT.code(), TERM.code(), FUNCTION.code()));
285
286 public String code(){
287 return code;
288 }
289 @Override
290 public String toString() {
291 return code;
292 }
293 }
294 }