1 5 package com.opensymphony.workflow.util.bsf; 6 7 import com.ibm.bsf.BSFEngine; 8 import com.ibm.bsf.BSFException; 9 import com.ibm.bsf.BSFManager; 10 11 import com.opensymphony.module.propertyset.PropertySet; 12 13 import com.opensymphony.util.TextUtils; 14 15 import com.opensymphony.workflow.*; 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.util.Map ; 22 23 24 30 public class BSFFunctionProvider implements FunctionProvider { 31 33 private static final Log log = LogFactory.getLog(BSFFunctionProvider.class); 34 35 37 public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException { 38 String language = (String ) args.get(AbstractWorkflow.BSF_LANGUAGE); 39 String source = (String ) args.get(AbstractWorkflow.BSF_SOURCE); 40 int row = TextUtils.parseInt((String ) args.get(AbstractWorkflow.BSF_ROW)); 41 int col = TextUtils.parseInt((String ) args.get(AbstractWorkflow.BSF_COL)); 42 String script = (String ) args.get(AbstractWorkflow.BSF_SCRIPT); 43 44 WorkflowContext context = (WorkflowContext) transientVars.get("context"); 45 WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry"); 46 47 BSFManager mgr = new BSFManager(); 48 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 49 50 if (loader != null) { 51 mgr.setClassLoader(loader); 52 } 53 54 mgr.registerBean("entry", entry); 55 mgr.registerBean("context", context); 56 mgr.registerBean("transientVars", transientVars); 57 mgr.registerBean("propertySet", ps); 58 59 BSFEngine engine = null; 60 61 try { 62 engine = mgr.loadScriptingEngine(language); 63 } catch (BSFException e) { 64 String message = "Could not load scripting engine for BSF language: " + language; 65 throw new WorkflowException(message, e); 66 } 67 68 try { 69 engine.eval(source, row, col, script); 70 } catch (BSFException e) { 71 String message = "BSF script/function could not run"; 72 throw new WorkflowException(message, e); 73 } 74 } 75 } 76 | Popular Tags |