Coverage Report - org.kuali.rice.ksb.api.registry.ServiceInfo
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceInfo
0%
0/43
0%
0/2
1.13
ServiceInfo$1
N/A
N/A
1.13
ServiceInfo$Builder
0%
0/101
0%
0/6
1.13
ServiceInfo$Constants
0%
0/1
N/A
1.13
ServiceInfo$Elements
0%
0/1
N/A
1.13
 
 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  
  * Immutable implementation of the {@link ServiceInfoContract} interface.
 23  
  * Includes standard configuration information about a service that has been
 24  
  * published to the service registry.
 25  
  * 
 26  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  0
 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  0
     @SuppressWarnings("unused")
 89  
     @XmlAnyElement
 90  
     private final Collection<Element> _futureElements = null;
 91  
 
 92  
     /**
 93  
      * Private constructor used only by JAXB.
 94  
      * 
 95  
      */
 96  0
     private ServiceInfo() {
 97  0
         this.serviceId = null;
 98  0
         this.serviceName = null;
 99  0
         this.endpointUrl = null;
 100  0
         this.instanceId = null;
 101  0
         this.applicationId = null;
 102  0
         this.serverIpAddress = null;
 103  0
         this.type = null;
 104  0
         this.serviceVersion = null;
 105  0
         this.status = null;
 106  0
         this.serviceDescriptorId = null;
 107  0
         this.checksum = null;
 108  0
         this.versionNumber = null;
 109  0
     }
 110  
 
 111  0
     private ServiceInfo(Builder builder) {
 112  0
         this.serviceId = builder.getServiceId();
 113  0
         this.serviceName = builder.getServiceName();
 114  0
         this.endpointUrl = builder.getEndpointUrl();
 115  0
         this.instanceId = builder.getInstanceId();
 116  0
         this.applicationId = builder.getApplicationId();
 117  0
         this.serverIpAddress = builder.getServerIpAddress();
 118  0
         this.type = builder.getType();
 119  0
         this.serviceVersion = builder.getServiceVersion();
 120  0
         ServiceEndpointStatus builderStatus = builder.getStatus();
 121  0
         this.status = builderStatus == null ? null : builderStatus.getCode();
 122  0
         this.serviceDescriptorId = builder.getServiceDescriptorId();
 123  0
         this.checksum = builder.getChecksum();
 124  0
         this.versionNumber = builder.getVersionNumber();
 125  0
     }
 126  
 
 127  
     @Override
 128  
     public String getServiceId() {
 129  0
         return this.serviceId;
 130  
     }
 131  
 
 132  
     @Override
 133  
     public QName getServiceName() {
 134  0
         return this.serviceName;
 135  
     }
 136  
 
 137  
     @Override
 138  
     public String getEndpointUrl() {
 139  0
         return this.endpointUrl;
 140  
     }
 141  
     
 142  
     @Override
 143  
     public String getInstanceId() {
 144  0
         return this.instanceId;
 145  
     }
 146  
 
 147  
     @Override
 148  
     public String getApplicationId() {
 149  0
         return this.applicationId;
 150  
     }
 151  
 
 152  
     @Override
 153  
     public String getServerIpAddress() {
 154  0
         return this.serverIpAddress;
 155  
     }
 156  
     
 157  
     @Override
 158  
     public String getType() {
 159  0
             return this.type;
 160  
     }
 161  
     
 162  
     @Override
 163  
     public String getServiceVersion() {
 164  0
             return this.serviceVersion;
 165  
     }
 166  
     
 167  
     @Override
 168  
     public ServiceEndpointStatus getStatus() {
 169  0
             return ServiceEndpointStatus.fromCode(this.status);
 170  
     }
 171  
 
 172  
     @Override
 173  
     public String getServiceDescriptorId() {
 174  0
         return this.serviceDescriptorId;
 175  
     }
 176  
     
 177  
     @Override
 178  
     public String getChecksum() {
 179  0
         return this.checksum;
 180  
     }
 181  
 
 182  
     @Override
 183  
     public Long getVersionNumber() {
 184  0
         return this.versionNumber;
 185  
     }
 186  
 
 187  
     /**
 188  
      * A builder which can be used to construct {@link ServiceInfo} instances.
 189  
      * Enforces the constraints of the {@link ServiceInfoContract}.
 190  
      */
 191  0
     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  0
         private Builder() {}
 211  
 
 212  
         public static Builder create() {
 213  0
             return new Builder();
 214  
         }
 215  
 
 216  
         public static Builder create(ServiceInfoContract contract) {
 217  0
             if (contract == null) {
 218  0
                 throw new IllegalArgumentException("contract was null");
 219  
             }
 220  0
             Builder builder = create();
 221  0
             builder.setServiceId(contract.getServiceId());
 222  0
             builder.setServiceName(contract.getServiceName());
 223  0
             builder.setEndpointUrl(contract.getEndpointUrl());
 224  0
             builder.setInstanceId(contract.getInstanceId());
 225  0
             builder.setApplicationId(contract.getApplicationId());
 226  0
             builder.setServerIpAddress(contract.getServerIpAddress());
 227  0
             builder.setType(contract.getType());
 228  0
             builder.setServiceVersion(contract.getServiceVersion());
 229  0
             builder.setStatus(contract.getStatus());
 230  0
             builder.setServiceDescriptorId(contract.getServiceDescriptorId());
 231  0
             builder.setChecksum(contract.getChecksum());
 232  0
             builder.setVersionNumber(contract.getVersionNumber());
 233  0
             return builder;
 234  
         }
 235  
 
 236  
         public ServiceInfo build() {
 237  0
                 validateAll();
 238  0
             return new ServiceInfo(this);
 239  
         }
 240  
 
 241  
         @Override
 242  
         public String getServiceId() {
 243  0
             return this.serviceId;
 244  
         }
 245  
 
 246  
         @Override
 247  
         public QName getServiceName() {
 248  0
             return this.serviceName;
 249  
         }
 250  
 
 251  
         @Override
 252  
         public String getEndpointUrl() {
 253  0
             return this.endpointUrl;
 254  
         }
 255  
         
 256  
         @Override
 257  
         public String getInstanceId() {
 258  0
             return this.instanceId;
 259  
         }
 260  
 
 261  
         @Override
 262  
         public String getApplicationId() {
 263  0
             return this.applicationId;
 264  
         }
 265  
 
 266  
         @Override
 267  
         public String getServerIpAddress() {
 268  0
             return this.serverIpAddress;
 269  
         }
 270  
         
 271  
         @Override
 272  
         public String getType() {
 273  0
                 return this.type;
 274  
         }
 275  
         
 276  
         @Override
 277  
         public String getServiceVersion() {
 278  0
                 return this.serviceVersion;
 279  
         }
 280  
 
 281  
         @Override
 282  
         public ServiceEndpointStatus getStatus() {
 283  0
                 return this.status;
 284  
         }
 285  
         
 286  
         @Override
 287  
         public String getServiceDescriptorId() {
 288  0
             return this.serviceDescriptorId;
 289  
         }
 290  
         
 291  
         @Override
 292  
         public String getChecksum() {
 293  0
             return this.checksum;
 294  
         }
 295  
 
 296  
         @Override
 297  
         public Long getVersionNumber() {
 298  0
             return this.versionNumber;
 299  
         }
 300  
 
 301  
         public void setServiceId(String serviceId) {
 302  0
             this.serviceId = serviceId;
 303  0
         }
 304  
 
 305  
         public void setServiceName(QName serviceName) {
 306  0
             validateServiceName(serviceName);
 307  0
             this.serviceName = serviceName;
 308  0
         }
 309  
 
 310  
         public void setEndpointUrl(String endpointUrl) {
 311  0
             validateEndpointUrl(endpointUrl);
 312  0
             this.endpointUrl = endpointUrl;
 313  0
         }
 314  
         
 315  
         public void setInstanceId(String instanceId) {
 316  0
             validateInstanceId(instanceId);
 317  0
             this.instanceId = instanceId;
 318  0
         }
 319  
 
 320  
         public void setApplicationId(String applicationId) {
 321  0
             validateApplicationId(applicationId);
 322  0
             this.applicationId = applicationId;
 323  0
         }
 324  
 
 325  
         public void setServerIpAddress(String serverIpAddress) {
 326  0
                 validateServerIpAddress(serverIpAddress);
 327  0
             this.serverIpAddress = serverIpAddress;
 328  0
         }
 329  
         
 330  
         public void setType(String type) {
 331  0
                 validateType(type);
 332  0
                 this.type = type;
 333  0
         }
 334  
         
 335  
         public void setServiceVersion(String serviceVersion) {
 336  0
                 validateServiceVersion(serviceVersion);
 337  0
                 this.serviceVersion = serviceVersion;
 338  0
         }
 339  
         
 340  
         public void setStatus(ServiceEndpointStatus status) {
 341  0
                 validateStatus(status);
 342  0
                 this.status = status;
 343  0
         }
 344  
 
 345  
         public void setServiceDescriptorId(String serviceDescriptorId) {
 346  0
             this.serviceDescriptorId = serviceDescriptorId;
 347  0
         }
 348  
         
 349  
         public void setChecksum(String checksum) {
 350  0
             validateChecksum(checksum);
 351  0
             this.checksum = checksum;
 352  0
         }
 353  
 
 354  
         public void setVersionNumber(Long versionNumber) {
 355  0
             this.versionNumber = versionNumber;
 356  0
         }
 357  
         
 358  
         private void assertNotNull(String name, Object object) {
 359  0
                 if (object == null) {
 360  0
                         throw new IllegalArgumentException(name + " was null");
 361  
                 }
 362  0
         }
 363  
         
 364  
         private void assertNotBlank(String name, String value) {
 365  0
                 assertNotNull(name, value);
 366  0
                 if (StringUtils.isBlank(value)) {
 367  0
                         throw new IllegalArgumentException(name + " was blank");
 368  
                 }
 369  0
         }
 370  
         
 371  
         private void validateServiceName(QName serviceName) {
 372  0
                 assertNotNull("serviceName", serviceName);
 373  0
         }
 374  
         
 375  
         private void validateEndpointUrl(String endpointUrl) {
 376  0
                 assertNotBlank("endpointUrl", endpointUrl);
 377  0
         }
 378  
         
 379  
         private void validateInstanceId(String instanceId) {
 380  0
                 assertNotBlank("instanceId", instanceId);
 381  0
         }
 382  
         
 383  
         private void validateApplicationId(String applicationId) {
 384  0
                 assertNotBlank("applicationId", applicationId);
 385  0
         }
 386  
         
 387  
         private void validateServerIpAddress(String serverIpAddress) {
 388  0
                 assertNotBlank("serverIpAddress", serverIpAddress);
 389  0
         }
 390  
         
 391  
         private void validateType(String type) {
 392  0
                 assertNotBlank("type", type);
 393  0
         }
 394  
 
 395  
         private void validateServiceVersion(String serviceVersion) {
 396  0
                 assertNotBlank("serviceVersion", serviceVersion);
 397  0
         }
 398  
         
 399  
         private void validateStatus(ServiceEndpointStatus status) {
 400  0
                 assertNotNull("status", status);
 401  0
         }
 402  
         
 403  
         private void validateChecksum(String checksum) {
 404  0
                 assertNotBlank("checksum", checksum);
 405  0
         }
 406  
         
 407  
         private void validateAll() {
 408  0
                 validateServiceName(serviceName);
 409  0
             validateEndpointUrl(endpointUrl);
 410  0
             validateInstanceId(instanceId);
 411  0
             validateApplicationId(applicationId);
 412  0
             validateServerIpAddress(serverIpAddress);
 413  0
             validateType(type);
 414  0
             validateServiceVersion(serviceVersion);
 415  0
             validateStatus(status);
 416  0
             validateChecksum(checksum);
 417  0
         }
 418  
 
 419  
     }
 420  
 
 421  
 
 422  
     /**
 423  
      * Defines some internal constants used on this class.
 424  
      * 
 425  
      */
 426  0
     static class Constants {
 427  
 
 428  
         final static String ROOT_ELEMENT_NAME = "serviceInfo";
 429  
         final static String TYPE_NAME = "ServiceInfoType";
 430  
     }
 431  
 
 432  
 
 433  
     /**
 434  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 435  
      * 
 436  
      */
 437  0
     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