001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.workflow.spi.ejb;
006:
007: import com.opensymphony.module.propertyset.PropertySet;
008: import com.opensymphony.module.propertyset.PropertySetManager;
009:
010: import com.opensymphony.workflow.StoreException;
011: import com.opensymphony.workflow.query.WorkflowExpressionQuery;
012: import com.opensymphony.workflow.query.WorkflowQuery;
013: import com.opensymphony.workflow.spi.*;
014:
015: import org.apache.commons.logging.Log;
016: import org.apache.commons.logging.LogFactory;
017:
018: import java.rmi.RemoteException;
019:
020: import java.util.*;
021:
022: import javax.naming.InitialContext;
023:
024: import javax.rmi.PortableRemoteObject;
025:
026: /**
027: * EJB entity bean workflow store implementation.
028: * <p>
029: *
030: * The following property is optional:
031: * <ul>
032: * <li><b>property.store</b> - JNDI location for the OSCore EJBPropertySet PropertyStore (defaults to "ejb/propertyStore")</li>
033: * <li><b>workflow.store</b> - JNDI location for the ejb workflow store session bean (defaults to @link{#WorkflowStoreHome.JNDI_NAME)</li>
034: * </ul>
035: *
036: * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
037: */
038: public class EJBWorkflowStore implements WorkflowStore {
039: //~ Static fields/initializers /////////////////////////////////////////////
040:
041: private static final Log log = LogFactory
042: .getLog(EJBWorkflowStore.class);
043:
044: //~ Instance fields ////////////////////////////////////////////////////////
045:
046: private WorkflowStoreRemote session;
047:
048: //~ Methods ////////////////////////////////////////////////////////////////
049:
050: public void setEntryState(long entryId, int state)
051: throws StoreException {
052: try {
053: session.setEntryState(entryId, state);
054: } catch (RemoteException ex) {
055: log.error("Error changing state of workflow instance #"
056: + entryId + " to " + state, ex);
057: }
058: }
059:
060: public PropertySet getPropertySet(long entryId)
061: throws StoreException {
062: try {
063: HashMap args = new HashMap(2);
064: args.put("entityId", new Long(entryId));
065: args.put("entityName", "WorkflowEntry");
066:
067: return PropertySetManager.getInstance("ejb", args);
068: } catch (Exception e) {
069: throw new StoreException(
070: "Could not retrieve PropertySet for workflow instance #"
071: + entryId, e);
072: }
073: }
074:
075: public Step createCurrentStep(long entryId, int stepId,
076: String owner, Date startDate, Date dueDate, String status,
077: long[] previousIds) throws StoreException {
078: try {
079: return session.createCurrentStep(entryId, stepId, owner,
080: startDate, dueDate, status, previousIds);
081: } catch (RemoteException ex) {
082: log.fatal("System error", ex);
083:
084: return null;
085: }
086: }
087:
088: public WorkflowEntry createEntry(String workflowName)
089: throws StoreException {
090: try {
091: return session.createEntry(workflowName);
092: } catch (RemoteException ex) {
093: log.fatal("System error", ex);
094:
095: return null;
096: }
097: }
098:
099: public List findCurrentSteps(long entryId) throws StoreException {
100: try {
101: return session.findCurrentSteps(entryId);
102: } catch (RemoteException ex) {
103: log.fatal("System error", ex);
104:
105: return null;
106: }
107: }
108:
109: public WorkflowEntry findEntry(long entryId) throws StoreException {
110: try {
111: return session.findEntry(entryId);
112: } catch (RemoteException ex) {
113: log.fatal("System error", ex);
114:
115: return null;
116: }
117: }
118:
119: public List findHistorySteps(long entryId) throws StoreException {
120: try {
121: return session.findHistorySteps(entryId);
122: } catch (RemoteException ex) {
123: log.fatal("System error", ex);
124:
125: return null;
126: }
127: }
128:
129: public void init(Map props) {
130: String workflowSessionLocation = (String) props
131: .get("workflow.store");
132:
133: if (workflowSessionLocation == null) {
134: workflowSessionLocation = WorkflowStoreHomeFactory.JNDI_NAME;
135: }
136:
137: try {
138: InitialContext context = new InitialContext();
139: session = ((WorkflowStoreHome) PortableRemoteObject.narrow(
140: context.lookup(workflowSessionLocation),
141: WorkflowStoreHome.class)).create();
142: } catch (Exception ex) {
143: log.error("Error looking up homes", ex);
144: throw new IllegalArgumentException(ex.toString());
145: }
146: }
147:
148: public Step markFinished(Step step, int actionId, Date finishDate,
149: String status, String caller) throws StoreException {
150: try {
151: return session.markFinished(step, actionId, finishDate,
152: status, caller);
153: } catch (RemoteException ex) {
154: log.fatal("System error", ex);
155:
156: return null;
157: }
158: }
159:
160: public void moveToHistory(Step step) throws StoreException {
161: try {
162: session.moveToHistory(step);
163: } catch (RemoteException ex) {
164: log.fatal("System error", ex);
165: }
166: }
167:
168: public List query(WorkflowQuery query) {
169: // not implemented
170: throw new UnsupportedOperationException(
171: "EJB store does not support queries");
172: }
173:
174: public List query(WorkflowExpressionQuery query)
175: throws StoreException {
176: throw new UnsupportedOperationException(
177: "EJB store does not support queries");
178: }
179: }
|