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