1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.core.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=true)
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=false)
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")
75 @XmlAnyElement
76 private final Collection<Element> _futureElements = null;
77
78
79
80
81 private Namespace() {
82 this.code = null;
83 this.applicationId = null;
84 this.name = null;
85 this.active = true;
86 this.versionNumber = null;
87 this.objectId = null;
88 }
89
90
91
92
93
94
95
96 private Namespace(Builder builder) {
97 code = builder.getCode();
98 applicationId = builder.getApplicationId();
99 name = builder.getName();
100 active = builder.isActive();
101 versionNumber = builder.getVersionNumber();
102 objectId = builder.getObjectId();
103 }
104
105 @Override
106 public String getCode() {
107 return code;
108 }
109
110 @Override
111 public String getApplicationId() {
112 return applicationId;
113 }
114
115 @Override
116 public String getName() {
117 return name;
118 }
119
120 @Override
121 public boolean isActive() {
122 return active;
123 }
124
125 @Override
126 public Long getVersionNumber() {
127 return versionNumber;
128 }
129
130 @Override
131 public String getObjectId() {
132 return objectId;
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, String applicationId) {
157 setCode(code);
158 setApplicationId(applicationId);
159 setActive(true);
160 }
161
162
163
164
165
166
167
168
169
170 public static Builder create(String code, String applicationId) {
171 return new Builder(code, applicationId);
172 }
173
174
175
176
177
178
179
180 public static Builder create(NamespaceContract contract) {
181 Builder builder = new Builder(contract.getCode(), contract.getApplicationId());
182 builder.setName(contract.getName());
183 builder.setActive(contract.isActive());
184 builder.setVersionNumber(contract.getVersionNumber());
185 builder.setObjectId(contract.getObjectId());
186 return builder;
187 }
188
189
190
191
192
193
194
195 public void setCode(String code) {
196 if (StringUtils.isBlank(code)) {
197 throw new IllegalArgumentException("code is blank");
198 }
199 this.code = code;
200 }
201
202
203
204
205
206
207
208 public void setApplicationId(String applicationId) {
209 if (StringUtils.isBlank(applicationId)) {
210 throw new IllegalArgumentException("applicationId is blank");
211 }
212 this.applicationId = applicationId;
213 }
214
215 public void setVersionNumber(Long versionNumber) {
216 this.versionNumber = versionNumber;
217 }
218
219 public void setObjectId(String objectId) {
220 this.objectId = objectId;
221 }
222
223 @Override
224 public String getName() {
225 return name;
226 }
227
228 public void setName(String name) {
229 this.name = name;
230 }
231
232 @Override
233 public boolean isActive() {
234 return active;
235 }
236
237 public void setActive(boolean active) {
238 this.active = active;
239 }
240
241 @Override
242 public String getCode() {
243 return code;
244 }
245
246 @Override
247 public String getApplicationId() {
248 return applicationId;
249 }
250
251 @Override
252 public Long getVersionNumber() {
253 return versionNumber;
254 }
255
256 @Override
257 public String getObjectId() {
258 return objectId;
259 }
260
261
262
263
264
265
266 @Override
267 public Namespace build() {
268 return new Namespace(this);
269 }
270
271 }
272
273
274
275
276 static class Constants {
277 final static String ROOT_ELEMENT_NAME = "namespace";
278 final static String TYPE_NAME = "NamespaceType";
279 }
280
281
282
283
284
285 static class Elements {
286 final static String CODE = "code";
287 final static String APPLICATION_ID = "applicationId";
288 final static String NAME = "name";
289 final static String ACTIVE = "active";
290 }
291
292 }