You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2003/10/10 18:42:14 UTC

cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting WorkflowInvokerAction.java

andreas     2003/10/10 09:42:14

  Modified:    src/java/org/apache/lenya/cms/workflow WorkflowFactory.java
                        CMSHistory.java WorkflowDocumentSet.java
               src/java/org/apache/lenya/cms/cocoon/transformation
                        WorkflowMenuTransformer.java
               src/java/org/apache/lenya/cms/ac2/workflow
                        WorkflowAuthorizer.java
               src/java/org/apache/lenya/cms/task WorkflowInvoker.java
               src/java/org/apache/lenya/cms/cocoon/acting
                        WorkflowInvokerAction.java
  Added:       src/java/org/apache/lenya/workflow
                        SynchronizedWorkflowInstances.java
               src/java/org/apache/lenya/workflow/impl
                        SynchronizedWorkflowInstancesImpl.java
  Removed:     src/java/org/apache/lenya/workflow/impl
                        SynchronizedWorkflowInstances.java
  Log:
  extracted interface from SynchronizedWorkflowInstances
  
  Revision  Changes    Path
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/SynchronizedWorkflowInstances.java
  
  Index: SynchronizedWorkflowInstances.java
  ===================================================================
  /*
  $Id: SynchronizedWorkflowInstances.java,v 1.1 2003/10/10 16:42:12 andreas Exp $
  <License>
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
   ware Foundation, please see <http://www.apache.org/>.
  
   Lenya includes software developed by the Apache Software Foundation, W3C,
   DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  </License>
  */
  package org.apache.lenya.workflow;
  
  
  /**
   * @author <a href="mailto:andreas@apache.org">Andreas Hartmann</a>
   */
  public interface SynchronizedWorkflowInstances {
      
      /**
       * Returns all executable events.
       * @see org.apache.lenya.workflow.WorkflowInstance#getExecutableEvents(org.apache.lenya.workflow.Situation)
       */
      Event[] getExecutableEvents(Situation situation) throws WorkflowException;
      
      /**
       * Invokes an event on all documents.
       * @see org.apache.lenya.workflow.WorkflowInstance#invoke(org.apache.lenya.workflow.Situation, org.apache.lenya.workflow.Event)
       */
      void invoke(Situation situation, Event event) throws WorkflowException;
  }
  
  
  1.25      +1 -2      cocoon-lenya/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java
  
  Index: WorkflowFactory.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- WorkflowFactory.java	2 Oct 2003 15:27:41 -0000	1.24
  +++ WorkflowFactory.java	10 Oct 2003 16:42:12 -0000	1.25
  @@ -72,7 +72,6 @@
   import org.apache.lenya.workflow.*;
   import org.apache.lenya.workflow.Workflow;
   import org.apache.lenya.workflow.impl.History;
  -import org.apache.lenya.workflow.impl.SynchronizedWorkflowInstances;
   import org.apache.lenya.workflow.impl.WorkflowBuilder;
   
   import java.io.File;
  
  
  
  1.20      +2 -2      cocoon-lenya/src/java/org/apache/lenya/cms/workflow/CMSHistory.java
  
  Index: CMSHistory.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/workflow/CMSHistory.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- CMSHistory.java	30 Sep 2003 14:45:50 -0000	1.19
  +++ CMSHistory.java	10 Oct 2003 16:42:12 -0000	1.20
  @@ -145,7 +145,7 @@
   
       /**
        * Returns the path of the history file inside the publication directory.
  -     * @param Document A CMS document.
  +     * @param document A CMS document.
        * @return A string.
        */
       public String getHistoryPath(Document document) {
  
  
  
  1.2       +12 -3     cocoon-lenya/src/java/org/apache/lenya/cms/workflow/WorkflowDocumentSet.java
  
  Index: WorkflowDocumentSet.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/workflow/WorkflowDocumentSet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WorkflowDocumentSet.java	2 Oct 2003 15:27:41 -0000	1.1
  +++ WorkflowDocumentSet.java	10 Oct 2003 16:42:12 -0000	1.2
  @@ -59,13 +59,22 @@
   import org.apache.lenya.cms.publication.DocumentSet;
   import org.apache.lenya.workflow.WorkflowException;
   import org.apache.lenya.workflow.WorkflowInstance;
  -import org.apache.lenya.workflow.impl.SynchronizedWorkflowInstances;
  +import org.apache.lenya.workflow.impl.SynchronizedWorkflowInstancesImpl;
   
   /**
  + * A synchronized workflow instance representing a set of documents.
  + * 
    * @author <a href="mailto:andreas@apache.org">Andreas Hartmann</a>
    */
  -public class WorkflowDocumentSet extends SynchronizedWorkflowInstances {
  +public class WorkflowDocumentSet extends SynchronizedWorkflowInstancesImpl {
   
  +    /**
  +     * Ctor.
  +     * @param documentSet The document set.
  +     * @param mainDocument The main document of the set, i.e. the document to
  +     * invoke the workflow on if the transition is not synchronized.
  +     * @throws WorkflowException when something went wrong.
  +     */
       public WorkflowDocumentSet(DocumentSet documentSet, Document mainDocument) throws WorkflowException {
           Document[] documents = documentSet.getDocuments();
           WorkflowInstance[] instances = new WorkflowInstance[documents.length];
  
  
  
  1.26      +2 -2      cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java
  
  Index: WorkflowMenuTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- WorkflowMenuTransformer.java	9 Oct 2003 22:34:25 -0000	1.25
  +++ WorkflowMenuTransformer.java	10 Oct 2003 16:42:13 -0000	1.26
  @@ -68,9 +68,9 @@
   import org.apache.lenya.cms.workflow.WorkflowFactory;
   import org.apache.lenya.workflow.Event;
   import org.apache.lenya.workflow.Situation;
  +import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
   import org.apache.lenya.workflow.Workflow;
   import org.apache.lenya.workflow.WorkflowException;
  -import org.apache.lenya.workflow.impl.SynchronizedWorkflowInstances;
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   import org.xml.sax.helpers.AttributesImpl;
  
  
  
  1.21      +2 -2      cocoon-lenya/src/java/org/apache/lenya/cms/ac2/workflow/WorkflowAuthorizer.java
  
  Index: WorkflowAuthorizer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac2/workflow/WorkflowAuthorizer.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- WorkflowAuthorizer.java	9 Oct 2003 22:34:25 -0000	1.20
  +++ WorkflowAuthorizer.java	10 Oct 2003 16:42:14 -0000	1.21
  @@ -70,7 +70,7 @@
   import org.apache.lenya.cms.workflow.WorkflowFactory;
   import org.apache.lenya.workflow.Event;
   import org.apache.lenya.workflow.Situation;
  -import org.apache.lenya.workflow.impl.SynchronizedWorkflowInstances;
  +import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
   
   /**
    * If the client requested invoking a workflow event, this authorizer checks if
  
  
  
  1.1                  cocoon-lenya/src/java/org/apache/lenya/workflow/impl/SynchronizedWorkflowInstancesImpl.java
  
  Index: SynchronizedWorkflowInstancesImpl.java
  ===================================================================
  /*
  $Id: SynchronizedWorkflowInstancesImpl.java,v 1.1 2003/10/10 16:42:14 andreas Exp $
  <License>
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Lenya" and  "Apache Software Foundation"  must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Michael Wechner <mi...@apache.org>. For more information on the Apache Soft-
   ware Foundation, please see <http://www.apache.org/>.
  
   Lenya includes software developed by the Apache Software Foundation, W3C,
   DOM4J Project, BitfluxEditor, Xopus, and WebSHPINX.
  </License>
  */
  package org.apache.lenya.workflow.impl;
  
  import java.util.Arrays;
  import java.util.HashSet;
  import java.util.Set;
  
  import org.apache.lenya.workflow.*;
  import org.apache.lenya.workflow.Event;
  import org.apache.lenya.workflow.Situation;
  import org.apache.lenya.workflow.State;
  import org.apache.lenya.workflow.WorkflowException;
  import org.apache.lenya.workflow.WorkflowInstance;
  import org.apache.log4j.Category;
  
  /**
   * An object of this class encapsulates a set of synchronized
   * workflow instances.
   * @author <a href="mailto:andreas@apache.org">Andreas Hartmann</a>
   */
  public class SynchronizedWorkflowInstancesImpl implements SynchronizedWorkflowInstances {
  
      private static final Category log = Category.getInstance(SynchronizedWorkflowInstancesImpl.class);
  
      /**
       * Ctor.
       */
      public SynchronizedWorkflowInstancesImpl() {
      }
  
      /**
       * Ctor.
       * @param instances The set of workflow instances to synchronize.
       * @param mainInstance The main workflow instance to invoke for non-synchronized transitions.
       */
      public SynchronizedWorkflowInstancesImpl(
          WorkflowInstance[] instances,
          WorkflowInstance mainInstance) {
          setInstances(instances);
          setMainInstance(mainInstance);
      }
  
      /**
       * Sets the main workflow instance.
       * @param mainInstance The main workflow instance to invoke for non-synchronized transitions.
       */
      public void setMainInstance(WorkflowInstance mainInstance) {
          this.mainInstance = mainInstance;
      }
  
      private WorkflowInstance[] instances;
      private WorkflowInstance mainInstance;
  
      public void setInstances(WorkflowInstance[] instances) {
          this.instances = instances;
      }
  
      public WorkflowInstance[] getInstances() {
          return instances;
      }
  
      /**
       * Returns all executable events.
       * @see org.apache.lenya.workflow.WorkflowInstance#getExecutableEvents(org.apache.lenya.workflow.Situation)
       */
      public Event[] getExecutableEvents(Situation situation) throws WorkflowException {
          if (log.isDebugEnabled()) {
              log.debug("Resolving executable events");
          }
  
          WorkflowInstance[] instances = getInstances();
          if (instances.length == 0) {
              throw new WorkflowException("The set must contain at least one workflow instance!");
          }
  
          Event[] events = mainInstance.getExecutableEvents(situation);
          Set executableEvents = new HashSet(Arrays.asList(events));
  
          for (int i = 0; i < events.length; i++) {
              Event event = events[i];
              if (mainInstance.isSynchronized(event)) {
  
                  boolean canFire = true;
                  if (log.isDebugEnabled()) {
                      log.debug("    Transition for event [" + event + "] is synchronized.");
                  }
  
                  boolean sameState = true;
                  State currentState = mainInstance.getCurrentState();
                  int j = 0;
                  while (j < instances.length && sameState) {
                      sameState = instances[j].getCurrentState().equals(currentState);
                      j++;
                  }
                  if (log.isDebugEnabled()) {
                      log.debug("    All instances are in the same state: [" + sameState + "]");
                  }
  
                  if (sameState) {
                      for (int k = 0; k < instances.length; k++) {
                          WorkflowInstanceImpl instance = (WorkflowInstanceImpl) instances[k];
                          if (instance != mainInstance && !instance.getNextTransition(event).canFire(situation, instance)) {
                              canFire = false;
                              if (log.isDebugEnabled()) {
                                  log.debug("    Workflow instance [" + instance + "] can not fire.");
                              }
                          }
                      }
                  } else {
                      canFire = false;
                  }
  
                  if (!canFire) {
                      executableEvents.remove(event);
                      if (log.isDebugEnabled()) {
                          log.debug("    Event [" + event + "] can not fire - removing from executable events.");
                      }
                  }
              }
          }
  
          if (log.isDebugEnabled()) {
              log.debug("    Resolving executable events completed.");
          }
  
          return (Event[]) executableEvents.toArray(new Event[executableEvents.size()]);
      }
  
      /**
       * Invokes an event on all documents.
       * @see org.apache.lenya.workflow.WorkflowInstance#invoke(org.apache.lenya.workflow.Situation, org.apache.lenya.workflow.Event)
       */
      public void invoke(Situation situation, Event event) throws WorkflowException {
          
          if (mainInstance.isSynchronized(event)) {
              for (int i = 0; i < instances.length; i++) {
                  instances[i].invoke(situation, event);
              }
          }
          else {
              mainInstance.invoke(situation, event);
          }
      }
  
  }
  
  
  
  1.5       +2 -2      cocoon-lenya/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java
  
  Index: WorkflowInvoker.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- WorkflowInvoker.java	9 Oct 2003 22:34:25 -0000	1.4
  +++ WorkflowInvoker.java	10 Oct 2003 16:42:14 -0000	1.5
  @@ -69,7 +69,7 @@
   import org.apache.lenya.util.NamespaceMap;
   import org.apache.lenya.workflow.Event;
   import org.apache.lenya.workflow.Situation;
  -import org.apache.lenya.workflow.impl.SynchronizedWorkflowInstances;
  +import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
   import org.apache.log4j.Category;
   
   /**
  
  
  
  1.4       +2 -2      cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java
  
  Index: WorkflowInvokerAction.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/acting/WorkflowInvokerAction.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- WorkflowInvokerAction.java	9 Oct 2003 22:34:25 -0000	1.3
  +++ WorkflowInvokerAction.java	10 Oct 2003 16:42:14 -0000	1.4
  @@ -70,7 +70,7 @@
   import org.apache.lenya.cms.workflow.WorkflowFactory;
   import org.apache.lenya.workflow.Event;
   import org.apache.lenya.workflow.Situation;
  -import org.apache.lenya.workflow.impl.SynchronizedWorkflowInstances;
  +import org.apache.lenya.workflow.SynchronizedWorkflowInstances;
   
   /**
    * Action to invoke a workflow transition independently from the request document URL.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org