1 5 package com.opensymphony.workflow.util.bsf; 6 7 import com.ibm.bsf.BSFEngine; 8 import com.ibm.bsf.BSFManager; 9 10 import com.opensymphony.module.propertyset.PropertySet; 11 12 import com.opensymphony.util.TextUtils; 13 14 import com.opensymphony.workflow.AbstractWorkflow; 15 import com.opensymphony.workflow.InvalidInputException; 16 import com.opensymphony.workflow.Validator; 17 import com.opensymphony.workflow.WorkflowContext; 18 import com.opensymphony.workflow.WorkflowException; 19 import com.opensymphony.workflow.spi.WorkflowEntry; 20 21 import java.util.Map ; 22 23 24 30 public class BSFValidator implements Validator { 31 33 public void validate(Map transientVars, Map args, PropertySet ps) throws WorkflowException { 34 String language = (String ) args.get(AbstractWorkflow.BSF_LANGUAGE); 35 String source = (String ) args.get(AbstractWorkflow.BSF_SOURCE); 36 int row = TextUtils.parseInt((String ) args.get(AbstractWorkflow.BSF_ROW)); 37 int col = TextUtils.parseInt((String ) args.get(AbstractWorkflow.BSF_COL)); 38 String script = (String ) args.get(AbstractWorkflow.BSF_SCRIPT); 39 40 WorkflowContext context = (WorkflowContext) transientVars.get("context"); 41 WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry"); 42 43 BSFManager mgr = new BSFManager(); 44 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 45 46 if (loader != null) { 47 mgr.setClassLoader(loader); 48 } 49 50 mgr.registerBean("entry", entry); 51 mgr.registerBean("context", context); 52 mgr.registerBean("transientVars", transientVars); 53 mgr.registerBean("propertySet", ps); 54 55 try { 56 BSFEngine engine = mgr.loadScriptingEngine(language); 57 Object o = engine.eval(source, row, col, script); 58 59 if (o != null) { 60 throw new InvalidInputException(o); 61 } 62 } catch (Exception e) { 63 String message = "Could not execute BSF validator"; 64 throw new WorkflowException(message, e); 65 } 66 } 67 } 68 | Popular Tags |