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