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 BSFCondition implements Condition { 31 33 private static final Log log = LogFactory.getLog(BSFCondition.class); 34 35 37 public boolean passesCondition(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 mgr.registerBean("jn", transientVars.get("jn")); 59 60 try { 61 BSFEngine engine = mgr.loadScriptingEngine(language); 62 Object o = engine.eval(source, row, col, script); 63 64 if (o == null) { 65 return false; 66 } else { 67 return TextUtils.parseBoolean(o.toString()); 68 } 69 } catch (BSFException e) { 70 String message = "Could not execute BSF script"; 71 throw new WorkflowException(message, e); 72 } 73 } 74 } 75 | Popular Tags |