1 23 24 package org.infoglue.cms.util.workflow; 25 26 import java.util.Collections ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 import javax.servlet.http.HttpServletRequest ; 32 33 import org.apache.log4j.Logger; 34 35 import webwork.action.ActionContext; 36 37 import com.opensymphony.module.propertyset.PropertySet; 38 import com.opensymphony.workflow.FunctionProvider; 39 import com.opensymphony.workflow.WorkflowContext; 40 import com.opensymphony.workflow.WorkflowException; 41 42 43 57 public class CustomClassExecutor implements FunctionProvider 58 { 59 private final static Logger logger = Logger.getLogger(CustomClassExecutor.class.getName()); 60 61 public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException 62 { 63 logger.info("CustomClassExecutor.execute........"); 64 final WorkflowContext wfContext = (WorkflowContext) transientVars.get("context"); 65 66 String className = (String ) args.get("customClass.name"); 67 HttpServletRequest request = (HttpServletRequest ) transientVars.get("request"); 68 logger.info("className:" + className); 69 70 Iterator paramsIterator = transientVars.keySet().iterator(); 71 while(paramsIterator.hasNext()) 72 { 73 String key = (String )paramsIterator.next(); 74 logger.info("transientVars key:" + key); 75 Object value = args.get(key); 76 logger.info("transientVars value:" + value); 77 } 78 79 Map params = new HashMap (transientVars); 80 params.putAll(args); 81 ActionContext.setParameters(Collections.unmodifiableMap(params)); 82 83 CustomWorkflowAction customWorkflowAction = getCustomWorkflowActionWithName(className); 84 if(customWorkflowAction != null) 85 customWorkflowAction.invokeAction(wfContext.getCaller(), request, Collections.unmodifiableMap(params), ps); 86 else 87 { 88 logger.warn("Could not find custom class " + className + ". Is it in the classpath?"); 89 throw new WorkflowException("Could not find custom class " + className + ". Is it in the classpath?"); 90 } 91 } 92 93 96 97 public CustomWorkflowAction getCustomWorkflowActionWithName(String className) 98 { 99 try 100 { 101 Class theClass = null; 102 try 103 { 104 theClass = Thread.currentThread().getContextClassLoader().loadClass( className ); 105 } 106 catch (ClassNotFoundException e) 107 { 108 theClass = getClass().getClassLoader().loadClass( className ); 109 } 110 return (CustomWorkflowAction)theClass.newInstance(); 111 112 } 113 catch (InstantiationException e) 114 { 115 e.printStackTrace(); 116 } 117 catch (IllegalAccessException e) 118 { 119 e.printStackTrace(); 120 } 121 catch (ClassNotFoundException e) 122 { 123 e.printStackTrace(); 124 } 125 126 return null; 127 } 128 } | Popular Tags |