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