1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.coreservice.api.namespace;
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 import org.w3c.dom.Element;
33
34
35
36
37
38
39
40
41 @XmlRootElement(name = Namespace.Constants.ROOT_ELEMENT_NAME)
42 @XmlAccessorType(XmlAccessType.NONE)
43 @XmlType(name = Namespace.Constants.TYPE_NAME, propOrder = {
44 Namespace.Elements.CODE,
45 Namespace.Elements.APPLICATION_ID,
46 Namespace.Elements.NAME,
47 Namespace.Elements.ACTIVE,
48 CoreConstants.CommonElements.VERSION_NUMBER,
49 CoreConstants.CommonElements.OBJECT_ID,
50 CoreConstants.CommonElements.FUTURE_ELEMENTS
51 })
52 public final class Namespace extends AbstractDataTransferObject implements NamespaceContract {
53
54 private static final long serialVersionUID = -5206398776503106883L;
55
56 @XmlElement(name = Elements.CODE, required = true)
57 private final String code;
58
59 @XmlElement(name = Elements.APPLICATION_ID, required = false)
60 private final String applicationId;
61
62 @XmlElement(name = Elements.NAME, required = false)
63 private final String name;
64
65 @XmlElement(name = Elements.ACTIVE, required = true)
66 private final boolean active;
67
68 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
69 private final Long versionNumber;
70
71 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
72 private final String objectId;
73
74 @SuppressWarnings("unused") @XmlAnyElement
75 private final Collection<Element> _futureElements = null;
76
77
78
79
80 private Namespace() {
81 this.code = null;
82 this.applicationId = null;
83 this.name = null;
84 this.active = true;
85 this.versionNumber = null;
86 this.objectId = null;
87 }
88
89
90
91
92
93
94
95 private Namespace(Builder builder) {
96 code = builder.getCode();
97 applicationId = builder.getApplicationId();
98 name = builder.getName();
99 active = builder.isActive();
100 versionNumber = builder.getVersionNumber();
101 objectId = builder.getObjectId();
102 }
103
104 @Override
105 public String getCode() {
106 return code;
107 }
108
109 @Override
110 public String getApplicationId() {
111 return applicationId;
112 }
113
114 @Override
115 public String getName() {
116 return name;
117 }
118
119 @Override
120 public boolean isActive() {
121 return active;
122 }
123
124 @Override
125 public Long getVersionNumber() {
126 return versionNumber;
127 }
128
129 @Override
130 public String getObjectId() {
131 return objectId;
132 }
133
134
135
136
137
138 public static final class Builder implements NamespaceContract, ModelBuilder, Serializable {
139
140 private static final long serialVersionUID = -70194982373806749L;
141
142 private String code;
143 private String applicationId;
144 private String name;
145 private boolean active;
146 private Long versionNumber;
147 private String objectId;
148
149
150
151
152
153
154
155
156 private Builder(String code) {
157 setCode(code);
158 setActive(true);
159 }
160
161
162
163
164
165
166
167
168 public static Builder create(String code) {
169 return new Builder(code);
170 }
171
172
173
174
175
176
177
178
179
180 public static Builder create(String code, String applicationId) {
181 Builder builder = new Builder(code);
182 builder.setApplicationId(applicationId);
183 return builder;
184 }
185
186
187
188
189
190
191
192 public static Builder create(NamespaceContract contract) {
193 if (contract == null) {
194 throw new IllegalArgumentException("contract was null");
195 }
196 Builder builder = new Builder(contract.getCode());
197 builder.setApplicationId(contract.getApplicationId());
198 builder.setName(contract.getName());
199 builder.setActive(contract.isActive());
200 builder.setVersionNumber(contract.getVersionNumber());
201 builder.setObjectId(contract.getObjectId());
202 return builder;
203 }
204
205
206
207
208
209
210
211 public void setCode(String code) {
212 if (StringUtils.isBlank(code)) {
213 throw new IllegalArgumentException("code is blank");
214 }
215 this.code = code;
216 }
217
218
219
220
221
222
223
224 public void setApplicationId(String applicationId) {
225 this.applicationId = applicationId;
226 }
227
228 public void setVersionNumber(Long versionNumber) {
229 this.versionNumber = versionNumber;
230 }
231
232 public void setObjectId(String objectId) {
233 this.objectId = objectId;
234 }
235
236 @Override
237 public String getName() {
238 return name;
239 }
240
241 public void setName(String name) {
242 this.name = name;
243 }
244
245 @Override
246 public boolean isActive() {
247 return active;
248 }
249
250 public void setActive(boolean active) {
251 this.active = active;
252 }
253
254 @Override
255 public String getCode() {
256 return code;
257 }
258
259 @Override
260 public String getApplicationId() {
261 return applicationId;
262 }
263
264 @Override
265 public Long getVersionNumber() {
266 return versionNumber;
267 }
268
269 @Override
270 public String getObjectId() {
271 return objectId;
272 }
273
274
275
276
277
278
279 @Override
280 public Namespace build() {
281 return new Namespace(this);
282 }
283
284 }
285
286
287
288
289 static class Constants {
290 final static String ROOT_ELEMENT_NAME = "namespace";
291 final static String TYPE_NAME = "NamespaceType";
292 }
293
294
295
296
297
298 static class Elements {
299 final static String CODE = "code";
300 final static String APPLICATION_ID = "applicationId";
301 final static String NAME = "name";
302 final static String ACTIVE = "active";
303 }
304
305 public static class Cache {
306 public static final String NAME =
307 CoreConstants.Namespaces.CORE_NAMESPACE_2_0 + "/" + Namespace.Constants.TYPE_NAME;
308 }
309
310 }