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