Commits

Anonymous committed 7685252

Extract WorkflowFactory interface
Added classes from WF-375

Comments (0)

Files changed (15)

src/designer/com/opensymphony/workflow/config/WorkspaceManager.java

 import com.opensymphony.workflow.FactoryException;
 import com.opensymphony.workflow.designer.event.WorkspaceListener;
 import com.opensymphony.workflow.designer.event.WorkspaceEvent;
-import com.opensymphony.workflow.loader.AbstractWorkflowFactory;
 import com.opensymphony.workflow.loader.RemoteWorkspace;
+import com.opensymphony.workflow.loader.WorkflowFactory;
 import com.opensymphony.workflow.designer.DesignerService;
 
 /**
 public class WorkspaceManager
 {
   //private Workspace currentWorkspace = null;
-  private AbstractWorkflowFactory currentWorkspace = null;
+  private WorkflowFactory currentWorkspace = null;
   private Collection listeners;
 
   public void loadWorkspace(URL url) throws FactoryException, IOException
     }
   }
 
-  public void setCurrentWorkspace(AbstractWorkflowFactory current)
+  public void setCurrentWorkspace(WorkflowFactory current)
   {
     saveWorkspace();
     if(this.currentWorkspace!=null)
     }
   }
 
-  public AbstractWorkflowFactory getCurrentWorkspace()
+  public WorkflowFactory getCurrentWorkspace()
   {
     return currentWorkspace;
   }

src/designer/com/opensymphony/workflow/designer/WorkflowDesigner.java

   public void createGraph(String workflowName)
   {
     //Workspace currentWorkspace = manager.getCurrentWorkspace();
-    AbstractWorkflowFactory currentWorkspace = manager.getCurrentWorkspace();
+    WorkflowFactory currentWorkspace = manager.getCurrentWorkspace();
     Layout layout = (Layout)currentWorkspace.getLayout(workflowName);
     WorkflowGraphModel model = new WorkflowGraphModel(layout);
     model.setPalette(palette);
         graphTabs.removeAll();
         Prefs.INSTANCE.put(Prefs.LAST_WORKSPACE, file.toString());
         manager.loadWorkspace(file);
-        AbstractWorkflowFactory workspace = manager.getCurrentWorkspace();
+        WorkflowFactory workspace = manager.getCurrentWorkspace();
         navigator.setWorkspace(workspace);
         String[] workflows = workspace.getWorkflowNames();
         for(int i = 0; i < workflows.length; i++)

src/designer/com/opensymphony/workflow/designer/WorkspaceNavigator.java

   private WorkflowDesigner designer;
   private DefaultMutableTreeNode rootNode;
   private String currentWorkflow;
-  private AbstractWorkflowFactory currentWorkspace = null;
+  private WorkflowFactory currentWorkspace = null;
 	private DefaultTreeCellRenderer  cellRenderer = new WorkspaceCellRenderer();
   
   private JPopupMenu popup;
     currentWorkflow = newValue;
   }
 
-  public void setWorkspace(AbstractWorkflowFactory workspace)
+  public void setWorkspace(WorkflowFactory workspace)
   {
     removeChildNodes(rootNode);
     ((DefaultTreeModel)getModel()).reload();

src/designer/com/opensymphony/workflow/designer/actions/ImportWorkflow.java

 import com.opensymphony.workflow.designer.Utils;
 import com.opensymphony.workflow.designer.swing.status.StatusDisplay;
 import com.opensymphony.workflow.designer.dialogs.ImportWorkflowDialog;
-import com.opensymphony.workflow.loader.AbstractWorkflowFactory;
 import com.opensymphony.workflow.loader.Workspace;
+import com.opensymphony.workflow.loader.WorkflowFactory;
 import com.opensymphony.workflow.FactoryException;
 import foxtrot.Worker;
 import foxtrot.Task;
 public class ImportWorkflow extends AbstractAction implements WorkspaceListener
 {
   //private Workspace currentWorkspace;
-  private AbstractWorkflowFactory currentWorkspace;
+  private WorkflowFactory currentWorkspace;
 
   public ImportWorkflow()
   {

src/designer/com/opensymphony/workflow/designer/actions/NewWorkflow.java

 import com.opensymphony.workflow.designer.event.WorkspaceEvent;
 import com.opensymphony.workflow.designer.WorkflowDesigner;
 import com.opensymphony.workflow.designer.ResourceManager;
-import com.opensymphony.workflow.loader.AbstractWorkflowFactory;
+import com.opensymphony.workflow.loader.WorkflowFactory;
 import com.opensymphony.workflow.FactoryException;
 
 /**
 public class NewWorkflow extends AbstractAction implements WorkspaceListener
 {
   //private Workspace currentWorkspace;
-  private AbstractWorkflowFactory currentWorkspace;
+  private WorkflowFactory currentWorkspace;
 
   public NewWorkflow()
   {

src/designer/com/opensymphony/workflow/designer/actions/SaveWorkspace.java

 import com.opensymphony.workflow.designer.event.WorkspaceEvent;
 import com.opensymphony.workflow.designer.*;
 import com.opensymphony.workflow.loader.Workspace;
-import com.opensymphony.workflow.loader.AbstractWorkflowFactory;
+import com.opensymphony.workflow.loader.WorkflowFactory;
 
 /**
  * @author Hani Suleiman (hani@formicary.net)
 public class SaveWorkspace extends AbstractAction implements WorkspaceListener
 {
   //private Workspace currentWorkspace;
-  private AbstractWorkflowFactory currentWorkspace;
+  private WorkflowFactory currentWorkspace;
 
   public SaveWorkspace()
   {

src/designer/com/opensymphony/workflow/designer/actions/ValidateWorkflow.java

 
 import com.opensymphony.workflow.designer.event.WorkspaceListener;
 import com.opensymphony.workflow.designer.event.WorkspaceEvent;
-import com.opensymphony.workflow.loader.AbstractWorkflowFactory;
+import com.opensymphony.workflow.loader.WorkflowFactory;
 import com.opensymphony.workflow.designer.WorkflowDesigner;
 
 /**
  */
 public class ValidateWorkflow extends AbstractAction implements WorkspaceListener
 {
-	private AbstractWorkflowFactory currentWorkspace;
+	private WorkflowFactory currentWorkspace;
 	
 	public ValidateWorkflow()
 	{

src/designer/com/opensymphony/workflow/designer/event/WorkspaceEvent.java

 
 import java.util.EventObject;
 
-import com.opensymphony.workflow.loader.AbstractWorkflowFactory;
+import com.opensymphony.workflow.loader.WorkflowFactory;
 
 /**
  * @author Hani Suleiman (hani@formicary.net)
   public static final int WORKSPACE_OPENED = 1;
   public static final int WORKSPACE_CLOSED = 2;
   private int id;
-  private AbstractWorkflowFactory workspace;
+  private WorkflowFactory workspace;
   private boolean consumed;
 
   public WorkspaceEvent(Object source)
     super(source);
   }
 
-  public WorkspaceEvent(Object source, AbstractWorkflowFactory workspace, int id)
+  public WorkspaceEvent(Object source, WorkflowFactory workspace, int id)
   {
     super(source);
     this.id = id;
     return id;
   }
 
-  public AbstractWorkflowFactory getWorkspace()
+  public WorkflowFactory getWorkspace()
   {
     return workspace;
   }

src/java/com/opensymphony/workflow/config/DefaultConfiguration.java

  * rather than in the calling client.
  *
  * @author Hani Suleiman
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
  */
 public class DefaultConfiguration implements Configuration, Serializable {
     //~ Static fields/initializers /////////////////////////////////////////////
 
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    private AbstractWorkflowFactory factory = new URLWorkflowFactory();
     private Map persistenceArgs = new HashMap();
     private String persistenceClass;
+    private WorkflowFactory factory = new URLWorkflowFactory();
     private transient WorkflowStore store = null;
     private boolean initialized;
 
                         throw new FactoryException("factory does not specify a class attribute");
                     }
 
-                    factory = (AbstractWorkflowFactory) ClassLoaderUtil.loadClass(clazz, getClass()).newInstance();
+                    factory = (WorkflowFactory) ClassLoaderUtil.loadClass(clazz, getClass()).newInstance();
 
                     Properties properties = new Properties();
                     List props = XMLUtil.getChildElements(factoryElement, "property");
      * Get the workflow factory for this configuration.
      * This method should never ever be called from client code!
      */
-    AbstractWorkflowFactory getFactory() {
+    WorkflowFactory getFactory() {
         return factory;
     }
 }

src/java/com/opensymphony/workflow/config/SpringConfiguration.java

 
 import com.opensymphony.workflow.FactoryException;
 import com.opensymphony.workflow.StoreException;
-import com.opensymphony.workflow.loader.AbstractWorkflowFactory;
 import com.opensymphony.workflow.loader.WorkflowDescriptor;
+import com.opensymphony.workflow.loader.WorkflowFactory;
 import com.opensymphony.workflow.spi.WorkflowStore;
 
 import java.net.URL;
 /**
  * @author        Quake Wang
  * @since        2004-5-2
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  *
  **/
 public class SpringConfiguration implements Configuration {
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    private AbstractWorkflowFactory factory;
+    private WorkflowFactory factory;
     private WorkflowStore store;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public void setFactory(AbstractWorkflowFactory factory) {
+    public void setFactory(WorkflowFactory factory) {
         this.factory = factory;
     }
 

src/java/com/opensymphony/workflow/config/WorkflowFactoryServlet.java

 package com.opensymphony.workflow.config;
 
 import com.opensymphony.workflow.FactoryException;
-import com.opensymphony.workflow.loader.AbstractWorkflowFactory;
-import com.opensymphony.workflow.loader.WorkflowDescriptor;
-import com.opensymphony.workflow.loader.WorkflowLoader;
+import com.opensymphony.workflow.loader.*;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 public class WorkflowFactoryServlet extends HttpServlet {
     //~ Instance fields ////////////////////////////////////////////////////////
 
-    private AbstractWorkflowFactory factory;
+    private WorkflowFactory factory;
 
     //~ Methods ////////////////////////////////////////////////////////////////
 

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

  * Date: May 10, 2002
  * Time: 11:17:06 AM
  */
-public abstract class AbstractWorkflowFactory {
+public abstract class AbstractWorkflowFactory implements WorkflowFactory {
     //~ Instance fields ////////////////////////////////////////////////////////
 
     protected Properties properties = new Properties();
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
-    public abstract void setLayout(String workflowName, Object layout);
-
-    public abstract Object getLayout(String workflowName);
-
-    public abstract boolean isModifiable(String name);
-
-    public abstract String getName();
-
     /**
-     * Get the configuration properties of this factory
-     */
+       * Get the configuration properties of this factory
+       */
     public Properties getProperties() {
         return properties;
     }
     }
 
     /**
-     * Get a workflow descriptor given a workflow name.
-     * @param name The name of the workflow to get.
-     * @return The descriptor for the specified workflow.
-     * @throws FactoryException if the specified workflow name does not exist or cannot be located.
-     */
-    public abstract WorkflowDescriptor getWorkflow(String name, boolean validate) throws FactoryException;
-
-    /**
-     * Get all workflow names in the current factory
-     * @return An array of all workflow names
-     * @throws FactoryException if the factory cannot determine the names of the workflows it has.
-     */
-    public abstract String[] getWorkflowNames() throws FactoryException;
-
-    public abstract void createWorkflow(String name);
-
-    public abstract boolean removeWorkflow(String name) throws FactoryException;
-
-    public abstract void renameWorkflow(String oldName, String newName);
-
-    public abstract void save();
-
-    /**
-     * Save the workflow.
-     * Is it the responsibility of the caller to ensure that the workflow is valid,
-     * through the {@link WorkflowDescriptor#validate()} method. Invalid workflows will
-     * be saved without being checked.
-     * @param name The name of the workflow to same.
-     * @param descriptor The descriptor for the workflow.
-     * @param replace true if an existing workflow with this name should be replaced.
-     * @return true if the workflow was saved.
-     * @throws FactoryException if there was an error saving the workflow
-     * @throws com.opensymphony.workflow.InvalidWorkflowDescriptorException if the descriptor specified is invalid
-     */
-    public abstract boolean saveWorkflow(String name, WorkflowDescriptor descriptor, boolean replace) throws FactoryException;
-
-    /**
-     * Invoked after the properties of the factory have been set.
-     * Subclasses should override this method and add any specific
-     * setup code required. For example, connecting to an external resource
-     * or database.
-     * @throws FactoryException if there was an error during initialization.
-     */
+       * Invoked after the properties of the factory have been set.
+       * Subclasses should override this method and add any specific
+       * setup code required. For example, connecting to an external resource
+       * or database.
+       * @throws FactoryException if there was an error during initialization.
+       */
     public void initDone() throws FactoryException {
     }
 }

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

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.loader;
+
+import com.opensymphony.workflow.FactoryException;
+
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+import java.util.Properties;
+
+
+/**
+ * Spring-compliant implementation of {@link AbstractWorkflowFactory}. This
+ * workflow factory retrieves {@link WorkflowDescriptor}s from the Spring's
+ * {@link ApplicationContext}. The name of the WorkflowDescriptors is the name
+ * of the bean in the applicationContext. <br />
+ * Motivation: reduce number of external configuration files leaving only
+ * workflow definitions files. <br />
+ * <ul>
+ * <li>SpringConfiguration replaces osworkflow.xml</li>
+ * <li>WorkflowFactoryImpl replaces workflows.xml</li>
+ * </ul>
+ * Usage:
+ * <pre>
+ * &lt;bean id=&quot;myworkflow&quot; class=&quot;com.opensymphony.workflow.loader.WorkflowDescriptorFactoryBean&quot;&gt;
+ *     &lt;property name=&quot;descriptorResource&quot;&gt;
+ *         &lt;value&gt;classpath:/META-INF/workflow/myworkflow.xml&lt;/value&gt;
+ *     &lt;/property&gt;
+ * &lt;/bean&gt;
+ *
+ * &lt;bean id=&quot;workflowFactory&quot; class=&quot;com.opensymphony.workflow.loader.BeanNameWorkflowFactory&quot;/&gt;
+ * </pre>
+ *
+ * @author xd
+ */
+public class SpringBeanNameWorkflowFactory implements WorkflowFactory, ApplicationContextAware {
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    //////////////////////////////////////////////////~ Instance attributes. //
+
+    /** The applicationContext. */
+    private ApplicationContext applicationContext;
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public void setApplicationContext(final ApplicationContext inApplicationContext) {
+        this.applicationContext = inApplicationContext;
+    }
+
+    public void setLayout(String workflowName, Object layout) {
+    }
+
+    public Object getLayout(String workflowName) {
+        return null;
+    }
+
+    public boolean isModifiable(String name) {
+        return false;
+    }
+
+    public String getName() {
+        return null;
+    }
+
+    public Properties getProperties() {
+        return null;
+    }
+
+    //////////////////////////~ AbstractWorkflowFactory implemented methods. //
+    public WorkflowDescriptor getWorkflow(final String inName) {
+        return (WorkflowDescriptor) this.applicationContext.getBean(inName);
+    }
+
+    public WorkflowDescriptor getWorkflow(String name, boolean validate) throws FactoryException {
+        return getWorkflow(name);
+    }
+
+    public String[] getWorkflowNames() {
+        return this.applicationContext.getBeanDefinitionNames(WorkflowDescriptor.class);
+    }
+
+    public void createWorkflow(String name) {
+    }
+
+    public void init(Properties p) {
+    }
+
+    public void initDone() throws FactoryException {
+    }
+
+    public boolean removeWorkflow(final String inName) throws FactoryException {
+        throw new FactoryException("Unsupported operation.");
+    }
+
+    public void renameWorkflow(String oldName, String newName) {
+    }
+
+    public void save() {
+    }
+
+    public boolean saveWorkflow(final String inName, final WorkflowDescriptor inDescriptor, final boolean inReplace) throws FactoryException {
+        throw new FactoryException("Unsupported operation.");
+    }
+}

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

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.loader;
+
+import com.opensymphony.workflow.InvalidWorkflowDescriptorException;
+
+import org.springframework.beans.factory.FactoryBean;
+
+import org.springframework.core.io.Resource;
+
+import org.xml.sax.SAXException;
+
+import java.io.IOException;
+
+
+/**
+ * DOCUMENT ME!
+ *
+ * @author $author$
+ * @version $Revision: 1.1 $
+ */
+public class SpringWorkflowDescriptorFactory implements FactoryBean {
+    //~ Instance fields ////////////////////////////////////////////////////////
+
+    /** The descriptor resource. */
+    private Resource descriptorResource;
+
+    /** Should the descriptor be reloaded on each call. */
+    private boolean reload;
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public final void setDescriptorResource(final Resource inDescriptorResource) {
+        this.descriptorResource = inDescriptorResource;
+    }
+
+    public Object getObject() throws InvalidWorkflowDescriptorException, SAXException, IOException {
+        return WorkflowLoader.load(this.descriptorResource.getInputStream(), false);
+    }
+
+    public Class getObjectType() {
+        return WorkflowDescriptor.class;
+    }
+
+    public final void setReload(final boolean inReload) {
+        this.reload = inReload;
+    }
+
+    public boolean isSingleton() {
+        return !this.reload;
+    }
+}

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

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.workflow.loader;
+
+import com.opensymphony.workflow.FactoryException;
+
+import java.util.Properties;
+
+
+/**
+ * @author hani Date: Feb 15, 2005 Time: 11:18:48 PM
+ */
+public interface WorkflowFactory {
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    void setLayout(String workflowName, Object layout);
+
+    Object getLayout(String workflowName);
+
+    boolean isModifiable(String name);
+
+    String getName();
+
+    Properties getProperties();
+
+    WorkflowDescriptor getWorkflow(String name) throws FactoryException;
+
+    /**
+     * Get a workflow descriptor given a workflow name.
+     * @param name The name of the workflow to get.
+     * @return The descriptor for the specified workflow.
+     * @throws com.opensymphony.workflow.FactoryException if the specified workflow name does not exist or cannot be located.
+     */
+    WorkflowDescriptor getWorkflow(String name, boolean validate) throws FactoryException;
+
+    /**
+       * Get all workflow names in the current factory
+       * @return An array of all workflow names
+       * @throws com.opensymphony.workflow.FactoryException if the factory cannot determine the names of the workflows it has.
+       */
+    String[] getWorkflowNames() throws FactoryException;
+
+    void createWorkflow(String name);
+
+    void init(Properties p);
+
+    void initDone() throws FactoryException;
+
+    boolean removeWorkflow(String name) throws FactoryException;
+
+    void renameWorkflow(String oldName, String newName);
+
+    void save();
+
+    /**
+       * Save the workflow.
+       * Is it the responsibility of the caller to ensure that the workflow is valid,
+       * through the {@link WorkflowDescriptor#validate()} method. Invalid workflows will
+       * be saved without being checked.
+       * @param name The name of the workflow to same.
+       * @param descriptor The descriptor for the workflow.
+       * @param replace true if an existing workflow with this name should be replaced.
+       * @return true if the workflow was saved.
+       * @throws com.opensymphony.workflow.FactoryException if there was an error saving the workflow
+       * @throws com.opensymphony.workflow.InvalidWorkflowDescriptorException if the descriptor specified is invalid
+       */
+    boolean saveWorkflow(String name, WorkflowDescriptor descriptor, boolean replace) throws FactoryException;
+}