Anonymous avatar Anonymous committed dfd5519

Initial import from SourceForge

Comments (0)

Files changed (4)

src/java/com/opensymphony/workflow/util/beanshell/BeanShellCondition.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.util.beanshell;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+
+import com.opensymphony.module.propertyset.PropertySet;
+
+import com.opensymphony.util.TextUtils;
+
+import com.opensymphony.workflow.*;
+import com.opensymphony.workflow.spi.WorkflowEntry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+
+
+/**
+ *
+ *
+ * @author $Author: hani $
+ * @version $Revision: 1.1.1.1 $
+ */
+public class BeanShellCondition implements Condition {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(BeanShellCondition.class);
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public boolean passesCondition(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
+        String script = (String) args.get(AbstractWorkflow.BSH_SCRIPT);
+
+        WorkflowContext context = (WorkflowContext) transientVars.get("context");
+        WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
+
+        Interpreter i = new Interpreter();
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+        try {
+            if (loader != null) {
+                i.setClassLoader(loader);
+            }
+
+            i.set("entry", entry);
+            i.set("context", context);
+            i.set("transientVars", transientVars);
+            i.set("propertySet", ps);
+            i.set("jn", transientVars.get("jn"));
+
+            Object o = i.eval(script);
+
+            if (o == null) {
+                return false;
+            } else {
+                return TextUtils.parseBoolean(o.toString());
+            }
+        } catch (EvalError e) {
+            String message = "Could not execute BeanShell script";
+            log.error(message, e);
+            throw new WorkflowException(message, e);
+        } finally {
+            if (loader != null) {
+                i.setClassLoader(null);
+            }
+        }
+    }
+}

src/java/com/opensymphony/workflow/util/beanshell/BeanShellFunctionProvider.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.util.beanshell;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+
+import com.opensymphony.module.propertyset.PropertySet;
+
+import com.opensymphony.workflow.*;
+import com.opensymphony.workflow.spi.WorkflowEntry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+
+
+/**
+ *
+ *
+ * @author $Author: hani $
+ * @version $Revision: 1.1.1.1 $
+ */
+public class BeanShellFunctionProvider implements FunctionProvider {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(BeanShellFunctionProvider.class);
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
+        String script = (String) args.get(AbstractWorkflow.BSH_SCRIPT);
+        Interpreter i = null;
+        ClassLoader loader = null;
+        WorkflowContext context = (WorkflowContext) transientVars.get("context");
+        WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
+        loader = Thread.currentThread().getContextClassLoader();
+
+        try {
+            i = new Interpreter();
+
+            if (loader != null) {
+                i.setClassLoader(loader);
+            }
+
+            i.set("entry", entry);
+            i.set("context", context);
+            i.set("transientVars", transientVars);
+            i.set("propertySet", ps);
+        } catch (EvalError evalError) {
+            String message = "Could not set values for BSH script";
+            log.error(message, evalError);
+            throw new WorkflowException(message, evalError);
+        }
+
+        try {
+            i.eval(script);
+        } catch (EvalError evalError) {
+            String message = "Evaluation error while running BSH script";
+            log.error(message, evalError);
+            throw new WorkflowException(message, evalError);
+        } finally {
+            if ((i != null) && (loader != null)) {
+                i.setClassLoader(null);
+            }
+        }
+    }
+}

src/java/com/opensymphony/workflow/util/beanshell/BeanShellRegister.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.util.beanshell;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+
+import com.opensymphony.workflow.*;
+import com.opensymphony.workflow.spi.WorkflowEntry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+
+
+/**
+ *
+ *
+ * @author $Author: hani $
+ * @version $Revision: 1.1.1.1 $
+ */
+public class BeanShellRegister implements Register {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(BeanShellRegister.class);
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public Object registerVariable(WorkflowContext context, WorkflowEntry entry, Map args) throws WorkflowException {
+        String script = (String) args.get(AbstractWorkflow.BSH_SCRIPT);
+
+        Interpreter i = new Interpreter();
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+        try {
+            if (loader != null) {
+                i.setClassLoader(loader);
+            }
+
+            i.set("entry", entry);
+            i.set("context", context);
+
+            Object o = i.eval(script);
+
+            return o;
+        } catch (EvalError e) {
+            String message = "Could not get object registered in to variable map";
+            throw new WorkflowException(message, e);
+        } finally {
+            if (loader != null) {
+                i.setClassLoader(null);
+            }
+        }
+    }
+}

src/java/com/opensymphony/workflow/util/beanshell/BeanShellValidator.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.util.beanshell;
+
+import bsh.Interpreter;
+
+import com.opensymphony.module.propertyset.PropertySet;
+
+import com.opensymphony.workflow.*;
+import com.opensymphony.workflow.spi.WorkflowEntry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+
+
+/**
+ *
+ *
+ * @author $Author: hani $
+ * @version $Revision: 1.1.1.1 $
+ */
+public class BeanShellValidator implements Validator {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(BeanShellValidator.class);
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void validate(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
+        Interpreter i = new Interpreter();
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+        try {
+            String contents = (String) args.get(AbstractWorkflow.BSH_SCRIPT);
+
+            WorkflowContext context = (WorkflowContext) transientVars.get("context");
+            WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
+
+            if (loader != null) {
+                i.setClassLoader(loader);
+            }
+
+            i.set("entry", entry);
+            i.set("context", context);
+            i.set("transientVars", transientVars);
+            i.set("propertySet", ps);
+
+            Object o = i.eval(contents);
+
+            if (o != null) {
+                throw new InvalidInputException(o);
+            }
+        } catch (Exception e) {
+            String message = "Error executing beanshell validator";
+            throw new WorkflowException(message, e);
+        } finally {
+            if (loader != null) {
+                i.setClassLoader(null);
+            }
+        }
+    }
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.