Commits

Anonymous committed 2de430c

Initial import from SourceForge

Comments (0)

Files changed (4)

src/java/com/opensymphony/workflow/util/bsf/BSFCondition.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.util.bsf;
+
+import com.ibm.bsf.BSFEngine;
+import com.ibm.bsf.BSFException;
+import com.ibm.bsf.BSFManager;
+
+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 BSFCondition implements Condition {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(BSFCondition.class);
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public boolean passesCondition(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
+        String language = (String) args.get(AbstractWorkflow.BSF_LANGUAGE);
+        String source = (String) args.get(AbstractWorkflow.BSF_SOURCE);
+        int row = TextUtils.parseInt((String) args.get(AbstractWorkflow.BSF_ROW));
+        int col = TextUtils.parseInt((String) args.get(AbstractWorkflow.BSF_COL));
+        String script = (String) args.get(AbstractWorkflow.BSF_SCRIPT);
+
+        WorkflowContext context = (WorkflowContext) transientVars.get("context");
+        WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
+
+        BSFManager mgr = new BSFManager();
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+        if (loader != null) {
+            mgr.setClassLoader(loader);
+        }
+
+        mgr.registerBean("entry", entry);
+        mgr.registerBean("context", context);
+        mgr.registerBean("transientVars", transientVars);
+        mgr.registerBean("propertySet", ps);
+        mgr.registerBean("jn", transientVars.get("jn"));
+
+        try {
+            BSFEngine engine = mgr.loadScriptingEngine(language);
+            Object o = engine.eval(source, row, col, script);
+
+            if (o == null) {
+                return false;
+            } else {
+                return TextUtils.parseBoolean(o.toString());
+            }
+        } catch (BSFException e) {
+            String message = "Could not execute BSF script";
+            throw new WorkflowException(message, e);
+        }
+    }
+}

src/java/com/opensymphony/workflow/util/bsf/BSFFunctionProvider.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.util.bsf;
+
+import com.ibm.bsf.BSFEngine;
+import com.ibm.bsf.BSFException;
+import com.ibm.bsf.BSFManager;
+
+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 BSFFunctionProvider implements FunctionProvider {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(BSFFunctionProvider.class);
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
+        String language = (String) args.get(AbstractWorkflow.BSF_LANGUAGE);
+        String source = (String) args.get(AbstractWorkflow.BSF_SOURCE);
+        int row = TextUtils.parseInt((String) args.get(AbstractWorkflow.BSF_ROW));
+        int col = TextUtils.parseInt((String) args.get(AbstractWorkflow.BSF_COL));
+        String script = (String) args.get(AbstractWorkflow.BSF_SCRIPT);
+
+        WorkflowContext context = (WorkflowContext) transientVars.get("context");
+        WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
+
+        BSFManager mgr = new BSFManager();
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+        if (loader != null) {
+            mgr.setClassLoader(loader);
+        }
+
+        mgr.registerBean("entry", entry);
+        mgr.registerBean("context", context);
+        mgr.registerBean("transientVars", transientVars);
+        mgr.registerBean("propertySet", ps);
+
+        BSFEngine engine = null;
+
+        try {
+            engine = mgr.loadScriptingEngine(language);
+        } catch (BSFException e) {
+            String message = "Could not load scripting engine for BSF language: " + language;
+            throw new WorkflowException(message, e);
+        }
+
+        try {
+            engine.eval(source, row, col, script);
+        } catch (BSFException e) {
+            String message = "BSF script/function could not run";
+            throw new WorkflowException(message, e);
+        }
+    }
+}

src/java/com/opensymphony/workflow/util/bsf/BSFRegister.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.util.bsf;
+
+import com.ibm.bsf.BSFEngine;
+import com.ibm.bsf.BSFException;
+import com.ibm.bsf.BSFManager;
+
+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 BSFRegister implements Register {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(BSFRegister.class);
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public Object registerVariable(WorkflowContext context, WorkflowEntry entry, Map args) throws WorkflowException {
+        String language = (String) args.get(AbstractWorkflow.BSF_LANGUAGE);
+        String source = (String) args.get(AbstractWorkflow.BSF_SOURCE);
+        int row = TextUtils.parseInt((String) args.get(AbstractWorkflow.BSF_ROW));
+        int col = TextUtils.parseInt((String) args.get(AbstractWorkflow.BSF_COL));
+        String script = (String) args.get(AbstractWorkflow.BSF_SCRIPT);
+
+        BSFManager mgr = new BSFManager();
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+        if (loader != null) {
+            mgr.setClassLoader(loader);
+        }
+
+        mgr.registerBean("entry", entry);
+        mgr.registerBean("context", context);
+
+        try {
+            BSFEngine engine = mgr.loadScriptingEngine(language);
+            Object o = engine.eval(source, row, col, script);
+
+            return o;
+        } catch (BSFException e) {
+            String message = "Could not get object registered in to variable map";
+            throw new WorkflowException(message, e);
+        }
+    }
+}

src/java/com/opensymphony/workflow/util/bsf/BSFValidator.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.util.bsf;
+
+import com.ibm.bsf.BSFEngine;
+import com.ibm.bsf.BSFManager;
+
+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 BSFValidator implements Validator {
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void validate(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
+        String language = (String) args.get(AbstractWorkflow.BSF_LANGUAGE);
+        String source = (String) args.get(AbstractWorkflow.BSF_SOURCE);
+        int row = TextUtils.parseInt((String) args.get(AbstractWorkflow.BSF_ROW));
+        int col = TextUtils.parseInt((String) args.get(AbstractWorkflow.BSF_COL));
+        String script = (String) args.get(AbstractWorkflow.BSF_SCRIPT);
+
+        WorkflowContext context = (WorkflowContext) transientVars.get("context");
+        WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
+
+        BSFManager mgr = new BSFManager();
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+
+        if (loader != null) {
+            mgr.setClassLoader(loader);
+        }
+
+        mgr.registerBean("entry", entry);
+        mgr.registerBean("context", context);
+        mgr.registerBean("transientVars", transientVars);
+        mgr.registerBean("propertySet", ps);
+
+        try {
+            BSFEngine engine = mgr.loadScriptingEngine(language);
+            Object o = engine.eval(source, row, col, script);
+
+            if (o != null) {
+                throw new InvalidInputException(o);
+            }
+        } catch (Exception e) {
+            String message = "Could not execute BSF validator";
+            throw new WorkflowException(message, e);
+        }
+    }
+}