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