KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > spi > ejb > EJBWorkflowStore


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.workflow.spi.ejb;
6
7 import com.opensymphony.module.propertyset.PropertySet;
8 import com.opensymphony.module.propertyset.PropertySetManager;
9
10 import com.opensymphony.workflow.StoreException;
11 import com.opensymphony.workflow.query.WorkflowExpressionQuery;
12 import com.opensymphony.workflow.query.WorkflowQuery;
13 import com.opensymphony.workflow.spi.*;
14
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17
18 import java.rmi.RemoteException JavaDoc;
19
20 import java.util.*;
21
22 import javax.naming.InitialContext JavaDoc;
23
24 import javax.rmi.PortableRemoteObject JavaDoc;
25
26
27 /**
28  * EJB entity bean workflow store implementation.
29  * <p>
30  *
31  * The following property is optional:
32  * <ul>
33  * <li><b>property.store</b> - JNDI location for the OSCore EJBPropertySet PropertyStore (defaults to "ejb/propertyStore")</li>
34  * <li><b>workflow.store</b> - JNDI location for the ejb workflow store session bean (defaults to @link{#WorkflowStoreHome.JNDI_NAME)</li>
35  * </ul>
36  *
37  * @author <a HREF="mailto:plightbo@hotmail.com">Pat Lightbody</a>
38  */

39 public class EJBWorkflowStore implements WorkflowStore {
40     //~ Static fields/initializers /////////////////////////////////////////////
41

42     private static final Log log = LogFactory.getLog(EJBWorkflowStore.class);
43
44     //~ Instance fields ////////////////////////////////////////////////////////
45

46     private WorkflowStoreRemote session;
47
48     //~ Methods ////////////////////////////////////////////////////////////////
49

50     public void setEntryState(long entryId, int state) throws StoreException {
51         try {
52             session.setEntryState(entryId, state);
53         } catch (RemoteException JavaDoc ex) {
54             log.error("Error changing state of workflow instance #" + entryId + " to " + state, ex);
55         }
56     }
57
58     public PropertySet getPropertySet(long entryId) throws StoreException {
59         try {
60             HashMap args = new HashMap(2);
61             args.put("entityId", new Long JavaDoc(entryId));
62             args.put("entityName", "WorkflowEntry");
63
64             return PropertySetManager.getInstance("ejb", args);
65         } catch (Exception JavaDoc e) {
66             throw new StoreException("Could not retrieve PropertySet for workflow instance #" + entryId, e);
67         }
68     }
69
70     public Step createCurrentStep(long entryId, int stepId, String JavaDoc owner, Date startDate, Date dueDate, String JavaDoc status, long[] previousIds) throws StoreException {
71         try {
72             return session.createCurrentStep(entryId, stepId, owner, startDate, dueDate, status, previousIds);
73         } catch (RemoteException JavaDoc ex) {
74             log.fatal("System error", ex);
75
76             return null;
77         }
78     }
79
80     public WorkflowEntry createEntry(String JavaDoc workflowName) throws StoreException {
81         try {
82             return session.createEntry(workflowName);
83         } catch (RemoteException JavaDoc ex) {
84             log.fatal("System error", ex);
85
86             return null;
87         }
88     }
89
90     public List findCurrentSteps(long entryId) throws StoreException {
91         try {
92             return session.findCurrentSteps(entryId);
93         } catch (RemoteException JavaDoc ex) {
94             log.fatal("System error", ex);
95
96             return null;
97         }
98     }
99
100     public WorkflowEntry findEntry(long entryId) throws StoreException {
101         try {
102             return session.findEntry(entryId);
103         } catch (RemoteException JavaDoc ex) {
104             log.fatal("System error", ex);
105
106             return null;
107         }
108     }
109
110     public List findHistorySteps(long entryId) throws StoreException {
111         try {
112             return session.findHistorySteps(entryId);
113         } catch (RemoteException JavaDoc ex) {
114             log.fatal("System error", ex);
115
116             return null;
117         }
118     }
119
120     public void init(Map props) {
121         String JavaDoc workflowSessionLocation = (String JavaDoc) props.get("workflow.store");
122
123         if (workflowSessionLocation == null) {
124             workflowSessionLocation = WorkflowStoreHomeFactory.JNDI_NAME;
125         }
126
127         try {
128             InitialContext JavaDoc context = new InitialContext JavaDoc();
129             session = ((WorkflowStoreHome) PortableRemoteObject.narrow(context.lookup(workflowSessionLocation), WorkflowStoreHome.class)).create();
130         } catch (Exception JavaDoc ex) {
131             log.error("Error looking up homes", ex);
132             throw new IllegalArgumentException JavaDoc(ex.toString());
133         }
134     }
135
136     public Step markFinished(Step step, int actionId, Date finishDate, String JavaDoc status, String JavaDoc caller) throws StoreException {
137         try {
138             return session.markFinished(step, actionId, finishDate, status, caller);
139         } catch (RemoteException JavaDoc ex) {
140             log.fatal("System error", ex);
141
142             return null;
143         }
144     }
145
146     public void moveToHistory(Step step) throws StoreException {
147         try {
148             session.moveToHistory(step);
149         } catch (RemoteException JavaDoc ex) {
150             log.fatal("System error", ex);
151         }
152     }
153
154     public List query(WorkflowQuery query) {
155         // not implemented
156
throw new UnsupportedOperationException JavaDoc("EJB store does not support queries");
157     }
158
159     public List query(WorkflowExpressionQuery query) throws StoreException {
160         throw new UnsupportedOperationException JavaDoc("EJB store does not support queries");
161     }
162 }
163
Popular Tags