001: /*--
002:
003: Copyright (C) 2002-2005 Adrian Price.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: adrianprice@sourceforge.net.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Adrian Price (adrianprice@users.sourceforge.net).
027:
028: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
029: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
030: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
031: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
032: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
033: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
034: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
035: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
036: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
037: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
038: POSSIBILITY OF SUCH DAMAGE.
039:
040: For more information on OBE, please see
041: <http://obe.sourceforge.net/>.
042:
043: */
044:
045: package org.obe.client.api.local;
046:
047: import org.apache.commons.logging.Log;
048: import org.apache.commons.logging.LogFactory;
049: import org.obe.client.api.WMClientFactory;
050: import org.obe.client.api.base.AbstractJAASClient;
051: import org.obe.engine.WorkflowEngine;
052: import org.obe.spi.WMLocalClient;
053: import org.obe.spi.WorkflowService;
054: import org.obe.spi.event.ApplicationEvent;
055: import org.obe.spi.service.ServiceManager;
056: import org.wfmc.wapi.WMConnectException;
057: import org.wfmc.wapi.WMConnectInfo;
058: import org.wfmc.wapi.WMWorkflowException;
059:
060: import java.security.PrivilegedExceptionAction;
061:
062: /**
063: * Class used to connect to and communicate with a workflow engine via a local
064: * interface.
065: * <p/>
066: * This interface is based on the WfMC's Interface 2 Client API
067: * specification. Some of the methods have been modified from the original
068: * specification to fit within the normal design of Java applications. For
069: * instance, the WfMC specification functions always return an error object
070: * (even for success) and uses out parameters to return values. This interface
071: * returns the value and throws an exception when an error occurs. If no error
072: * occurs then an exception is not thrown.
073: *
074: * @author Adrian Price
075: */
076: public final class LocalClient extends AbstractJAASClient implements
077: WMLocalClient {
078:
079: private static final Log _logger = LogFactory
080: .getLog(LocalClient.class);
081:
082: public LocalClient() {
083: }
084:
085: protected Log getLogger() {
086: return _logger;
087: }
088:
089: public String getProtocol() {
090: return WMClientFactory.LOCAL;
091: }
092:
093: public synchronized void connect(WMConnectInfo connectInfo)
094: throws WMConnectException {
095:
096: super .connect(connectInfo);
097: _engine = WorkflowEngine.getEngine();
098: }
099:
100: public synchronized void disconnect() throws WMConnectException {
101: try {
102: super .disconnect();
103: } finally {
104: _engine = null;
105: }
106: }
107:
108: public void raiseEvent(final ApplicationEvent event,
109: final String[] correlationKeys) throws WMWorkflowException {
110:
111: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
112: public Object run() throws Exception {
113: ((WorkflowEngine) _engine).raiseEvent(event,
114: correlationKeys);
115: return null;
116: }
117: };
118: doAsSubject(action);
119: }
120:
121: public void refreshWorkItems(final String processInstanceId)
122: throws WMWorkflowException {
123:
124: PrivilegedExceptionAction action = new PrivilegedExceptionAction() {
125: public Object run() throws Exception {
126: ((WorkflowEngine) _engine)
127: .refreshWorkItems(processInstanceId);
128: return null;
129: }
130: };
131: doAsSubject(action);
132: }
133:
134: public ServiceManager getServiceManager() {
135: return ((WorkflowService) _engine).getServiceManager();
136: }
137: }
|