1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ksb.api.registry;
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.util.jaxb.QNameAsStringAdapter;
23 import org.w3c.dom.Element;
24
25 import javax.xml.bind.annotation.XmlAccessType;
26 import javax.xml.bind.annotation.XmlAccessorType;
27 import javax.xml.bind.annotation.XmlAnyElement;
28 import javax.xml.bind.annotation.XmlElement;
29 import javax.xml.bind.annotation.XmlRootElement;
30 import javax.xml.bind.annotation.XmlType;
31 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
32 import javax.xml.namespace.QName;
33 import java.io.Serializable;
34 import java.util.Collection;
35
36
37
38
39
40
41
42
43
44 @XmlRootElement(name = ServiceInfo.Constants.ROOT_ELEMENT_NAME)
45 @XmlAccessorType(XmlAccessType.NONE)
46 @XmlType(name = ServiceInfo.Constants.TYPE_NAME, propOrder = {
47 ServiceInfo.Elements.SERVICE_ID,
48 ServiceInfo.Elements.SERVICE_NAME,
49 ServiceInfo.Elements.ENDPOINT_URL,
50 ServiceInfo.Elements.INSTANCE_ID,
51 ServiceInfo.Elements.APPLICATION_ID,
52 ServiceInfo.Elements.SERVER_IP_ADDRESS,
53 ServiceInfo.Elements.TYPE,
54 ServiceInfo.Elements.SERVICE_VERSION,
55 ServiceInfo.Elements.STATUS,
56 ServiceInfo.Elements.SERVICE_DESCRIPTOR_ID,
57 ServiceInfo.Elements.CHECKSUM,
58 CoreConstants.CommonElements.VERSION_NUMBER,
59 CoreConstants.CommonElements.FUTURE_ELEMENTS
60 })
61 public final class ServiceInfo extends AbstractDataTransferObject implements ServiceInfoContract {
62
63 private static final long serialVersionUID = 4793306414624564991L;
64
65 @XmlElement(name = Elements.SERVICE_ID, required = false)
66 private final String serviceId;
67
68 @XmlJavaTypeAdapter(QNameAsStringAdapter.class)
69 @XmlElement(name = Elements.SERVICE_NAME, required = true)
70 private final QName serviceName;
71
72 @XmlElement(name = Elements.ENDPOINT_URL, required = true)
73 private final String endpointUrl;
74
75 @XmlElement(name = Elements.INSTANCE_ID, required = true)
76 private final String instanceId;
77
78 @XmlElement(name = Elements.APPLICATION_ID, required = true)
79 private final String applicationId;
80
81 @XmlElement(name = Elements.SERVER_IP_ADDRESS, required = true)
82 private final String serverIpAddress;
83
84 @XmlElement(name = Elements.TYPE, required = true)
85 private final String type;
86
87 @XmlElement(name = Elements.SERVICE_VERSION, required = true)
88 private final String serviceVersion;
89
90 @XmlJavaTypeAdapter(ServiceEndpointStatus.Adapter.class)
91 @XmlElement(name = Elements.STATUS, required = true)
92 private final String status;
93
94 @XmlElement(name = Elements.SERVICE_DESCRIPTOR_ID, required = false)
95 private final String serviceDescriptorId;
96
97 @XmlElement(name = Elements.CHECKSUM, required = true)
98 private final String checksum;
99
100 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
101 private final Long versionNumber;
102
103 @SuppressWarnings("unused")
104 @XmlAnyElement
105 private final Collection<Element> _futureElements = null;
106
107
108
109
110
111 private ServiceInfo() {
112 this.serviceId = null;
113 this.serviceName = null;
114 this.endpointUrl = null;
115 this.instanceId = null;
116 this.applicationId = null;
117 this.serverIpAddress = null;
118 this.type = null;
119 this.serviceVersion = null;
120 this.status = null;
121 this.serviceDescriptorId = null;
122 this.checksum = null;
123 this.versionNumber = null;
124 }
125
126 private ServiceInfo(Builder builder) {
127 this.serviceId = builder.getServiceId();
128 this.serviceName = builder.getServiceName();
129 this.endpointUrl = builder.getEndpointUrl();
130 this.instanceId = builder.getInstanceId();
131 this.applicationId = builder.getApplicationId();
132 this.serverIpAddress = builder.getServerIpAddress();
133 this.type = builder.getType();
134 this.serviceVersion = builder.getServiceVersion();
135 ServiceEndpointStatus builderStatus = builder.getStatus();
136 this.status = builderStatus == null ? null : builderStatus.getCode();
137 this.serviceDescriptorId = builder.getServiceDescriptorId();
138 this.checksum = builder.getChecksum();
139 this.versionNumber = builder.getVersionNumber();
140 }
141
142 @Override
143 public String getServiceId() {
144 return this.serviceId;
145 }
146
147 @Override
148 public QName getServiceName() {
149 return this.serviceName;
150 }
151
152 @Override
153 public String getEndpointUrl() {
154 return this.endpointUrl;
155 }
156
157 @Override
158 public String getInstanceId() {
159 return this.instanceId;
160 }
161
162 @Override
163 public String getApplicationId() {
164 return this.applicationId;
165 }
166
167 @Override
168 public String getServerIpAddress() {
169 return this.serverIpAddress;
170 }
171
172 @Override
173 public String getType() {
174 return this.type;
175 }
176
177 @Override
178 public String getServiceVersion() {
179 return this.serviceVersion;
180 }
181
182 @Override
183 public ServiceEndpointStatus getStatus() {
184 return ServiceEndpointStatus.fromCode(this.status);
185 }
186
187 @Override
188 public String getServiceDescriptorId() {
189 return this.serviceDescriptorId;
190 }
191
192 @Override
193 public String getChecksum() {
194 return this.checksum;
195 }
196
197 @Override
198 public Long getVersionNumber() {
199 return this.versionNumber;
200 }
201
202
203
204
205
206 public final static class Builder
207 implements Serializable, ModelBuilder, ServiceInfoContract
208 {
209
210 private static final long serialVersionUID = 4424090938369742940L;
211
212 private String serviceId;
213 private QName serviceName;
214 private String endpointUrl;
215 private String instanceId;
216 private String applicationId;
217 private String serverIpAddress;
218 private String type;
219 private String serviceVersion;
220 private ServiceEndpointStatus status;
221 private String serviceDescriptorId;
222 private String checksum;
223 private Long versionNumber;
224
225 private Builder() {}
226
227 public static Builder create() {
228 return new Builder();
229 }
230
231 public static Builder create(ServiceInfoContract contract) {
232 if (contract == null) {
233 throw new IllegalArgumentException("contract was null");
234 }
235 Builder builder = create();
236 builder.setServiceId(contract.getServiceId());
237 builder.setServiceName(contract.getServiceName());
238 builder.setEndpointUrl(contract.getEndpointUrl());
239 builder.setInstanceId(contract.getInstanceId());
240 builder.setApplicationId(contract.getApplicationId());
241 builder.setServerIpAddress(contract.getServerIpAddress());
242 builder.setType(contract.getType());
243 builder.setServiceVersion(contract.getServiceVersion());
244 builder.setStatus(contract.getStatus());
245 builder.setServiceDescriptorId(contract.getServiceDescriptorId());
246 builder.setChecksum(contract.getChecksum());
247 builder.setVersionNumber(contract.getVersionNumber());
248 return builder;
249 }
250
251 public ServiceInfo build() {
252 validateAll();
253 return new ServiceInfo(this);
254 }
255
256 @Override
257 public String getServiceId() {
258 return this.serviceId;
259 }
260
261 @Override
262 public QName getServiceName() {
263 return this.serviceName;
264 }
265
266 @Override
267 public String getEndpointUrl() {
268 return this.endpointUrl;
269 }
270
271 @Override
272 public String getInstanceId() {
273 return this.instanceId;
274 }
275
276 @Override
277 public String getApplicationId() {
278 return this.applicationId;
279 }
280
281 @Override
282 public String getServerIpAddress() {
283 return this.serverIpAddress;
284 }
285
286 @Override
287 public String getType() {
288 return this.type;
289 }
290
291 @Override
292 public String getServiceVersion() {
293 return this.serviceVersion;
294 }
295
296 @Override
297 public ServiceEndpointStatus getStatus() {
298 return this.status;
299 }
300
301 @Override
302 public String getServiceDescriptorId() {
303 return this.serviceDescriptorId;
304 }
305
306 @Override
307 public String getChecksum() {
308 return this.checksum;
309 }
310
311 @Override
312 public Long getVersionNumber() {
313 return this.versionNumber;
314 }
315
316 public void setServiceId(String serviceId) {
317 this.serviceId = serviceId;
318 }
319
320 public void setServiceName(QName serviceName) {
321 validateServiceName(serviceName);
322 this.serviceName = serviceName;
323 }
324
325 public void setEndpointUrl(String endpointUrl) {
326 validateEndpointUrl(endpointUrl);
327 this.endpointUrl = endpointUrl;
328 }
329
330 public void setInstanceId(String instanceId) {
331 validateInstanceId(instanceId);
332 this.instanceId = instanceId;
333 }
334
335 public void setApplicationId(String applicationId) {
336 validateApplicationId(applicationId);
337 this.applicationId = applicationId;
338 }
339
340 public void setServerIpAddress(String serverIpAddress) {
341 validateServerIpAddress(serverIpAddress);
342 this.serverIpAddress = serverIpAddress;
343 }
344
345 public void setType(String type) {
346 validateType(type);
347 this.type = type;
348 }
349
350 public void setServiceVersion(String serviceVersion) {
351 validateServiceVersion(serviceVersion);
352 this.serviceVersion = serviceVersion;
353 }
354
355 public void setStatus(ServiceEndpointStatus status) {
356 validateStatus(status);
357 this.status = status;
358 }
359
360 public void setServiceDescriptorId(String serviceDescriptorId) {
361 this.serviceDescriptorId = serviceDescriptorId;
362 }
363
364 public void setChecksum(String checksum) {
365 validateChecksum(checksum);
366 this.checksum = checksum;
367 }
368
369 public void setVersionNumber(Long versionNumber) {
370 this.versionNumber = versionNumber;
371 }
372
373 private void assertNotNull(String name, Object object) {
374 if (object == null) {
375 throw new IllegalArgumentException(name + " was null");
376 }
377 }
378
379 private void assertNotBlank(String name, String value) {
380 assertNotNull(name, value);
381 if (StringUtils.isBlank(value)) {
382 throw new IllegalArgumentException(name + " was blank");
383 }
384 }
385
386 private void validateServiceName(QName serviceName) {
387 assertNotNull("serviceName", serviceName);
388 }
389
390 private void validateEndpointUrl(String endpointUrl) {
391 assertNotBlank("endpointUrl", endpointUrl);
392 }
393
394 private void validateInstanceId(String instanceId) {
395 assertNotBlank("instanceId", instanceId);
396 }
397
398 private void validateApplicationId(String applicationId) {
399 assertNotBlank("applicationId", applicationId);
400 }
401
402 private void validateServerIpAddress(String serverIpAddress) {
403 assertNotBlank("serverIpAddress", serverIpAddress);
404 }
405
406 private void validateType(String type) {
407 assertNotBlank("type", type);
408 }
409
410 private void validateServiceVersion(String serviceVersion) {
411 assertNotBlank("serviceVersion", serviceVersion);
412 }
413
414 private void validateStatus(ServiceEndpointStatus status) {
415 assertNotNull("status", status);
416 }
417
418 private void validateChecksum(String checksum) {
419 assertNotBlank("checksum", checksum);
420 }
421
422 private void validateAll() {
423 validateServiceName(serviceName);
424 validateEndpointUrl(endpointUrl);
425 validateInstanceId(instanceId);
426 validateApplicationId(applicationId);
427 validateServerIpAddress(serverIpAddress);
428 validateType(type);
429 validateServiceVersion(serviceVersion);
430 validateStatus(status);
431 validateChecksum(checksum);
432 }
433
434 }
435
436
437
438
439
440
441 static class Constants {
442
443 final static String ROOT_ELEMENT_NAME = "serviceInfo";
444 final static String TYPE_NAME = "ServiceInfoType";
445 }
446
447
448
449
450
451
452 static class Elements {
453
454 final static String SERVICE_ID = "serviceId";
455 final static String SERVICE_NAME = "serviceName";
456 final static String ENDPOINT_URL = "endpointUrl";
457 final static String INSTANCE_ID = "instanceId";
458 final static String APPLICATION_ID = "applicationId";
459 final static String SERVER_IP_ADDRESS = "serverIpAddress";
460 final static String TYPE = "type";
461 final static String SERVICE_VERSION = "serviceVersion";
462 final static String STATUS = "status";
463 final static String SERVICE_DESCRIPTOR_ID = "serviceDescriptorId";
464 final static String CHECKSUM = "checksum";
465
466 }
467
468 }
469