1 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 ; 19 20 import java.util.*; 21 22 import javax.naming.InitialContext ; 23 24 import javax.rmi.PortableRemoteObject ; 25 26 27 39 public class EJBWorkflowStore implements WorkflowStore { 40 42 private static final Log log = LogFactory.getLog(EJBWorkflowStore.class); 43 44 46 private WorkflowStoreRemote session; 47 48 50 public void setEntryState(long entryId, int state) throws StoreException { 51 try { 52 session.setEntryState(entryId, state); 53 } catch (RemoteException 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 (entryId)); 62 args.put("entityName", "WorkflowEntry"); 63 64 return PropertySetManager.getInstance("ejb", args); 65 } catch (Exception 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 owner, Date startDate, Date dueDate, String status, long[] previousIds) throws StoreException { 71 try { 72 return session.createCurrentStep(entryId, stepId, owner, startDate, dueDate, status, previousIds); 73 } catch (RemoteException ex) { 74 log.fatal("System error", ex); 75 76 return null; 77 } 78 } 79 80 public WorkflowEntry createEntry(String workflowName) throws StoreException { 81 try { 82 return session.createEntry(workflowName); 83 } catch (RemoteException 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 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 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 ex) { 114 log.fatal("System error", ex); 115 116 return null; 117 } 118 } 119 120 public void init(Map props) { 121 String workflowSessionLocation = (String ) props.get("workflow.store"); 122 123 if (workflowSessionLocation == null) { 124 workflowSessionLocation = WorkflowStoreHomeFactory.JNDI_NAME; 125 } 126 127 try { 128 InitialContext context = new InitialContext (); 129 session = ((WorkflowStoreHome) PortableRemoteObject.narrow(context.lookup(workflowSessionLocation), WorkflowStoreHome.class)).create(); 130 } catch (Exception ex) { 131 log.error("Error looking up homes", ex); 132 throw new IllegalArgumentException (ex.toString()); 133 } 134 } 135 136 public Step markFinished(Step step, int actionId, Date finishDate, String status, String caller) throws StoreException { 137 try { 138 return session.markFinished(step, actionId, finishDate, status, caller); 139 } catch (RemoteException 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 ex) { 150 log.fatal("System error", ex); 151 } 152 } 153 154 public List query(WorkflowQuery query) { 155 throw new UnsupportedOperationException ("EJB store does not support queries"); 157 } 158 159 public List query(WorkflowExpressionQuery query) throws StoreException { 160 throw new UnsupportedOperationException ("EJB store does not support queries"); 161 } 162 } 163 | Popular Tags |