1 5 package com.opensymphony.workflow.util.beanshell; 6 7 import bsh.EvalError; 8 import bsh.Interpreter; 9 import bsh.TargetError; 10 11 import com.opensymphony.workflow.*; 12 import com.opensymphony.workflow.spi.WorkflowEntry; 13 14 import org.apache.commons.logging.Log; 15 import org.apache.commons.logging.LogFactory; 16 17 import java.util.Map ; 18 19 20 26 public class BeanShellRegister implements Register { 27 29 private static final Log log = LogFactory.getLog(BeanShellRegister.class); 30 31 33 public Object registerVariable(WorkflowContext context, WorkflowEntry entry, Map args) throws WorkflowException { 34 String script = (String ) args.get(AbstractWorkflow.BSH_SCRIPT); 35 36 Interpreter i = new Interpreter(); 37 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 38 39 try { 40 if (loader != null) { 41 i.setClassLoader(loader); 42 } 43 44 i.set("entry", entry); 45 i.set("context", context); 46 47 Object o = i.eval(script); 48 49 return o; 50 } catch (TargetError targetError) { 51 if (targetError.getTarget() instanceof WorkflowException) { 52 throw (WorkflowException) targetError.getTarget(); 53 } else { 54 String message = "Could not get object registered in to variable map"; 55 throw new WorkflowException(message, targetError.getTarget()); 56 } 57 } catch (EvalError e) { 58 String message = "Could not get object registered in to variable map"; 59 throw new WorkflowException(message, e); 60 } finally { 61 if (loader != null) { 62 i.setClassLoader(null); 63 } 64 } 65 } 66 } 67 | Popular Tags |