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