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  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 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  
  * Immutable implementation of the {@link ServiceInfoContract} interface.
 38  
  * Includes standard configuration information about a service that has been
 39  
  * published to the service registry.
 40  
  * 
 41  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  0
 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  0
     @SuppressWarnings("unused")
 104  
     @XmlAnyElement
 105  
     private final Collection<Element> _futureElements = null;
 106  
 
 107  
     /**
 108  
      * Private constructor used only by JAXB.
 109  
      * 
 110  
      */
 111  0
     private ServiceInfo() {
 112  0
         this.serviceId = null;
 113  0
         this.serviceName = null;
 114  0
         this.endpointUrl = null;
 115  0
         this.instanceId = null;
 116  0
         this.applicationId = null;
 117  0
         this.serverIpAddress = null;
 118  0
         this.type = null;
 119  0
         this.serviceVersion = null;
 120  0
         this.status = null;
 121  0
         this.serviceDescriptorId = null;
 122  0
         this.checksum = null;
 123  0
         this.versionNumber = null;
 124  0
     }
 125  
 
 126  0
     private ServiceInfo(Builder builder) {
 127  0
         this.serviceId = builder.getServiceId();
 128  0
         this.serviceName = builder.getServiceName();
 129  0
         this.endpointUrl = builder.getEndpointUrl();
 130  0
         this.instanceId = builder.getInstanceId();
 131  0
         this.applicationId = builder.getApplicationId();
 132  0
         this.serverIpAddress = builder.getServerIpAddress();
 133  0
         this.type = builder.getType();
 134  0
         this.serviceVersion = builder.getServiceVersion();
 135  0
         ServiceEndpointStatus builderStatus = builder.getStatus();
 136  0
         this.status = builderStatus == null ? null : builderStatus.getCode();
 137  0
         this.serviceDescriptorId = builder.getServiceDescriptorId();
 138  0
         this.checksum = builder.getChecksum();
 139  0
         this.versionNumber = builder.getVersionNumber();
 140  0
     }
 141  
 
 142  
     @Override
 143  
     public String getServiceId() {
 144  0
         return this.serviceId;
 145  
     }
 146  
 
 147  
     @Override
 148  
     public QName getServiceName() {
 149  0
         return this.serviceName;
 150  
     }
 151  
 
 152  
     @Override
 153  
     public String getEndpointUrl() {
 154  0
         return this.endpointUrl;
 155  
     }
 156  
     
 157  
     @Override
 158  
     public String getInstanceId() {
 159  0
         return this.instanceId;
 160  
     }
 161  
 
 162  
     @Override
 163  
     public String getApplicationId() {
 164  0
         return this.applicationId;
 165  
     }
 166  
 
 167  
     @Override
 168  
     public String getServerIpAddress() {
 169  0
         return this.serverIpAddress;
 170  
     }
 171  
     
 172  
     @Override
 173  
     public String getType() {
 174  0
             return this.type;
 175  
     }
 176  
     
 177  
     @Override
 178  
     public String getServiceVersion() {
 179  0
             return this.serviceVersion;
 180  
     }
 181  
     
 182  
     @Override
 183  
     public ServiceEndpointStatus getStatus() {
 184  0
             return ServiceEndpointStatus.fromCode(this.status);
 185  
     }
 186  
 
 187  
     @Override
 188  
     public String getServiceDescriptorId() {
 189  0
         return this.serviceDescriptorId;
 190  
     }
 191  
     
 192  
     @Override
 193  
     public String getChecksum() {
 194  0
         return this.checksum;
 195  
     }
 196  
 
 197  
     @Override
 198  
     public Long getVersionNumber() {
 199  0
         return this.versionNumber;
 200  
     }
 201  
 
 202  
     /**
 203  
      * A builder which can be used to construct {@link ServiceInfo} instances.
 204  
      * Enforces the constraints of the {@link ServiceInfoContract}.
 205  
      */
 206  0
     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  0
         private Builder() {}
 226  
 
 227  
         public static Builder create() {
 228  0
             return new Builder();
 229  
         }
 230  
 
 231  
         public static Builder create(ServiceInfoContract contract) {
 232  0
             if (contract == null) {
 233  0
                 throw new IllegalArgumentException("contract was null");
 234  
             }
 235  0
             Builder builder = create();
 236  0
             builder.setServiceId(contract.getServiceId());
 237  0
             builder.setServiceName(contract.getServiceName());
 238  0
             builder.setEndpointUrl(contract.getEndpointUrl());
 239  0
             builder.setInstanceId(contract.getInstanceId());
 240  0
             builder.setApplicationId(contract.getApplicationId());
 241  0
             builder.setServerIpAddress(contract.getServerIpAddress());
 242  0
             builder.setType(contract.getType());
 243  0
             builder.setServiceVersion(contract.getServiceVersion());
 244  0
             builder.setStatus(contract.getStatus());
 245  0
             builder.setServiceDescriptorId(contract.getServiceDescriptorId());
 246  0
             builder.setChecksum(contract.getChecksum());
 247  0
             builder.setVersionNumber(contract.getVersionNumber());
 248  0
             return builder;
 249  
         }
 250  
 
 251  
         public ServiceInfo build() {
 252  0
                 validateAll();
 253  0
             return new ServiceInfo(this);
 254  
         }
 255  
 
 256  
         @Override
 257  
         public String getServiceId() {
 258  0
             return this.serviceId;
 259  
         }
 260  
 
 261  
         @Override
 262  
         public QName getServiceName() {
 263  0
             return this.serviceName;
 264  
         }
 265  
 
 266  
         @Override
 267  
         public String getEndpointUrl() {
 268  0
             return this.endpointUrl;
 269  
         }
 270  
         
 271  
         @Override
 272  
         public String getInstanceId() {
 273  0
             return this.instanceId;
 274  
         }
 275  
 
 276  
         @Override
 277  
         public String getApplicationId() {
 278  0
             return this.applicationId;
 279  
         }
 280  
 
 281  
         @Override
 282  
         public String getServerIpAddress() {
 283  0
             return this.serverIpAddress;
 284  
         }
 285  
         
 286  
         @Override
 287  
         public String getType() {
 288  0
                 return this.type;
 289  
         }
 290  
         
 291  
         @Override
 292  
         public String getServiceVersion() {
 293  0
                 return this.serviceVersion;
 294  
         }
 295  
 
 296  
         @Override
 297  
         public ServiceEndpointStatus getStatus() {
 298  0
                 return this.status;
 299  
         }
 300  
         
 301  
         @Override
 302  
         public String getServiceDescriptorId() {
 303  0
             return this.serviceDescriptorId;
 304  
         }
 305  
         
 306  
         @Override
 307  
         public String getChecksum() {
 308  0
             return this.checksum;
 309  
         }
 310  
 
 311  
         @Override
 312  
         public Long getVersionNumber() {
 313  0
             return this.versionNumber;
 314  
         }
 315  
 
 316  
         public void setServiceId(String serviceId) {
 317  0
             this.serviceId = serviceId;
 318  0
         }
 319  
 
 320  
         public void setServiceName(QName serviceName) {
 321  0
             validateServiceName(serviceName);
 322  0
             this.serviceName = serviceName;
 323  0
         }
 324  
 
 325  
         public void setEndpointUrl(String endpointUrl) {
 326  0
             validateEndpointUrl(endpointUrl);
 327  0
             this.endpointUrl = endpointUrl;
 328  0
         }
 329  
         
 330  
         public void setInstanceId(String instanceId) {
 331  0
             validateInstanceId(instanceId);
 332  0
             this.instanceId = instanceId;
 333  0
         }
 334  
 
 335  
         public void setApplicationId(String applicationId) {
 336  0
             validateApplicationId(applicationId);
 337  0
             this.applicationId = applicationId;
 338  0
         }
 339  
 
 340  
         public void setServerIpAddress(String serverIpAddress) {
 341  0
                 validateServerIpAddress(serverIpAddress);
 342  0
             this.serverIpAddress = serverIpAddress;
 343  0
         }
 344  
         
 345  
         public void setType(String type) {
 346  0
                 validateType(type);
 347  0
                 this.type = type;
 348  0
         }
 349  
         
 350  
         public void setServiceVersion(String serviceVersion) {
 351  0
                 validateServiceVersion(serviceVersion);
 352  0
                 this.serviceVersion = serviceVersion;
 353  0
         }
 354  
         
 355  
         public void setStatus(ServiceEndpointStatus status) {
 356  0
                 validateStatus(status);
 357  0
                 this.status = status;
 358  0
         }
 359  
 
 360  
         public void setServiceDescriptorId(String serviceDescriptorId) {
 361  0
             this.serviceDescriptorId = serviceDescriptorId;
 362  0
         }
 363  
         
 364  
         public void setChecksum(String checksum) {
 365  0
             validateChecksum(checksum);
 366  0
             this.checksum = checksum;
 367  0
         }
 368  
 
 369  
         public void setVersionNumber(Long versionNumber) {
 370  0
             this.versionNumber = versionNumber;
 371  0
         }
 372  
         
 373  
         private void assertNotNull(String name, Object object) {
 374  0
                 if (object == null) {
 375  0
                         throw new IllegalArgumentException(name + " was null");
 376  
                 }
 377  0
         }
 378  
         
 379  
         private void assertNotBlank(String name, String value) {
 380  0
                 assertNotNull(name, value);
 381  0
                 if (StringUtils.isBlank(value)) {
 382  0
                         throw new IllegalArgumentException(name + " was blank");
 383  
                 }
 384  0
         }
 385  
         
 386  
         private void validateServiceName(QName serviceName) {
 387  0
                 assertNotNull("serviceName", serviceName);
 388  0
         }
 389  
         
 390  
         private void validateEndpointUrl(String endpointUrl) {
 391  0
                 assertNotBlank("endpointUrl", endpointUrl);
 392  0
         }
 393  
         
 394  
         private void validateInstanceId(String instanceId) {
 395  0
                 assertNotBlank("instanceId", instanceId);
 396  0
         }
 397  
         
 398  
         private void validateApplicationId(String applicationId) {
 399  0
                 assertNotBlank("applicationId", applicationId);
 400  0
         }
 401  
         
 402  
         private void validateServerIpAddress(String serverIpAddress) {
 403  0
                 assertNotBlank("serverIpAddress", serverIpAddress);
 404  0
         }
 405  
         
 406  
         private void validateType(String type) {
 407  0
                 assertNotBlank("type", type);
 408  0
         }
 409  
 
 410  
         private void validateServiceVersion(String serviceVersion) {
 411  0
                 assertNotBlank("serviceVersion", serviceVersion);
 412  0
         }
 413  
         
 414  
         private void validateStatus(ServiceEndpointStatus status) {
 415  0
                 assertNotNull("status", status);
 416  0
         }
 417  
         
 418  
         private void validateChecksum(String checksum) {
 419  0
                 assertNotBlank("checksum", checksum);
 420  0
         }
 421  
         
 422  
         private void validateAll() {
 423  0
                 validateServiceName(serviceName);
 424  0
             validateEndpointUrl(endpointUrl);
 425  0
             validateInstanceId(instanceId);
 426  0
             validateApplicationId(applicationId);
 427  0
             validateServerIpAddress(serverIpAddress);
 428  0
             validateType(type);
 429  0
             validateServiceVersion(serviceVersion);
 430  0
             validateStatus(status);
 431  0
             validateChecksum(checksum);
 432  0
         }
 433  
 
 434  
     }
 435  
 
 436  
 
 437  
     /**
 438  
      * Defines some internal constants used on this class.
 439  
      * 
 440  
      */
 441  0
     static class Constants {
 442  
 
 443  
         final static String ROOT_ELEMENT_NAME = "serviceInfo";
 444  
         final static String TYPE_NAME = "ServiceInfoType";
 445  
     }
 446  
 
 447  
 
 448  
     /**
 449  
      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
 450  
      * 
 451  
      */
 452  0
     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