craigmcc    01/09/03 12:13:30

  Modified:    workflow/src/java/org/apache/commons/workflow/base
                        BaseStep.java
               workflow/src/java/org/apache/commons/workflow/core
                        GotoStep.java
  Added:       workflow/src/java/org/apache/commons/workflow/web
                        GotoStep.java
  Log:
  Add a "go to" step for web implementations that takes the new step
  identifier from a specified request parameter.  This makes it easy for
  navigation hyperlinks to include the destination step identifier on the
  query string.
  
  Revision  Changes    Path
  1.2       +26 -4     
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseStep.java
  
  Index: BaseStep.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseStep.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseStep.java     2001/08/13 21:16:01     1.1
  +++ BaseStep.java     2001/09/03 19:13:30     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseStep.java,v
 1.1 2001/08/13 21:16:01 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/08/13 21:16:01 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseStep.java,v
 1.2 2001/09/03 19:13:30 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/09/03 19:13:30 $
    *
    * ====================================================================
    * 
  @@ -74,7 +74,7 @@
    * relationships of Steps to each other, and to their owning Activity, but
    * requires the implementation to provide an <code>execute()</code> method.
    *
  - * @version $Revision: 1.1 $ $Date: 2001/08/13 21:16:01 $
  + * @version $Revision: 1.2 $ $Date: 2001/09/03 19:13:30 $
    * @author Craig R. McClanahan
    */
   
  @@ -213,6 +213,28 @@
        * @exception StepException if a processing error has occurred
        */
       public abstract void execute(Context context) throws StepException;
  +
  +
  +    // ------------------------------------------------------ Protected Methods
  +
  +
  +    /**
  +     * Return the identified Step from our current Activity, if it exists.
  +     * Otherwise, return <code>null</code>.
  +     *
  +     * @param id Identifier of the desired Step
  +     */
  +    protected Step findStep(String id) {
  +
  +        Step current = getActivity().getFirstStep();
  +        while (current != null) {
  +            if (id.equals(current.getId()))
  +                return (current);
  +            current = current.getNextStep();
  +        }
  +        return (null);
  +
  +    }
   
   
   }
  
  
  
  1.4       +4 -26     
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/core/GotoStep.java
  
  Index: GotoStep.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/core/GotoStep.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- GotoStep.java     2001/08/26 03:38:11     1.3
  +++ GotoStep.java     2001/09/03 19:13:30     1.4
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/core/GotoStep.java,v
 1.3 2001/08/26 03:38:11 craigmcc Exp $
  - * $Revision: 1.3 $
  - * $Date: 2001/08/26 03:38:11 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/core/GotoStep.java,v
 1.4 2001/09/03 19:13:30 craigmcc Exp $
  + * $Revision: 1.4 $
  + * $Date: 2001/09/03 19:13:30 $
    *
    * ====================================================================
    * 
  @@ -78,7 +78,7 @@
    *     should be transferred.</li>
    * </ul>
    *
  - * @version $Revision: 1.3 $ $Date: 2001/08/26 03:38:11 $
  + * @version $Revision: 1.4 $ $Date: 2001/09/03 19:13:30 $
    * @author Craig R. McClanahan
    */
   
  @@ -162,28 +162,6 @@
   
           // Tell our Context to transfer control
           context.setNextStep(next);
  -
  -    }
  -
  -
  -    // ------------------------------------------------------ Protected Methods
  -
  -
  -    /**
  -     * Return the identified Step from our current Activity, if it exists.
  -     * Otherwise, return <code>null</code>.
  -     *
  -     * @param id Identifier of the desired Step
  -     */
  -    protected Step findStep(String id) {
  -
  -        Step current = getActivity().getFirstStep();
  -        while (current != null) {
  -            if (id.equals(current.getId()))
  -                return (current);
  -            current = current.getNextStep();
  -        }
  -        return (null);
   
       }
   
  
  
  
  1.1                  
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/web/GotoStep.java
  
  Index: GotoStep.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/web/GotoStep.java,v
 1.1 2001/09/03 19:13:30 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2001/09/03 19:13:30 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, 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 acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", 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 [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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 (INCLUDING, 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.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  package org.apache.commons.workflow.web;
  
  
  import java.io.IOException;
  import java.util.EmptyStackException;
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import org.apache.commons.workflow.Context;
  import org.apache.commons.workflow.Step;
  import org.apache.commons.workflow.StepException;
  import org.apache.commons.workflow.base.BaseStep;
  
  
  /**
   * <p>Unconditionally transfer control to the step that is identified by
   * a request parameter with the specified name.</p>
   *
   * <p>Supported Attributes:</p>
   * <ul>
   * <li><strong>step</strong> - Name of a request parameter, included on the
   *     current request, that contains the identifier of the Step (within the
   *     current Activity) to which control should be transferred.  If not
   *     specified, a request parameter named <code>step</code> is used.</li>
   * </ul>
   *
   * @version $Revision: 1.1 $ $Date: 2001/09/03 19:13:30 $
   * @author Craig R. McClanahan
   */
  
  public class GotoStep extends BaseStep {
  
  
      // ----------------------------------------------------------= Constructors
  
  
      /**
       * Construct a default instance of this Step.
       */
      public GotoStep() {
  
          super();
  
      }
  
  
      /**
       * Construct an instance of this Step with the specified identifier.
       *
       * @param id Step identifier
       */
      public GotoStep(String id) {
  
          super();
          setId(id);
  
      }
  
  
      /**
       * Construct a fully configured instance of this Step.
       *
       * @param id Step identifier
       * @param step Request parameter name containing our step identifier
       */
      public GotoStep(String id, String step) {
  
          super();
          setId(id);
          setStep(step);
  
      }
  
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The request parameter containing the identifier of the Step to which
       * control should be transferred.
       */
      protected String step = "step";
  
      public String getStep() {
          return (this.step);
      }
  
      public void setStep(String step) {
          this.step = step;
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Perform the executable actions related to this Step, in the context of
       * the specified Context.
       *
       * @param context The Context that is tracking our execution state
       *
       * @exception StepException if a processing error has occurred
       */
      public void execute(Context context) throws StepException {
  
          // Make sure our executing Context is a WebContext
          if (!(context instanceof WebContext))
              throw new StepException("Execution context is not a WebContext",
                                      this);
          WebContext webContext = (WebContext) context;
  
          // Locate the step identifier to which we will transfer control
          ServletRequest request = webContext.getServletRequest();
          String id = request.getParameter(step);
          if (id == null)
              throw new StepException("No request parameter '" + step + "'",
                                      this);
  
  
          // Locate the step to which we will transfer control
          Step next = findStep(id);
          if (next == null)
              throw new StepException("Cannot find step '" + id + "'", this);
  
          // Tell our Context to transfer control
          context.setNextStep(next);
  
      }
  
  
  }
  
  
  

Reply via email to