001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.clientapp;
018:
019: import java.io.IOException;
020:
021: import org.apache.log4j.Logger;
022: import org.kuali.rice.config.Config;
023: import org.kuali.rice.core.Core;
024:
025: import edu.iu.uis.eden.EdenConstants;
026: import edu.iu.uis.eden.KEWServiceLocator;
027: import edu.iu.uis.eden.exception.WorkflowException;
028: import edu.iu.uis.eden.server.WorkflowDocumentActions;
029: import edu.iu.uis.eden.server.WorkflowUtility;
030: import edu.iu.uis.eden.util.Utilities;
031:
032: /**
033: * Assists in locating the WorkflowUtility and WorkflowDocumentActions services from a Workflow client.
034: * It's behavior is to check the workflow client configuration (workfow-config.properties) and if it
035: * finds a webservice url configured it connects to the services via web services. Otherwise it will
036: * attempt to use locally running services. In order for local running services to be functional,
037: * this kind of configuration must be used only in an application running inside of the same JVM as
038: * workflow, such as the workflow core or a workflow client plugin.
039: *
040: * This class stores configured services keyed off of the current Thread's context classloader (provided
041: * it has one). Therefore, multiple Workflow plugins can configure their workflow client access differently.
042: *
043: * @author ewestfal
044: */
045: public class ClientServiceLocator {
046:
047: private static final Logger LOG = Logger
048: .getLogger(ClientServiceLocator.class);
049:
050: public static WorkflowUtility getWorkflowUtility()
051: throws WorkflowException {
052: WorkflowUtility workflowUtility = null;
053: String clientProtocol = getClientProtocol();
054: if (EdenConstants.LOCAL_CLIENT_PROTOCOL.equals(clientProtocol)) {
055: LOG
056: .debug("Connecting to locally running instance of WorkflowUtility");
057: workflowUtility = KEWServiceLocator
058: .getWorkflowUtilityService();
059: } else if (EdenConstants.WEBSERVICE_CLIENT_PROTOCOL
060: .equals(clientProtocol)) {
061: LOG
062: .debug("Connecting to WorkflowUtility web service at url "
063: + getClientConfig().getBaseWebServiceURL());
064: // workflowUtility = WebServiceLocator.getWorkflowUtilityProxy();
065: throw new UnsupportedOperationException(
066: "This object does not currently support Web services");
067: } else {
068: throw new WorkflowException(
069: "Did not recognize the configured client.protocol: '"
070: + clientProtocol + "'");
071: }
072: return workflowUtility;
073: }
074:
075: public static WorkflowDocumentActions getWorkflowDocumentActions()
076: throws WorkflowException {
077: WorkflowDocumentActions workflowDocumentActions = null;
078: String clientProtocol = getClientProtocol();
079: if (EdenConstants.LOCAL_CLIENT_PROTOCOL.equals(clientProtocol)) {
080: LOG
081: .debug("Connecting to locally running instance of WorkflowDocumentActions");
082: workflowDocumentActions = KEWServiceLocator
083: .getWorkflowDocumentActionsService();
084: } else if (EdenConstants.WEBSERVICE_CLIENT_PROTOCOL
085: .equals(clientProtocol)) {
086: LOG
087: .debug("Connecting to WorkflowDocumentActions web service at url "
088: + getClientConfig().getBaseWebServiceURL());
089: // workflowDocumentActions = WebServiceLocator.getWorkflowDocumentActionsProxy();
090: throw new UnsupportedOperationException(
091: "This object does not currently support web services");
092: } else {
093: throw new WorkflowException(
094: "Did not recognize the configured client.protocol: '"
095: + clientProtocol + "'");
096: }
097: return workflowDocumentActions;
098: }
099:
100: public static synchronized Config getClientConfig()
101: throws WorkflowException {
102: Config config = Core.getCurrentContextConfig();
103: if (config == null) {
104: config = new ClientConfig();
105: try {
106: config.parseConfig();
107: } catch (IOException e) {
108: throw new WorkflowException(e);
109: }
110: }
111: return config;
112: }
113:
114: /**
115: * Returns the configured client protocol. If there is no configured client protocol
116: * then the default is webservices.
117: */
118: private static String getClientProtocol() throws WorkflowException {
119: String clientProtocol = getClientConfig().getClientProtocol();
120: if (Utilities.isEmpty(clientProtocol)) {
121: clientProtocol = EdenConstants.WEBSERVICE_CLIENT_PROTOCOL;
122: }
123: return clientProtocol;
124: }
125:
126: }
|