Commits

Anonymous committed 1460a9a

Initial import from SourceForge

Comments (0)

Files changed (5)

src/java/com/opensymphony/workflow/loader/XMLUtil.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.loader;
+
+import com.opensymphony.workflow.util.XMLizable;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.io.PrintWriter;
+
+
+/**
+ *
+ *
+ * @author <a href="mailto:plightbo@.com">Pat Lightbody</a>
+ */
+public class XMLUtil {
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public static Element getChildElement(Element parent, String childName) {
+        NodeList children = parent.getChildNodes();
+        int size = children.getLength();
+
+        for (int i = 0; i < size; i++) {
+            Node node = children.item(i);
+
+            if (node.getNodeType() == Node.ELEMENT_NODE) {
+                Element element = (Element) node;
+
+                if (childName.equals(element.getNodeName())) {
+                    return element;
+                }
+            }
+        }
+
+        return null;
+    }
+
+    public static String encode(Object string) {
+        if (string == null) {
+            return "";
+        }
+
+        char[] chars = string.toString().toCharArray();
+        StringBuffer out = new StringBuffer();
+
+        for (int i = 0; i < chars.length; i++) {
+            switch (chars[i]) {
+            case '&':
+                out.append("&amp;");
+
+                break;
+
+            case '<':
+                out.append("&lt;");
+
+                break;
+
+            case '>':
+                out.append("&gt;");
+
+                break;
+
+            case '\"':
+                out.append("&quot;");
+
+                break;
+
+            default:
+                out.append(chars[i]);
+            }
+        }
+
+        return out.toString();
+    }
+
+    public static void printIndent(PrintWriter out, int indent) {
+        for (int i = 0; i < indent; i++) {
+            out.print(XMLizable.INDENT);
+        }
+    }
+}

src/java/com/opensymphony/workflow/query/WorkflowQuery.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.query;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.Serializable;
+
+
+/**
+ *
+ *
+ * @author $Author: hani $
+ * @version $Revision: 1.1.1.1 $
+ */
+public class WorkflowQuery implements Serializable {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(WorkflowQuery.class);
+    public final static int EQUALS = 1;
+    public final static int LT = 2;
+    public final static int GT = 3;
+    public final static int BETWEEN = 4;
+    public final static int NOT_EQUALS = 5;
+    public final static int AND = 6;
+    public final static int OR = 7;
+    public final static int XOR = 8;
+    public final static int OWNER = 1;
+    public final static int START_DATE = 2;
+    public final static int FINISH_DATE = 3;
+    public final static int ACTION = 4;
+    public final static int STEP = 5;
+    public final static int CALLER = 6;
+    public final static int STATUS = 7;
+    public final static int HISTORY = 1;
+    public final static int CURRENT = 2;
+
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private Object value;
+    private WorkflowQuery left;
+    private WorkflowQuery right;
+    private int field;
+    private int operator;
+    private int type;
+
+    //~ Constructors ///////////////////////////////////////////////////////////
+
+    public WorkflowQuery(WorkflowQuery left, int operator, WorkflowQuery right) {
+        this.operator = operator;
+        this.left = left;
+        this.right = right;
+    }
+
+    public WorkflowQuery(int field, int type, int operator, Object value) {
+        this.type = type;
+        this.operator = operator;
+        this.field = field;
+        this.value = value;
+    }
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public int getField() {
+        return field;
+    }
+
+    public WorkflowQuery getLeft() {
+        return left;
+    }
+
+    public int getOperator() {
+        return operator;
+    }
+
+    public WorkflowQuery getRight() {
+        return right;
+    }
+
+    public int getType() {
+        int qtype = type;
+
+        if (qtype == 0) {
+            if (getLeft() != null) {
+                qtype = getLeft().getType();
+            }
+        }
+
+        return qtype;
+    }
+
+    public Object getValue() {
+        return value;
+    }
+}

src/java/com/opensymphony/workflow/spi/SimpleStep.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.spi;
+
+import java.io.Serializable;
+
+import java.util.Date;
+
+
+/**
+ * Simple implementation
+ *
+ * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
+ */
+public class SimpleStep implements Step, Serializable {
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private Date dueDate;
+    private Date finishDate;
+    private Date startDate;
+    private String caller;
+    private String owner;
+    private String status;
+    private long[] previousStepIds;
+    private int actionId;
+    private int stepId;
+    private long entryId;
+    private long id;
+
+    //~ Constructors ///////////////////////////////////////////////////////////
+
+    public SimpleStep(long id, long entryId, int stepId, int actionId, String owner, Date startDate, Date dueDate, Date finishDate, String status, long[] previousStepIds, String caller) {
+        this.id = id;
+        this.entryId = entryId;
+        this.stepId = stepId;
+        this.actionId = actionId;
+        this.owner = owner;
+        this.startDate = startDate;
+        this.finishDate = finishDate;
+        this.dueDate = dueDate;
+        this.status = status;
+        this.previousStepIds = previousStepIds;
+        this.caller = caller;
+    }
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void setActionId(int actionId) {
+        this.actionId = actionId;
+    }
+
+    public int getActionId() {
+        return actionId;
+    }
+
+    public void setCaller(String caller) {
+        this.caller = caller;
+    }
+
+    public String getCaller() {
+        return caller;
+    }
+
+    public Date getDueDate() {
+        return dueDate;
+    }
+
+    public void setEntryId(long entryId) {
+        this.entryId = entryId;
+    }
+
+    public long getEntryId() {
+        return entryId;
+    }
+
+    public void setFinishDate(Date finishDate) {
+        this.finishDate = finishDate;
+    }
+
+    public Date getFinishDate() {
+        return finishDate;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setOwner(String owner) {
+        this.owner = owner;
+    }
+
+    public String getOwner() {
+        return owner;
+    }
+
+    public void setPreviousStepIds(long[] previousStepIds) {
+        this.previousStepIds = previousStepIds;
+    }
+
+    public long[] getPreviousStepIds() {
+        return previousStepIds;
+    }
+
+    public void setStartDate(Date startDate) {
+        this.startDate = startDate;
+    }
+
+    public Date getStartDate() {
+        return startDate;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStepId(int stepId) {
+        this.stepId = stepId;
+    }
+
+    public int getStepId() {
+        return stepId;
+    }
+}

src/java/com/opensymphony/workflow/util/JMSMessage.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.util;
+
+import com.opensymphony.module.propertyset.PropertySet;
+
+import com.opensymphony.workflow.FunctionProvider;
+import com.opensymphony.workflow.spi.WorkflowEntry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.*;
+
+import javax.jms.*;
+
+import javax.naming.InitialContext;
+
+
+/**
+ * Sends out a JMS TextMessage to a specified Queue or Topic. The following arguments
+ * are expected:
+ *
+ * <ul>
+ *  <li>queue-factory-location - the location to be passed to InitialContext.lookup</li>
+ *  <li>queue-location - the location to be passed to InitialContext.lookup</li>
+ *  <li>topic-factory-location - the location to be passed to InitialContext.lookup</li>
+ *  <li>topic-location - the location to be passed to InitialContext.lookup</li>
+ *  <li>text - the text message to be included in this JMS message</li>
+ * </ul>
+ *
+ * Also, please note that the entire set of properties will be passed through to the
+ * constructor for InitialContext, meaning that if you need to use an
+ * InintialContextFactory other than the default one, you are free to include arguments
+ * that will do so.
+ *
+ * Also note that all arguments are also passed to the TextMessage using
+ * setObjectProperty(), except for "text" which is set using setText(). An extra
+ * property is always added to denote the workflow entry for this message. This is
+ * stored as a long property, with the name 'workflowEntry'.
+ *
+ * @author Hani Suleiman
+ * @version $Revision: 1.1.1.1 $
+ */
+public class JMSMessage implements FunctionProvider {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(JMSMessage.class);
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void execute(Map transientVars, Map args, PropertySet ps) {
+        WorkflowEntry entry = (WorkflowEntry) transientVars.get("entry");
+
+        try {
+            Hashtable env = new Hashtable(args);
+            InitialContext initialContext = new InitialContext(env);
+
+            if (args.containsKey("queue-factory-location")) {
+                QueueConnectionFactory queueFactory = (QueueConnectionFactory) initialContext.lookup((String) args.get("queue-factory-location"));
+                QueueConnection conn = queueFactory.createQueueConnection();
+                conn.start();
+
+                QueueSession queueSession = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+                Queue queue = (Queue) initialContext.lookup((String) args.get("queue-location"));
+                QueueSender sender = queueSession.createSender(queue);
+                TextMessage message = queueSession.createTextMessage();
+                populateMessage(message, entry, args);
+                sender.send(message);
+            } else if (args.containsKey("topic-factory-location")) {
+                TopicConnectionFactory topicFactory = (TopicConnectionFactory) initialContext.lookup((String) args.get("topic-factory-location"));
+                TopicConnection conn = topicFactory.createTopicConnection();
+                conn.start();
+
+                TopicSession topicSession = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+                Topic topic = (Topic) initialContext.lookup((String) args.get("topic-location"));
+                TopicPublisher publisher = topicSession.createPublisher(topic);
+                TextMessage message = topicSession.createTextMessage();
+                populateMessage(message, entry, args);
+                publisher.publish(message);
+            }
+        } catch (Exception ex) {
+            log.error("Error sending JMS message", ex);
+        }
+    }
+
+    private void populateMessage(TextMessage message, WorkflowEntry entry, Map properties) throws JMSException {
+        message.setText((String) properties.get("text"));
+        message.setLongProperty("workflowEntry", entry.getId());
+
+        for (Iterator iterator = properties.entrySet().iterator();
+                iterator.hasNext();) {
+            Map.Entry mapEntry = (Map.Entry) iterator.next();
+
+            // don't include "text", it was already done
+            if (!"text".equals(mapEntry.getKey())) {
+                message.setObjectProperty((String) mapEntry.getKey(), mapEntry.getValue());
+            }
+        }
+    }
+}

src/java/com/opensymphony/workflow/util/LogRegister.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.util;
+
+import com.opensymphony.util.TextUtils;
+
+import com.opensymphony.workflow.Register;
+import com.opensymphony.workflow.WorkflowContext;
+import com.opensymphony.workflow.spi.WorkflowEntry;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+
+
+/**
+ * This is a register, which helps logging using commons-logging.
+ * It wraps a Logger instance which is linked to the "OSWorkflow/<workflow_name>/<id>" category
+ *
+ * Following optional arguments available:
+ * <ul>
+ *  <li>addInstanceId=true/false - if the instance id of the workflow should be added to the category. Defaults to false</li>
+ *  <li>Category="OSWorkflow" - change the name of the log category other than "OSWorkflow"</li>
+ * </ul>
+ *
+ *
+ * If you register this class as "Logger", then you may use it from a Beanshell script like:
+ * <pre>
+ * logger = variables.get("logger");
+ * logger.debug("hello logger!");
+ * </pre>
+ *
+ * @author Zoltan Luspai
+ */
+public class LogRegister implements Register {
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    /**
+     * @see com.opensymphony.workflow.Register#registerVariable(WorkflowContext, WorkflowEntry, Map)
+     */
+    public Object registerVariable(WorkflowContext context, WorkflowEntry entry, Map args) {
+        String workflowname = "unknown";
+        long workflow_id = -1;
+
+        if (entry != null) {
+            workflowname = entry.getWorkflowName();
+            workflow_id = entry.getId();
+        }
+
+        boolean groupByInstance = false;
+        String useInstance = (String) args.get("addInstanceId");
+
+        if (useInstance != null) {
+            groupByInstance = TextUtils.parseBoolean(useInstance);
+        }
+
+        String categoryName = "OSWorkflow";
+
+        if (args.get("Category") != null) {
+            categoryName = (String) args.get("Category");
+        }
+
+        String category = categoryName + "." + workflowname;
+
+        if (groupByInstance) {
+            category += ("." + (Long.toString(workflow_id)));
+        }
+
+        Log log = LogFactory.getLog(category);
+
+        return log;
+    }
+}