1 | |
package org.kuali.rice.krms.api.repository.category; |
2 | |
|
3 | |
import org.apache.commons.lang.StringUtils; |
4 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
5 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
6 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
7 | |
import org.kuali.rice.core.api.CoreConstants; |
8 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
9 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
10 | |
import org.w3c.dom.Element; |
11 | |
|
12 | |
import javax.xml.bind.annotation.XmlAccessType; |
13 | |
import javax.xml.bind.annotation.XmlAccessorType; |
14 | |
import javax.xml.bind.annotation.XmlAnyElement; |
15 | |
import javax.xml.bind.annotation.XmlElement; |
16 | |
import javax.xml.bind.annotation.XmlRootElement; |
17 | |
import javax.xml.bind.annotation.XmlType; |
18 | |
import java.io.Serializable; |
19 | |
import java.util.Collection; |
20 | |
|
21 | |
@XmlRootElement(name = CategoryDefinition.Constants.ROOT_ELEMENT_NAME) |
22 | |
@XmlAccessorType(XmlAccessType.NONE) |
23 | |
@XmlType(name = CategoryDefinition.Constants.TYPE_NAME, propOrder = { |
24 | |
CategoryDefinition.Elements.ID, |
25 | |
CategoryDefinition.Elements.NAME, |
26 | |
CategoryDefinition.Elements.NAMESPACE, |
27 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
28 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
29 | |
}) |
30 | 10 | public class CategoryDefinition implements CategoryDefinitionContract, ModelObjectComplete { |
31 | |
|
32 | |
private static final long serialVersionUID = -4748818967880857017L; |
33 | |
|
34 | |
@XmlElement(name = Elements.ID, required=true) |
35 | |
private String id; |
36 | |
@XmlElement(name = Elements.NAME, required=true) |
37 | |
private String name; |
38 | |
@XmlElement(name = Elements.NAMESPACE, required=true) |
39 | |
private String namespace; |
40 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
41 | |
private final Long versionNumber; |
42 | |
|
43 | 16 | @SuppressWarnings("unused") |
44 | |
@XmlAnyElement |
45 | |
private final Collection<Element> _futureElements = null; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 6 | private CategoryDefinition() { |
51 | 6 | this.id = null; |
52 | 6 | this.name = null; |
53 | 6 | this.namespace = null; |
54 | 6 | this.versionNumber = null; |
55 | 6 | } |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | 10 | private CategoryDefinition(Builder builder) { |
64 | 10 | this.id = builder.getId(); |
65 | 10 | this.name = builder.getName(); |
66 | 10 | this.namespace = builder.getNamespace(); |
67 | 10 | this.versionNumber = builder.getVersionNumber(); |
68 | 10 | } |
69 | |
|
70 | |
public String getId() { |
71 | 4 | return this.id; |
72 | |
} |
73 | |
|
74 | |
public String getName() { |
75 | 4 | return this.name; |
76 | |
} |
77 | |
|
78 | |
public String getNamespace() { |
79 | 4 | return this.namespace; |
80 | |
} |
81 | |
|
82 | |
@Override |
83 | |
public Long getVersionNumber() { |
84 | 2 | return versionNumber; |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | 4 | public static class Builder implements CategoryDefinitionContract, ModelBuilder, Serializable { |
91 | |
|
92 | |
private static final long serialVersionUID = -5775478956373560840L; |
93 | |
|
94 | |
private String id; |
95 | |
private String name; |
96 | |
private String namespace; |
97 | |
private Long versionNumber; |
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | 20 | private Builder(String id, String name, String namespace) { |
103 | 20 | setId(id); |
104 | 19 | setName(name); |
105 | 17 | setNamespace(namespace); |
106 | 16 | } |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
public static Builder create(String id, String name, String namespace) { |
118 | 6 | return new Builder(id, name, namespace); |
119 | |
} |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
public static Builder create(CategoryDefinitionContract category) { |
128 | 14 | if (category == null) { |
129 | 0 | throw new IllegalArgumentException("contract is null"); |
130 | |
} |
131 | 14 | Builder builder = new Builder(category.getId(), category.getName(), category.getNamespace()); |
132 | 14 | builder.setVersionNumber(category.getVersionNumber()); |
133 | 14 | return builder; |
134 | |
} |
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
public void setId(String id) { |
143 | 20 | if (null != id && StringUtils.isBlank(id)) { |
144 | 1 | throw new IllegalArgumentException("id must be null or non-blank"); |
145 | |
} |
146 | 19 | this.id = id; |
147 | 19 | } |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
public void setName(String name) { |
158 | 19 | if (StringUtils.isBlank(name)) { |
159 | 2 | throw new IllegalArgumentException("name is blank"); |
160 | |
} |
161 | 17 | this.name = name; |
162 | 17 | } |
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
public void setNamespace(String namespace) { |
173 | 17 | if (StringUtils.isBlank(namespace)) { |
174 | 1 | throw new IllegalArgumentException("namespace is blank"); |
175 | |
} |
176 | 16 | this.namespace = namespace; |
177 | 16 | } |
178 | |
|
179 | |
public void setVersionNumber(Long versionNumber){ |
180 | 14 | this.versionNumber = versionNumber; |
181 | 14 | } |
182 | |
|
183 | |
@Override |
184 | |
public String getId() { |
185 | 16 | return this.id; |
186 | |
} |
187 | |
|
188 | |
@Override |
189 | |
public String getName() { |
190 | 16 | return this.name; |
191 | |
} |
192 | |
|
193 | |
@Override |
194 | |
public String getNamespace() { |
195 | 16 | return this.namespace; |
196 | |
} |
197 | |
|
198 | |
@Override |
199 | |
public Long getVersionNumber() { |
200 | 16 | return this.versionNumber; |
201 | |
} |
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
@Override |
209 | |
public CategoryDefinition build() { |
210 | 10 | return new CategoryDefinition(this); |
211 | |
} |
212 | |
|
213 | |
} |
214 | |
@Override |
215 | |
public int hashCode() { |
216 | 21 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
217 | |
} |
218 | |
|
219 | |
@Override |
220 | |
public boolean equals(Object obj) { |
221 | 6 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
222 | |
} |
223 | |
|
224 | |
@Override |
225 | |
public String toString() { |
226 | 3 | return ToStringBuilder.reflectionToString(this); |
227 | |
} |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | 0 | static class Constants { |
233 | |
final static String ROOT_ELEMENT_NAME = "category"; |
234 | |
final static String TYPE_NAME = "CategoryType"; |
235 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = { CoreConstants.CommonElements.FUTURE_ELEMENTS }; |
236 | |
} |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | 0 | public static class Elements { |
243 | |
final static String ID = "id"; |
244 | |
final static String NAME = "name"; |
245 | |
final static String NAMESPACE = "namespace"; |
246 | |
} |
247 | |
} |
248 | |
|
249 | |
|