Coverage Report - org.kuali.rice.ksb.messaging.serviceconnectors.ServiceConnectorFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceConnectorFactory
0%
0/19
0%
0/16
11
 
 1  
 /*
 2  
  * Copyright 2005-2007 The Kuali Foundation
 3  
  * 
 4  
  * 
 5  
  * Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in
 6  
  * compliance with the License. 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 distributed under the License is distributed on an "AS
 11  
  * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
 12  
  * language governing permissions and limitations under the License.
 13  
  */
 14  
 package org.kuali.rice.ksb.messaging.serviceconnectors;
 15  
 
 16  
 import org.kuali.rice.core.config.Config;
 17  
 import org.kuali.rice.core.config.ConfigContext;
 18  
 import org.kuali.rice.core.exception.RiceRuntimeException;
 19  
 import org.kuali.rice.core.security.credentials.CredentialsSource;
 20  
 import org.kuali.rice.core.security.credentials.CredentialsSourceFactory;
 21  
 import org.kuali.rice.ksb.messaging.JavaServiceDefinition;
 22  
 import org.kuali.rice.ksb.messaging.RESTServiceDefinition;
 23  
 import org.kuali.rice.ksb.messaging.SOAPServiceDefinition;
 24  
 import org.kuali.rice.ksb.messaging.ServiceDefinition;
 25  
 import org.kuali.rice.ksb.messaging.ServiceInfo;
 26  
 
 27  
 
 28  
 /**
 29  
  * Constructs a ServiceConnector based on the provided ServiceInfo/ServiceDefinition. Connects that ServiceConnector to the
 30  
  * appropriate CredentialsSource.
 31  
  * <p>
 32  
  * ServiceConnector will fail if a CredentialsSource for the Service Definition cannot be located.
 33  
  * 
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  *
 36  
  * @since 0.9
 37  
  * @see ServiceConnector
 38  
  * @see ServiceInfo
 39  
  * @see ServiceDefinition
 40  
  * @see CredentialsSource
 41  
  */
 42  0
 public class ServiceConnectorFactory {
 43  
 
 44  
     public static ServiceConnector getServiceConnector(final ServiceInfo serviceInfo) {
 45  0
         final ServiceDefinition serviceDefinition = serviceInfo.getServiceDefinition();
 46  0
         final CredentialsSourceFactory credentialsSourceFactory = (CredentialsSourceFactory) ConfigContext.getCurrentContextConfig()
 47  
                 .getObjects().get(Config.CREDENTIALS_SOURCE_FACTORY);
 48  0
         final CredentialsSource credentialsSource = credentialsSourceFactory != null ? credentialsSourceFactory
 49  
                 .getCredentialsForType(serviceDefinition.getCredentialsType()) : null;
 50  0
         ServiceConnector serviceConnector = null;
 51  
 
 52  0
         if (serviceDefinition.getCredentialsType() != null && credentialsSource == null) {
 53  0
             throw new RiceRuntimeException(
 54  
                     "Service requires credentials but no factory or CredentialsSource could be located.");
 55  
         }
 56  
 
 57  
         // if set in local mode then preempt any protocol connectors
 58  0
         if (ConfigContext.getCurrentContextConfig().getDevMode()) {
 59  0
             serviceConnector = new BusLocalConnector(serviceInfo);
 60  0
         } else if (serviceDefinition instanceof JavaServiceDefinition) {
 61  0
             serviceConnector = new HttpInvokerConnector(serviceInfo);
 62  0
         } else if (serviceDefinition instanceof SOAPServiceDefinition) {
 63  0
             serviceConnector = new SOAPConnector(serviceInfo);
 64  0
     } else if (serviceDefinition instanceof RESTServiceDefinition) {
 65  0
         serviceConnector = new RESTConnector(serviceInfo);
 66  
     }
 67  
 
 68  0
         if (serviceConnector == null) {
 69  0
             throw new RiceRuntimeException("Don't support service type of " + serviceInfo.getServiceDefinition());
 70  
         }
 71  
 
 72  0
         serviceConnector.setCredentialsSource(credentialsSource);
 73  
 
 74  0
         return serviceConnector;
 75  
     }
 76  
 
 77  
     
 78  
 }