001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
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 org.bpmscript.remote;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import javax.jbi.component.Component;
023: import javax.xml.namespace.QName;
024:
025: import org.apache.servicemix.common.BaseComponent;
026: import org.bpmscript.BpmScriptException;
027: import org.bpmscript.IPagedResult;
028: import org.bpmscript.IProcess;
029: import org.bpmscript.IProcessInstance;
030: import org.bpmscript.IProcessInstanceManager;
031: import org.bpmscript.IProcessManager;
032: import org.bpmscript.IProcessSource;
033: import org.bpmscript.IProcessSourceName;
034: import org.bpmscript.IQuery;
035: import org.bpmscript.ProcessSourceName;
036: import org.bpmscript.jbi.IComponentAware;
037: import org.bpmscript.jbi.component.BpmScriptLifeCycle;
038: import org.bpmscript.jbi.component.ProcessEndpoint;
039:
040: public class RemoteProcessManager implements IRemoteProcessManager,
041: IComponentAware {
042:
043: private final transient org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
044: .getLog(getClass());
045:
046: private IProcessManager processManager = null;
047: private IProcessInstanceManager processInstanceManager = null;
048: private Component component;
049:
050: /* (non-Javadoc)
051: * @see org.bpmscript.remote.IRemoteProcessManager#addSourceToProcess(java.lang.String, java.lang.String, java.lang.String, boolean)
052: */
053: public void addSourceToProcess(String processId, String name,
054: String source, boolean main) throws BpmScriptException {
055: processManager
056: .addSourceToProcess(processId, name, source, main);
057: }
058:
059: /* (non-Javadoc)
060: * @see org.bpmscript.remote.IRemoteProcessManager#createProcess(java.lang.String)
061: */
062: public String createProcess(String source, String name)
063: throws BpmScriptException {
064: IProcess primaryProcess = processManager
065: .getPrimaryProcess(name);
066: if (primaryProcess == null) {
067: log.info("new process " + name + " registering endpoint");
068: String processId = processManager.createProcess(source,
069: name, false);
070: BpmScriptLifeCycle lifeCycle = (BpmScriptLifeCycle) component
071: .getLifeCycle();
072: ProcessEndpoint processEndpoint = new ProcessEndpoint();
073: processEndpoint.setProcessId(processId);
074: processEndpoint
075: .setProcessInstanceManager(processInstanceManager);
076: processEndpoint.setProcessExecutor(lifeCycle
077: .getProcessExecutor());
078: processEndpoint.setServiceUnit(lifeCycle
079: .getProcessServiceUnit());
080: QName service = new QName(lifeCycle.getDefaultNamespace(),
081: name);
082: processEndpoint.setService(service);
083: processEndpoint.setEndpoint(name);
084: lifeCycle.getProcessServiceUnit().addEndpoint(
085: processEndpoint);
086: BaseComponent baseComponent = (BaseComponent) component;
087: baseComponent.getRegistry().registerEndpoint(
088: processEndpoint);
089: log.info("endpoint " + service + " registered");
090: try {
091: processEndpoint.activate();
092: processEndpoint.start();
093: log.info("endpoint " + service + " started");
094: } catch (Exception e) {
095: throw new BpmScriptException(e);
096: }
097: return processId;
098: } else {
099: String processId = processManager.createProcess(source,
100: name, primaryProcess.isPinned());
101: return processId;
102: }
103: }
104:
105: /* (non-Javadoc)
106: * @see org.bpmscript.remote.IRemoteProcessManager#getMainSource(java.lang.String)
107: */
108: public IProcessSource getMainSource(String processId)
109: throws BpmScriptException {
110: return processManager.getMainSource(processId);
111: }
112:
113: /* (non-Javadoc)
114: * @see org.bpmscript.remote.IRemoteProcessManager#getProcess(java.lang.String)
115: */
116: public IProcess getProcess(String processId)
117: throws BpmScriptException {
118: return processManager.getProcess(processId);
119: }
120:
121: /* (non-Javadoc)
122: * @see org.bpmscript.remote.IRemoteProcessManager#getProcesses()
123: */
124: public List<IProcess> getPrimaryProcesses()
125: throws BpmScriptException {
126: return processManager.getPrimaryProcesses();
127: }
128:
129: /* (non-Javadoc)
130: * @see org.bpmscript.remote.IRemoteProcessManager#getProcessSources(java.lang.String)
131: */
132: public List<IProcessSource> getProcessSources(String processId)
133: throws BpmScriptException {
134: return processManager.getProcessSources(processId);
135: }
136:
137: /* (non-Javadoc)
138: * @see org.bpmscript.remote.IRemoteProcessManager#setProcessAsPrimary(java.lang.String)
139: */
140: public void setProcessAsPrimary(String processId)
141: throws BpmScriptException {
142: processManager.setProcessAsPrimary(processId);
143: }
144:
145: public void setProcessManager(IProcessManager processManager) {
146: this .processManager = processManager;
147: }
148:
149: public IProcessInstance getProcessInstance(String processInstanceId)
150: throws BpmScriptException {
151: return this .processInstanceManager
152: .getProcessInstance(processInstanceId);
153: }
154:
155: public IProcessSource getProcessSource(String processSourceId)
156: throws BpmScriptException {
157: return this .processManager.getProcessSource(processSourceId);
158: }
159:
160: public List<IProcessSourceName> getProcessSourceNames(
161: String processId) throws BpmScriptException {
162: List<IProcessSource> processSources = processManager
163: .getProcessSources(processId);
164: List<IProcessSourceName> result = new ArrayList<IProcessSourceName>();
165: for (IProcessSource source : processSources) {
166: result.add(new ProcessSourceName(source.getId(), source
167: .getName(), source.isMain()));
168: }
169: return result;
170: }
171:
172: public List<IProcessInstance> getChildProcessInstances(
173: String processInstanceId) throws BpmScriptException {
174: return processInstanceManager
175: .getChildProcessInstances(processInstanceId);
176: }
177:
178: public IPagedResult<IProcessInstance> getProcessInstances(
179: IQuery query) throws BpmScriptException {
180: return processInstanceManager.getProcessInstances(query);
181: }
182:
183: public IProcess getPrimaryProcess(String name)
184: throws BpmScriptException {
185: return processManager.getPrimaryProcess(name);
186: }
187:
188: public void setComponent(Component component) {
189: this .component = component;
190: }
191:
192: public IProcessInstanceManager getProcessInstanceManager() {
193: return processInstanceManager;
194: }
195:
196: public void setProcessInstanceManager(
197: IProcessInstanceManager processInstanceManager) {
198: this .processInstanceManager = processInstanceManager;
199: }
200:
201: public List<IProcess> getProcessVersions(String name)
202: throws BpmScriptException {
203: return this.processManager.getProcessVersions(name);
204: }
205:
206: }
|