Coverage Report - org.kuali.rice.ksb.impl.bus.RemoteService
 
Classes in this File Line Coverage Branch Coverage Complexity
RemoteService
0%
0/33
0%
0/16
2.75
 
 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.impl.bus;
 17  
 
 18  
 import javax.xml.namespace.QName;
 19  
 
 20  
 import org.apache.commons.lang.StringUtils;
 21  
 import org.kuali.rice.ksb.api.bus.Endpoint;
 22  
 import org.kuali.rice.ksb.api.bus.ServiceConfiguration;
 23  
 import org.kuali.rice.ksb.api.registry.ServiceDescriptor;
 24  
 import org.kuali.rice.ksb.api.registry.ServiceInfo;
 25  
 import org.kuali.rice.ksb.api.registry.ServiceRegistry;
 26  
 
 27  
 public final class RemoteService {
 28  
         
 29  
         private final ServiceInfo serviceInfo;
 30  
         private final ServiceRegistry serviceRegistry;
 31  
         
 32  0
         private final Object endpointAcquisitionLock = new Object();
 33  
         private volatile Endpoint endpoint;
 34  
         
 35  0
         public RemoteService(ServiceInfo serviceInfo, ServiceRegistry serviceRegistry) {
 36  0
                 validateServiceInfo(serviceInfo);
 37  0
                 if (serviceRegistry == null) {
 38  0
                         throw new IllegalArgumentException("serviceRegistry cannot be null");
 39  
                 }
 40  0
                 this.serviceInfo = serviceInfo;
 41  0
                 this.serviceRegistry = serviceRegistry;
 42  0
         }
 43  
         
 44  
         private static void validateServiceInfo(ServiceInfo serviceInfo) {
 45  0
                 if (serviceInfo == null) {
 46  0
                         throw new IllegalArgumentException("serviceInfo cannot be null");
 47  
                 }
 48  0
                 if (serviceInfo.getServiceId() == null) {
 49  0
                         throw new IllegalArgumentException("serviceInfo must have a serviceId but was null");
 50  
                 }
 51  0
         }
 52  
         
 53  
         public QName getServiceName() {
 54  0
                 return serviceInfo.getServiceName();
 55  
         }
 56  
                 
 57  
         public ServiceInfo getServiceInfo() {
 58  0
                 return serviceInfo;
 59  
         }
 60  
         
 61  
         public Endpoint getEndpoint() {
 62  
                 // double-checked locking idiom - see Effective Java, Item 71
 63  0
                 Endpoint internalEndpoint = this.endpoint;
 64  0
                 if (internalEndpoint == null) {
 65  0
                         synchronized (endpointAcquisitionLock) {
 66  0
                                 internalEndpoint = this.endpoint;
 67  0
                                 if (internalEndpoint == null) {
 68  0
                                         this.endpoint = internalEndpoint = new LazyEndpoint(constructServiceConfiguration()); 
 69  
                                 }
 70  0
                         }
 71  
                 }
 72  0
                 return internalEndpoint;
 73  
         }
 74  
         
 75  
         protected ServiceConfiguration constructServiceConfiguration() {
 76  0
                 ServiceDescriptor serviceDescriptor = serviceRegistry.getServiceDescriptor(serviceInfo.getServiceDescriptorId());
 77  0
                 if (serviceDescriptor == null) {
 78  0
                         throw new IllegalStateException("Failed to locate ServiceDescriptor for ServiceInfo with serviceDescriptorId=" + serviceInfo.getServiceDescriptorId());
 79  0
                 } else if (StringUtils.isBlank(serviceDescriptor.getDescriptor())) {
 80  0
                         throw new IllegalStateException("ServiceDescriptor descriptor value is blank or null for descriptor with serviceEndpointId=" + serviceInfo.getServiceId());
 81  
                 }
 82  0
                 return ServiceConfigurationSerializationHandler.unmarshallFromXml(serviceDescriptor.getDescriptor());
 83  
         }
 84  
         
 85  
         @Override
 86  
     public boolean equals(Object obj) {
 87  0
                 if (!(obj instanceof RemoteService)) {
 88  0
                         return false;
 89  
                 }
 90  0
                 return serviceInfo.equals(((RemoteService)obj).getServiceInfo());
 91  
     }
 92  
 
 93  
         @Override
 94  
     public int hashCode() {
 95  0
         return serviceInfo.hashCode();
 96  
     }
 97  
         
 98  
 }