Anonymous avatar Anonymous committed f6f4404

Initial import from SourceForge

Comments (0)

Files changed (4)

Add a comment to this file

lib/build/xdoclet/xdoclet-ejb-module-1.2b3.jar

Binary file added.

src/java/com/opensymphony/workflow/ejb/EJBWorkflow.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.ejb;
+
+import com.opensymphony.module.propertyset.PropertySet;
+
+import com.opensymphony.util.EJBUtils;
+
+import com.opensymphony.workflow.*;
+import com.opensymphony.workflow.loader.WorkflowDescriptor;
+import com.opensymphony.workflow.query.WorkflowQuery;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.rmi.RemoteException;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.CreateException;
+
+import javax.naming.NamingException;
+
+
+/**
+ * EJB based workflow class.
+ * This class acts as a wrapper around a workflow session bean.
+ *
+ * @author plightbo
+ * @version $Revision: 1.1.1.1 $
+ */
+public class EJBWorkflow implements Workflow {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(EJBWorkflow.class);
+
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private WorkflowRemote wf;
+
+    //~ Constructors ///////////////////////////////////////////////////////////
+
+    public EJBWorkflow(String location) throws CreateException, RemoteException, WorkflowException {
+        WorkflowHome home = null;
+
+        try {
+            home = (WorkflowHome) EJBUtils.lookup(location, WorkflowHome.class);
+        } catch (NamingException e) {
+            try {
+                home = (WorkflowHome) EJBUtils.lookup(WorkflowHomeFactory.COMP_NAME, WorkflowHome.class);
+            } catch (NamingException e1) {
+                try {
+                    home = (WorkflowHome) EJBUtils.lookup(WorkflowHomeFactory.JNDI_NAME, WorkflowHome.class);
+                } catch (NamingException e2) {
+                    throw new WorkflowException("Could not get a handle on the workflow Home EJB", e);
+                }
+            }
+        }
+
+        wf = home.create();
+    }
+
+    public EJBWorkflow() throws CreateException, RemoteException, WorkflowException {
+        this(WorkflowHomeFactory.JNDI_NAME);
+    }
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public int[] getAvailableActions(long id) throws WorkflowException {
+        try {
+            return wf.getAvailableActions(id);
+        } catch (RemoteException e) {
+            log.error("Error getting available actions", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public List getCurrentSteps(long id) throws WorkflowException {
+        try {
+            return wf.getCurrentSteps(id);
+        } catch (RemoteException e) {
+            log.error("Error getting current steps", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public List getHistorySteps(long id) throws WorkflowException {
+        try {
+            return wf.getHistorySteps(id);
+        } catch (RemoteException e) {
+            log.error("Error getting history steps", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public PropertySet getPropertySet(long id) throws WorkflowException {
+        try {
+            return wf.getPropertySet(id);
+        } catch (RemoteException e) {
+            log.error("Error getting PropertySet", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public List getSecurityPermissions(long id) throws WorkflowException {
+        try {
+            return wf.getSecurityPermissions(id);
+        } catch (RemoteException e) {
+            log.error("Error getting security permissions", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public WorkflowDescriptor getWorkflowDescriptor(String workflowName) throws WorkflowException {
+        try {
+            return wf.getWorkflowDescriptor(workflowName);
+        } catch (RemoteException e) {
+            log.error("Error getting descriptor", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public String getWorkflowName(long id) throws WorkflowException {
+        try {
+            return wf.getWorkflowName(id);
+        } catch (RemoteException e) {
+            log.error("Error getting workflow name", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public boolean canInitialize(String workflowName, int initialState) throws WorkflowException {
+        try {
+            return wf.canInitialize(workflowName, initialState);
+        } catch (RemoteException e) {
+            log.error("Error checking canInitialize", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public void doAction(long id, int actionId, Map inputs) throws InvalidInputException, WorkflowException {
+        try {
+            wf.doAction(id, actionId, inputs);
+        } catch (RemoteException e) {
+            log.error("Error performing action", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public void executeTriggerFunction(long id, int triggerId) throws WorkflowException {
+        try {
+            wf.executeTriggerFunction(id, triggerId);
+        } catch (RemoteException e) {
+            log.error("Error executing trigger", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public long initialize(String workflowName, int initialState, Map inputs) throws InvalidRoleException, InvalidInputException, WorkflowException {
+        try {
+            return wf.initialize(workflowName, initialState, inputs);
+        } catch (RemoteException e) {
+            log.error("Error initializing", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public List query(WorkflowQuery query) throws WorkflowException {
+        try {
+            return wf.query(query);
+        } catch (RemoteException e) {
+            log.error("Error querying", e);
+            throw new WorkflowException(e);
+        }
+    }
+
+    public boolean saveWorkflowDescriptor(String workflowName, WorkflowDescriptor descriptor, boolean replace) throws WorkflowException {
+        try {
+            return wf.saveWorkflowDescriptor(workflowName, descriptor, replace);
+        } catch (RemoteException e) {
+            log.error("Error saving workflow", e);
+            throw new WorkflowException(e);
+        }
+    }
+}

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

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.loader;
+
+import com.opensymphony.workflow.InvalidWorkflowDescriptorException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.xml.sax.*;
+
+import java.io.*;
+
+import java.net.URL;
+
+import javax.xml.parsers.*;
+
+
+/**
+ * The WorkflowLoader is responsible for creating a WorkflowDesciptor
+ * by loading the XML from various sources.
+ *
+ * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
+ * @version $Revision: 1.1.1.1 $
+ */
+public class WorkflowLoader {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(WorkflowLoader.class);
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public static WorkflowDescriptor load(final InputStream is) throws SAXException, IOException, InvalidWorkflowDescriptorException {
+        return load(is, null);
+    }
+
+    /**
+     * Load a workflow descriptor from a URL
+     */
+    public static WorkflowDescriptor load(final URL url) throws SAXException, IOException, InvalidWorkflowDescriptorException {
+        return load(url.openStream(), url);
+    }
+
+    private static WorkflowDescriptor load(InputStream is, URL url) throws SAXException, IOException, InvalidWorkflowDescriptorException {
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        dbf.setValidating(true);
+
+        DocumentBuilder db = null;
+
+        try {
+            db = dbf.newDocumentBuilder();
+            db.setEntityResolver(new EntityResolver() {
+                    public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
+                        if (systemId == null) {
+                            return null;
+                        }
+
+                        URL url = new URL(systemId);
+                        String file = url.getFile();
+
+                        if ((file != null) && (file.indexOf('/') > -1)) {
+                            file = file.substring(file.lastIndexOf('/') + 1);
+                        }
+
+                        if ("www.opensymphony.com".equals(url.getHost())) {
+                            InputStream workflowIs = getClass().getResourceAsStream("/META-INF/" + file);
+
+                            if (workflowIs == null) {
+                                workflowIs = getClass().getResourceAsStream("/" + file);
+                            }
+
+                            if (workflowIs == null) {
+                                log.info("Cannot find " + file + " locally");
+                            }
+
+                            if (workflowIs != null) {
+                                return new InputSource(workflowIs);
+                            }
+                        }
+
+                        return null;
+                    }
+                });
+        } catch (ParserConfigurationException e) {
+            log.fatal("Could not load workflow file", e);
+        }
+
+        db.setErrorHandler(new WorkflowErrorHandler(url));
+
+        Document doc = db.parse(is);
+
+        Element root = (Element) doc.getElementsByTagName("workflow").item(0);
+
+        WorkflowDescriptor descriptor = new WorkflowDescriptor(root);
+        descriptor.validate();
+
+        return descriptor;
+    }
+
+    //~ Inner Classes //////////////////////////////////////////////////////////
+
+    static class WorkflowErrorHandler implements ErrorHandler {
+        private URL url;
+
+        public WorkflowErrorHandler(final URL url) {
+            this.url = url;
+        }
+
+        public void error(SAXParseException exception) throws SAXException {
+            throw new SAXException(getMessage(exception));
+        }
+
+        public void fatalError(SAXParseException exception) throws SAXException {
+            throw new SAXException(getMessage(exception));
+        }
+
+        public void warning(SAXParseException exception) throws SAXException {
+            log.warn(getMessage(exception));
+        }
+
+        private String getMessage(SAXParseException exception) {
+            return exception.getMessage() + " (" + ((url != null) ? (" url=" + url + " ") : "") + "line:" + exception.getLineNumber() + ((exception.getColumnNumber() > -1) ? (" col:" + exception.getColumnNumber()) : "") + ")";
+        }
+    }
+}

src/java/com/opensymphony/workflow/spi/ejb/EJBWorkflowStore.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.spi.ejb;
+
+import com.opensymphony.module.propertyset.PropertySet;
+import com.opensymphony.module.propertyset.PropertySetManager;
+
+import com.opensymphony.workflow.StoreException;
+import com.opensymphony.workflow.query.WorkflowQuery;
+import com.opensymphony.workflow.spi.*;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.rmi.RemoteException;
+
+import java.util.*;
+
+import javax.naming.InitialContext;
+
+import javax.rmi.PortableRemoteObject;
+
+
+/**
+ * EJB entity bean workflow store implementation.
+ * <p>
+ *
+ * The following property is optional:
+ * <ul>
+ *  <li><b>property.store</b> - JNDI location for the OSCore EJBPropertySet PropertyStore (defaults to "ejb/propertyStore")</li>
+ *  <li><b>workflow.store</b> - JNDI location for the ejb workflow store session bean (defaults to @link{#WorkflowStoreHome.JNDI_NAME)</li>
+ * </ul>
+ *
+ * @author <a href="mailto:plightbo@hotmail.com">Pat Lightbody</a>
+ */
+public class EJBWorkflowStore implements WorkflowStore {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static final Log log = LogFactory.getLog(EJBWorkflowStore.class);
+
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    private WorkflowStoreRemote session;
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public PropertySet getPropertySet(long entryId) throws StoreException {
+        try {
+            HashMap args = new HashMap(2);
+            args.put("entityId", new Long(entryId));
+            args.put("entityName", "WorkflowEntry");
+
+            return PropertySetManager.getInstance("ejb", args);
+        } catch (Exception e) {
+            throw new StoreException("Could not retrieve PropertySet for #" + entryId, e);
+        }
+    }
+
+    public Step createCurrentStep(long entryId, int stepId, String owner, Date startDate, Date dueDate, String status, long[] previousIds) throws StoreException {
+        try {
+            return session.createCurrentStep(entryId, stepId, owner, startDate, dueDate, status, previousIds);
+        } catch (RemoteException ex) {
+            log.fatal("System error", ex);
+
+            return null;
+        }
+    }
+
+    public WorkflowEntry createEntry(String workflowName) throws StoreException {
+        try {
+            return session.createEntry(workflowName);
+        } catch (RemoteException ex) {
+            log.fatal("System error", ex);
+
+            return null;
+        }
+    }
+
+    public List findCurrentSteps(long entryId) throws StoreException {
+        try {
+            return session.findCurrentSteps(entryId);
+        } catch (RemoteException ex) {
+            log.fatal("System error", ex);
+
+            return null;
+        }
+    }
+
+    public WorkflowEntry findEntry(long entryId) throws StoreException {
+        try {
+            return session.findEntry(entryId);
+        } catch (RemoteException ex) {
+            log.fatal("System error", ex);
+
+            return null;
+        }
+    }
+
+    public List findHistorySteps(long entryId) throws StoreException {
+        try {
+            return session.findHistorySteps(entryId);
+        } catch (RemoteException ex) {
+            log.fatal("System error", ex);
+
+            return null;
+        }
+    }
+
+    public void init(Map props) {
+        String workflowSessionLocation = (String) props.get("workflow.store");
+
+        if (workflowSessionLocation == null) {
+            workflowSessionLocation = WorkflowStoreHomeFactory.JNDI_NAME;
+        }
+
+        try {
+            InitialContext context = new InitialContext();
+            session = ((WorkflowStoreHome) PortableRemoteObject.narrow(context.lookup(workflowSessionLocation), WorkflowStoreHome.class)).create();
+        } catch (Exception ex) {
+            log.error("Error looking up homes", ex);
+            throw new IllegalArgumentException(ex.toString());
+        }
+    }
+
+    public Step markFinished(Step step, int actionId, Date finishDate, String status, String caller) throws StoreException {
+        try {
+            return session.markFinished(step, actionId, finishDate, status, caller);
+        } catch (RemoteException ex) {
+            log.fatal("System error", ex);
+
+            return null;
+        }
+    }
+
+    public void moveToHistory(Step step) throws StoreException {
+        try {
+            session.moveToHistory(step);
+        } catch (RemoteException ex) {
+            log.fatal("System error", ex);
+        }
+    }
+
+    public List query(WorkflowQuery query) {
+        // not implemented
+        throw new UnsupportedOperationException("EJB store does not support queries");
+    }
+}
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.