01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.messaging.serviceconnectors;
18:
19: import org.kuali.rice.config.Config;
20: import org.kuali.rice.core.Core;
21: import org.kuali.rice.exceptions.RiceRuntimeException;
22: import org.kuali.rice.security.credentials.CredentialsSource;
23: import org.kuali.rice.security.credentials.CredentialsSourceFactory;
24:
25: import edu.iu.uis.eden.messaging.JavaServiceDefinition;
26: import edu.iu.uis.eden.messaging.JmsServiceDefinition;
27: import edu.iu.uis.eden.messaging.SOAPServiceDefinition;
28: import edu.iu.uis.eden.messaging.ServiceDefinition;
29: import edu.iu.uis.eden.messaging.ServiceInfo;
30:
31: /**
32: * Constructs a ServiceConnector based on the provided ServiceInfo/ServiceDefinition.
33: * Connects that ServiceConnector to the appropriate CredentialsSource.
34: * <p>
35: * ServiceConnector will fail if a CredentialsSource for the Service Definition cannot
36: * be located.
37: *
38: * @author Kuali Rice Team (kuali-rice@googlegroups.com)
39: * @version $Revision: 1.2.24.1 $ $Date: 2007/10/17 20:32:04 $
40: * @since 0.9
41: *
42: * @see ServiceConnector
43: * @see ServiceInfo
44: * @see ServiceDefinition
45: * @see CredentialsSource
46: */
47: public class ServiceConnectorFactory {
48:
49: public static ServiceConnector getServiceConnector(
50: final ServiceInfo serviceInfo) {
51: final ServiceDefinition serviceDefinition = serviceInfo
52: .getServiceDefinition();
53: final CredentialsSourceFactory credentialsSourceFactory = (CredentialsSourceFactory) Core
54: .getCurrentContextConfig().getObjects().get(
55: Config.CREDENTIALS_SOURCE_FACTORY);
56: final CredentialsSource credentialsSource = credentialsSourceFactory != null ? credentialsSourceFactory
57: .getCredentialsForType(serviceDefinition
58: .getCredentialsType())
59: : null;
60: ServiceConnector serviceConnector = null;
61:
62: if (serviceDefinition.getCredentialsType() != null
63: && credentialsSource == null) {
64: throw new RiceRuntimeException(
65: "Service requires credentials but no factory or CredentialsSource could be located.");
66: }
67:
68: // if set in local mode then preempt any protocol connectors
69: if (Core.getCurrentContextConfig().getDevMode()) {
70: serviceConnector = new BusLocalConnector(serviceInfo);
71: } else if (serviceDefinition instanceof JavaServiceDefinition) {
72: serviceConnector = new HttpInvokerConnector(serviceInfo);
73: } else if (serviceDefinition instanceof SOAPServiceDefinition) {
74: serviceConnector = new SOAPConnector(serviceInfo);
75: } else if (serviceDefinition instanceof JmsServiceDefinition) {
76: serviceConnector = new JmsConnector(serviceInfo);
77: }
78:
79: if (serviceConnector == null) {
80: throw new RiceRuntimeException(
81: "Don't support service type of "
82: + serviceInfo.getServiceDefinition());
83: }
84:
85: serviceConnector.setCredentialsSource(credentialsSource);
86:
87: return serviceConnector;
88: }
89: }
|