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