1 5 package com.opensymphony.workflow.ejb; 6 7 import com.opensymphony.module.propertyset.PropertySet; 8 9 import com.opensymphony.util.EJBUtils; 10 11 import com.opensymphony.workflow.*; 12 import com.opensymphony.workflow.config.Configuration; 13 import com.opensymphony.workflow.loader.WorkflowDescriptor; 14 import com.opensymphony.workflow.query.WorkflowExpressionQuery; 15 import com.opensymphony.workflow.query.WorkflowQuery; 16 import com.opensymphony.workflow.spi.WorkflowEntry; 17 18 import org.apache.commons.logging.Log; 19 import org.apache.commons.logging.LogFactory; 20 21 import java.rmi.RemoteException ; 22 23 import java.util.Collections ; 24 import java.util.List ; 25 import java.util.Map ; 26 27 import javax.ejb.CreateException ; 28 29 import javax.naming.NamingException ; 30 31 32 39 public class EJBWorkflow implements Workflow { 40 42 private static final Log log = LogFactory.getLog(EJBWorkflow.class); 43 44 46 private WorkflowRemote wf; 47 48 50 public EJBWorkflow(String location) throws CreateException , RemoteException , WorkflowException { 51 WorkflowHome home = null; 52 53 try { 54 home = (WorkflowHome) EJBUtils.lookup(location, WorkflowHome.class); 55 } catch (NamingException e) { 56 try { 57 home = (WorkflowHome) EJBUtils.lookup(WorkflowHomeFactory.COMP_NAME, WorkflowHome.class); 58 } catch (NamingException e1) { 59 try { 60 home = (WorkflowHome) EJBUtils.lookup(WorkflowHomeFactory.JNDI_NAME, WorkflowHome.class); 61 } catch (NamingException e2) { 62 throw new WorkflowException("Could not get a handle on the workflow Home EJB", e); 63 } 64 } 65 } 66 67 wf = home.create(); 68 } 69 70 public EJBWorkflow() throws CreateException , RemoteException , WorkflowException { 71 this(WorkflowHomeFactory.JNDI_NAME); 72 } 73 74 76 public int[] getAvailableActions(long id) { 77 try { 78 return wf.getAvailableActions(id); 79 } catch (RemoteException e) { 80 log.error("Error getting available actions", e); 81 82 return new int[0]; 83 } 84 } 85 86 public int[] getAvailableActions(long id, Map inputs) { 87 try { 88 return wf.getAvailableActions(id, inputs); 89 } catch (RemoteException e) { 90 log.error("Error getting available actions", e); 91 92 return new int[0]; 93 } 94 } 95 96 public void setConfiguration(Configuration configuration) { 97 try { 98 wf.setConfiguration(configuration); 99 } catch (RemoteException e) { 100 log.fatal("Error setting configuration", e); 101 } 102 } 103 104 public List getCurrentSteps(long id) { 105 try { 106 return wf.getCurrentSteps(id); 107 } catch (RemoteException e) { 108 log.error("Error getting current steps", e); 109 110 return Collections.EMPTY_LIST; 111 } 112 } 113 114 public int getEntryState(long id) { 115 try { 116 return wf.getEntryState(id); 117 } catch (RemoteException e) { 118 log.error("Error getting entry state", e); 119 120 return WorkflowEntry.UNKNOWN; 121 } 122 } 123 124 public List getHistorySteps(long id) { 125 try { 126 return wf.getHistorySteps(id); 127 } catch (RemoteException e) { 128 log.error("Error getting history steps", e); 129 130 return Collections.EMPTY_LIST; 131 } 132 } 133 134 public PropertySet getPropertySet(long id) { 135 try { 136 return wf.getPropertySet(id); 137 } catch (RemoteException e) { 138 log.error("Error getting PropertySet", e); 139 140 return null; 141 } 142 } 143 144 public List getSecurityPermissions(long id) { 145 try { 146 return wf.getSecurityPermissions(id); 147 } catch (RemoteException e) { 148 log.error("Error getting security permissions", e); 149 150 return Collections.EMPTY_LIST; 151 } 152 } 153 154 public WorkflowDescriptor getWorkflowDescriptor(String workflowName) { 155 try { 156 return wf.getWorkflowDescriptor(workflowName); 157 } catch (RemoteException e) { 158 log.error("Error getting descriptor", e); 159 160 return null; 161 } 162 } 163 164 public String getWorkflowName(long id) { 165 try { 166 return wf.getWorkflowName(id); 167 } catch (RemoteException e) { 168 log.error("Error getting workflow name", e); 169 170 return null; 171 } 172 } 173 174 public String [] getWorkflowNames() { 175 try { 176 return wf.getWorkflowNames(); 177 } catch (RemoteException e) { 178 log.error("Error calling getWorkflowNames", e); 179 180 return new String [0]; 181 } 182 } 183 184 public boolean canInitialize(String workflowName, int initialState) { 185 try { 186 return wf.canInitialize(workflowName, initialState); 187 } catch (RemoteException e) { 188 log.error("Error checking canInitialize", e); 189 190 return false; 191 } 192 } 193 194 public boolean canInitialize(String workflowName, int initialAction, Map inputs) { 195 try { 196 return wf.canInitialize(workflowName, initialAction, inputs); 197 } catch (RemoteException e) { 198 log.error("Error checking canInitialize", e); 199 200 return false; 201 } 202 } 203 204 public boolean canModifyEntryState(long id, int newState) { 205 try { 206 return wf.canModifyEntryState(id, newState); 207 } catch (RemoteException e) { 208 log.error("Error checking modifying entry state", e); 209 210 return false; 211 } 212 } 213 214 public void changeEntryState(long id, int newState) throws WorkflowException { 215 try { 216 wf.changeEntryState(id, newState); 217 } catch (RemoteException e) { 218 log.error("Error modifying entry state", e); 219 throw new WorkflowException(e); 220 } 221 } 222 223 public void doAction(long id, int actionId, Map inputs) throws InvalidInputException, WorkflowException { 224 try { 225 wf.doAction(id, actionId, inputs); 226 } catch (RemoteException e) { 227 log.error("Error performing action", e); 228 throw new WorkflowException(e); 229 } 230 } 231 232 public void executeTriggerFunction(long id, int triggerId) throws WorkflowException { 233 try { 234 wf.executeTriggerFunction(id, triggerId); 235 } catch (RemoteException e) { 236 log.error("Error executing trigger", e); 237 throw new WorkflowException(e); 238 } 239 } 240 241 public long initialize(String workflowName, int initialState, Map inputs) throws InvalidRoleException, InvalidInputException, WorkflowException { 242 try { 243 return wf.initialize(workflowName, initialState, inputs); 244 } catch (RemoteException e) { 245 log.error("Error initializing", e); 246 throw new WorkflowException(e); 247 } 248 } 249 250 public List query(WorkflowExpressionQuery query) throws WorkflowException { 251 throw new QueryNotSupportedException("EJB Store does not support queries"); 252 } 253 254 public List query(WorkflowQuery query) throws WorkflowException { 255 throw new QueryNotSupportedException("EJB Store does not support queries"); 256 } 257 258 public boolean removeWorkflowDescriptor(String workflowName) throws FactoryException { 259 try { 260 return wf.removeWorkflowDescriptor(workflowName); 261 } catch (RemoteException e) { 262 log.error("Error removing workflow " + workflowName, e); 263 264 return false; 265 } 266 } 267 268 public boolean saveWorkflowDescriptor(String workflowName, WorkflowDescriptor descriptor, boolean replace) throws FactoryException { 269 try { 270 return wf.saveWorkflowDescriptor(workflowName, descriptor, replace); 271 } catch (RemoteException e) { 272 log.error("Error saving workflow", e); 273 throw new FactoryException(e); 274 } 275 } 276 } 277 | Popular Tags |