001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.workflow.ejb;
006:
007: import com.opensymphony.module.propertyset.PropertySet;
008:
009: import com.opensymphony.util.EJBUtils;
010:
011: import com.opensymphony.workflow.*;
012: import com.opensymphony.workflow.config.Configuration;
013: import com.opensymphony.workflow.loader.WorkflowDescriptor;
014: import com.opensymphony.workflow.query.WorkflowExpressionQuery;
015: import com.opensymphony.workflow.query.WorkflowQuery;
016: import com.opensymphony.workflow.spi.WorkflowEntry;
017:
018: import org.apache.commons.logging.Log;
019: import org.apache.commons.logging.LogFactory;
020:
021: import java.rmi.RemoteException;
022:
023: import java.util.Collections;
024: import java.util.List;
025: import java.util.Map;
026:
027: import javax.ejb.CreateException;
028:
029: import javax.naming.NamingException;
030:
031: /**
032: * EJB based workflow class.
033: * This class acts as a wrapper around a workflow session bean.
034: *
035: * @author plightbo
036: * @version $Revision: 1.13 $
037: */
038: public class EJBWorkflow implements Workflow {
039: //~ Static fields/initializers /////////////////////////////////////////////
040:
041: private static final Log log = LogFactory.getLog(EJBWorkflow.class);
042:
043: //~ Instance fields ////////////////////////////////////////////////////////
044:
045: private WorkflowRemote wf;
046:
047: //~ Constructors ///////////////////////////////////////////////////////////
048:
049: public EJBWorkflow(String location) throws CreateException,
050: RemoteException, WorkflowException {
051: WorkflowHome home = null;
052:
053: try {
054: home = (WorkflowHome) EJBUtils.lookup(location,
055: WorkflowHome.class);
056: } catch (NamingException e) {
057: try {
058: home = (WorkflowHome) EJBUtils.lookup(
059: WorkflowHomeFactory.COMP_NAME,
060: WorkflowHome.class);
061: } catch (NamingException e1) {
062: try {
063: home = (WorkflowHome) EJBUtils.lookup(
064: WorkflowHomeFactory.JNDI_NAME,
065: WorkflowHome.class);
066: } catch (NamingException e2) {
067: throw new WorkflowException(
068: "Could not get a handle on the workflow Home EJB",
069: e);
070: }
071: }
072: }
073:
074: wf = home.create();
075: }
076:
077: public EJBWorkflow() throws CreateException, RemoteException,
078: WorkflowException {
079: this (WorkflowHomeFactory.JNDI_NAME);
080: }
081:
082: //~ Methods ////////////////////////////////////////////////////////////////
083:
084: public int[] getAvailableActions(long id) {
085: try {
086: return wf.getAvailableActions(id);
087: } catch (RemoteException e) {
088: log.error("Error getting available actions", e);
089:
090: return new int[0];
091: }
092: }
093:
094: public int[] getAvailableActions(long id, Map inputs) {
095: try {
096: return wf.getAvailableActions(id, inputs);
097: } catch (RemoteException e) {
098: log.error("Error getting available actions", e);
099:
100: return new int[0];
101: }
102: }
103:
104: public void setConfiguration(Configuration configuration) {
105: try {
106: wf.setConfiguration(configuration);
107: } catch (RemoteException e) {
108: log.fatal("Error setting configuration", e);
109: }
110: }
111:
112: public List getCurrentSteps(long id) {
113: try {
114: return wf.getCurrentSteps(id);
115: } catch (RemoteException e) {
116: log.error("Error getting current steps", e);
117:
118: return Collections.EMPTY_LIST;
119: }
120: }
121:
122: public int getEntryState(long id) {
123: try {
124: return wf.getEntryState(id);
125: } catch (RemoteException e) {
126: log.error("Error getting entry state", e);
127:
128: return WorkflowEntry.UNKNOWN;
129: }
130: }
131:
132: public List getHistorySteps(long id) {
133: try {
134: return wf.getHistorySteps(id);
135: } catch (RemoteException e) {
136: log.error("Error getting history steps", e);
137:
138: return Collections.EMPTY_LIST;
139: }
140: }
141:
142: public PropertySet getPropertySet(long id) {
143: try {
144: return wf.getPropertySet(id);
145: } catch (RemoteException e) {
146: log.error("Error getting PropertySet", e);
147:
148: return null;
149: }
150: }
151:
152: public List getSecurityPermissions(long id) {
153: try {
154: return wf.getSecurityPermissions(id);
155: } catch (RemoteException e) {
156: log.error("Error getting security permissions", e);
157:
158: return Collections.EMPTY_LIST;
159: }
160: }
161:
162: public List getSecurityPermissions(long id, Map inputs) {
163: try {
164: return wf.getSecurityPermissions(id, inputs);
165: } catch (RemoteException e) {
166: log.error("Error getting security permissions", e);
167:
168: return Collections.EMPTY_LIST;
169: }
170: }
171:
172: public WorkflowDescriptor getWorkflowDescriptor(String workflowName) {
173: try {
174: return wf.getWorkflowDescriptor(workflowName);
175: } catch (RemoteException e) {
176: log.error("Error getting descriptor", e);
177:
178: return null;
179: }
180: }
181:
182: public String getWorkflowName(long id) {
183: try {
184: return wf.getWorkflowName(id);
185: } catch (RemoteException e) {
186: log.error("Error getting workflow name", e);
187:
188: return null;
189: }
190: }
191:
192: public String[] getWorkflowNames() {
193: try {
194: return wf.getWorkflowNames();
195: } catch (RemoteException e) {
196: log.error("Error calling getWorkflowNames", e);
197:
198: return new String[0];
199: }
200: }
201:
202: public boolean canInitialize(String workflowName, int initialState) {
203: try {
204: return wf.canInitialize(workflowName, initialState);
205: } catch (RemoteException e) {
206: log.error("Error checking canInitialize", e);
207:
208: return false;
209: }
210: }
211:
212: public boolean canInitialize(String workflowName,
213: int initialAction, Map inputs) {
214: try {
215: return wf
216: .canInitialize(workflowName, initialAction, inputs);
217: } catch (RemoteException e) {
218: log.error("Error checking canInitialize", e);
219:
220: return false;
221: }
222: }
223:
224: public boolean canModifyEntryState(long id, int newState) {
225: try {
226: return wf.canModifyEntryState(id, newState);
227: } catch (RemoteException e) {
228: log.error("Error checking modifying entry state", e);
229:
230: return false;
231: }
232: }
233:
234: public void changeEntryState(long id, int newState)
235: throws WorkflowException {
236: try {
237: wf.changeEntryState(id, newState);
238: } catch (RemoteException e) {
239: log.error("Error modifying entry state", e);
240: throw new WorkflowException(e);
241: }
242: }
243:
244: public void doAction(long id, int actionId, Map inputs)
245: throws InvalidInputException, WorkflowException {
246: try {
247: wf.doAction(id, actionId, inputs);
248: } catch (RemoteException e) {
249: log.error("Error performing action", e);
250: throw new WorkflowException(e);
251: }
252: }
253:
254: public void executeTriggerFunction(long id, int triggerId)
255: throws WorkflowException {
256: try {
257: wf.executeTriggerFunction(id, triggerId);
258: } catch (RemoteException e) {
259: log.error("Error executing trigger", e);
260: throw new WorkflowException(e);
261: }
262: }
263:
264: public long initialize(String workflowName, int initialState,
265: Map inputs) throws InvalidRoleException,
266: InvalidInputException, WorkflowException {
267: try {
268: return wf.initialize(workflowName, initialState, inputs);
269: } catch (RemoteException e) {
270: log.error("Error initializing", e);
271: throw new WorkflowException(e);
272: }
273: }
274:
275: public List query(WorkflowExpressionQuery query)
276: throws WorkflowException {
277: throw new QueryNotSupportedException(
278: "EJB Store does not support queries");
279: }
280:
281: public List query(WorkflowQuery query) throws WorkflowException {
282: throw new QueryNotSupportedException(
283: "EJB Store does not support queries");
284: }
285:
286: public boolean removeWorkflowDescriptor(String workflowName)
287: throws FactoryException {
288: try {
289: return wf.removeWorkflowDescriptor(workflowName);
290: } catch (RemoteException e) {
291: log.error("Error removing workflow " + workflowName, e);
292:
293: return false;
294: }
295: }
296:
297: public boolean saveWorkflowDescriptor(String workflowName,
298: WorkflowDescriptor descriptor, boolean replace)
299: throws FactoryException {
300: try {
301: return wf.saveWorkflowDescriptor(workflowName, descriptor,
302: replace);
303: } catch (RemoteException e) {
304: log.error("Error saving workflow", e);
305: throw new FactoryException(e);
306: }
307: }
308: }
|