1 5 package com.opensymphony.workflow.util.beanshell; 6 7 import bsh.Interpreter; 8 import bsh.TargetError; 9 10 import com.opensymphony.module.propertyset.PropertySet; 11 12 import com.opensymphony.workflow.*; 13 import com.opensymphony.workflow.spi.WorkflowEntry; 14 15 import org.apache.commons.logging.Log; 16 import org.apache.commons.logging.LogFactory; 17 18 import java.util.Map ; 19 20 21 27 public class BeanShellValidator implements Validator { 28 30 private static final Log log = LogFactory.getLog(BeanShellValidator.class); 31 32 34 public void validate(Map transientVars, Map args, PropertySet ps) throws WorkflowException { 35 Interpreter i = new Interpreter(); 36 ClassLoader loader = Thread.currentThread().getContextClassLoader(); 37 38 try { 39 String contents = (String ) args.get(AbstractWorkflow.BSH_SCRIPT); 40 41 WorkflowContext context = (WorkflowContext) transientVars.get("context"); 42 WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry"); 43 44 if (loader != null) { 45 i.setClassLoader(loader); 46 } 47 48 i.set("entry", entry); 49 i.set("context", context); 50 i.set("transientVars", transientVars); 51 i.set("propertySet", ps); 52 53 Object o = i.eval(contents); 54 55 if (o != null) { 56 throw new InvalidInputException(o); 57 } 58 } catch (TargetError e) { 59 if (e.getTarget() instanceof WorkflowException) { 60 throw (WorkflowException) e.getTarget(); 61 } else { 62 throw new WorkflowException("Unexpected exception in beanshell validator script:" + e.getMessage(), e); 63 } 64 } catch (Exception e) { 65 String message = "Error executing beanshell validator"; 66 throw new WorkflowException(message, e); 67 } finally { 68 if (loader != null) { 69 i.setClassLoader(null); 70 } 71 } 72 } 73 } 74 | Popular Tags |