1 5 package com.opensymphony.workflow.util; 6 7 import com.opensymphony.module.propertyset.PropertySet; 8 9 import com.opensymphony.workflow.FunctionProvider; 10 import com.opensymphony.workflow.spi.WorkflowEntry; 11 12 import org.apache.commons.logging.Log; 13 import org.apache.commons.logging.LogFactory; 14 15 import java.lang.reflect.Method ; 16 17 import java.util.Hashtable ; 18 import java.util.Map ; 19 20 import javax.naming.InitialContext ; 21 22 import javax.rmi.PortableRemoteObject ; 23 24 25 50 public class EJBInvoker implements FunctionProvider { 51 53 private static final Log log = LogFactory.getLog(EJBInvoker.class); 54 55 57 public void execute(Map transientVars, Map args, PropertySet ps) { 58 Class homeClass = null; 59 Object home = null; 60 WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry"); 61 Hashtable env = new Hashtable (args); 62 63 try { 64 InitialContext ic = new InitialContext (env); 65 66 if (log.isDebugEnabled()) { 67 log.debug("executing with properties=" + args); 68 } 69 70 if (args.containsKey("ejb-home")) { 71 homeClass = Class.forName((String ) args.get("ejb-home")); 72 } else if (args.containsKey("ejb-local-home")) { 73 homeClass = Class.forName((String ) args.get("ejb-local-home")); 74 } 75 76 home = PortableRemoteObject.narrow(ic.lookup((String ) args.get("ejb-jndi-location")), homeClass); 77 78 Method method = homeClass.getMethod("create", new Class [0]); 79 80 if (java.rmi.Remote .class.isAssignableFrom(homeClass)) { 81 WorkflowListener listener = (WorkflowListener) method.invoke(home, new Object [0]); 82 listener.stateChanged(entry); 83 } else { 84 WorkflowLocalListener listener = (WorkflowLocalListener) method.invoke(home, new Object [0]); 85 listener.stateChanged(entry); 86 } 87 } catch (Exception e) { 88 log.error("Error invoking EJB homeClass=" + homeClass, e); 89 } 90 } 91 } 92 | Popular Tags |