craigmcc    01/08/18 14:06:50

  Modified:    workflow/src/java/org/apache/commons/workflow Context.java
                        ScopeEvent.java
               workflow/src/java/org/apache/commons/workflow/base
                        BaseContext.java
  Added:       workflow/src/java/org/apache/commons/workflow
                        ContextEvent.java ContextListener.java
               workflow/src/java/org/apache/commons/workflow/util
                        ContextSupport.java
  Log:
  Add event and listener support to the execute() method of BaseContext.
  This allows applications to do things like recording Step execution, or
  debugging of the Steps associated with an Activity.
  
  Revision  Changes    Path
  1.3       +25 -4     
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/Context.java
  
  Index: Context.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/Context.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Context.java      2001/08/17 05:15:48     1.2
  +++ Context.java      2001/08/18 21:06:50     1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/Context.java,v
 1.2 2001/08/17 05:15:48 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/08/17 05:15:48 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/Context.java,v
 1.3 2001/08/18 21:06:50 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/08/18 21:06:50 $
    *
    * ====================================================================
    * 
  @@ -87,7 +87,7 @@
    * the Step implementations that are executed to maintain the stack's
    * integrity.</p>
    *
  - * @version $Revision: 1.2 $ $Date: 2001/08/17 05:15:48 $
  + * @version $Revision: 1.3 $ $Date: 2001/08/18 21:06:50 $
    * @author Craig R. McClanahan
    */
   
  @@ -382,6 +382,27 @@
        * @param suspend The new suspend flag
        */
       public void setSuspend(boolean suspend);
  +
  +
  +    // ------------------------------------------------- Event Listener Methods
  +
  +
  +    /**
  +     * Add a listener that is notified each time beans are added,
  +     * replaced, or removed in this context.
  +     *
  +     * @param listener The ContextListener to be added
  +     */
  +    public void addContextListener(ContextListener listener);
  +
  +
  +    /**
  +     * Remove a listener that is notified each time beans are added,
  +     * replaced, or removed in this context.
  +     *
  +     * @param listener The ContextListener to be removed
  +     */
  +    public void removeContextListener(ContextListener listener);
   
   
   }
  
  
  
  1.2       +5 -5      
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/ScopeEvent.java
  
  Index: ScopeEvent.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/ScopeEvent.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ScopeEvent.java   2001/08/13 21:15:03     1.1
  +++ ScopeEvent.java   2001/08/18 21:06:50     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/ScopeEvent.java,v
 1.1 2001/08/13 21:15:03 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/08/13 21:15:03 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/ScopeEvent.java,v
 1.2 2001/08/18 21:06:50 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/08/18 21:06:50 $
    *
    * ====================================================================
    * 
  @@ -66,11 +66,11 @@
   
   
   /**
  - * A <stong>ScopeEvent</scope> provides notification to a
  + * A <strong>ScopeEvent</strong> provides notification to a
    * <code>ScopeListener</code> that a specified event has occurred for
    * the specified scope.
    *
  - * @version $Revision: 1.1 $ $Date: 2001/08/13 21:15:03 $
  + * @version $Revision: 1.2 $ $Date: 2001/08/18 21:06:50 $
    * @author Craig R. McClanahan
    */
   
  
  
  
  1.1                  
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/ContextEvent.java
  
  Index: ContextEvent.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/ContextEvent.java,v
 1.1 2001/08/18 21:06:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2001/08/18 21:06:50 $
   *
   * ====================================================================
   * 
   * 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;
  
  
  import java.util.EventObject;
  
  
  /**
   * A <strong>ContextEvent</strong> provides notification to a
   * <code>ContextListener</code> that a specified event has occurred for
   * the specified context.
   *
   * @version $Revision: 1.1 $ $Date: 2001/08/18 21:06:50 $
   * @author Craig R. McClanahan
   */
  
  public class ContextEvent extends EventObject {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a new immutable ContextEvent.
       *
       * @param context Context in which this event occurred
       */
      public ContextEvent(Context context) {
  
          this(context, null, null);
  
      }
          
  
      /**
       * Construct a new immutable ContextEvent.
       *
       * @param context Context upon which this event occurred
       * @param step Step this event is associated with (if any)
       */
      public ContextEvent(Context context, Step step) {
  
          this(context, step, null);
  
      }
  
  
      /**
       * Construct a new immutable ContextEvent.
       *
       *
       * @param context Context upon which this event occurred
       * @param step Step this event is associated with (if any)
       * @param exception StepException that was thrown
       *  (<code>afterStep()</code> and <code>afterActivity()</code> only)
       */
      public ContextEvent(Context context, Step step, StepException exception) {
  
          super(context);
          this.context = context;
          this.step = step;
          this.exception = exception;
  
      }
          
  
      // ------------------------------------------------------------- Properties
  
  
      /**
       * The <code>Context</code> upon which this event occurred.
       */
      protected Context context = null;
  
      public Context getContext() {
  
          return (this.context);
  
      }
  
  
      /**
       * The <code>StepException</code> that caused this event.
       */
      protected StepException exception = null;
  
      public StepException getException() {
  
          return (this.exception);
  
      }
  
  
      /**
       * The <code>Step</code> upon which this event occurred.  For
       * <code>beanReplaced</code> events, this will be the previous step.
       */
      protected Step step = null;
  
      public Step getStep() {
  
          return (this.step);
  
      }
  
  
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/ContextListener.java
  
  Index: ContextListener.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/ContextListener.java,v
 1.1 2001/08/18 21:06:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2001/08/18 21:06:50 $
   *
   * ====================================================================
   * 
   * 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;
  
  
  import java.util.EventListener;
  
  
  /**
   * A <strong>ContextListener</strong> registers its interest in receiving
   * <code>ContextEvent</code> notifications when the occur on a particular
   * <code>Context</code> of interest.
   *
   * @version $Revision: 1.1 $ $Date: 2001/08/18 21:06:50 $
   * @author Craig R. McClanahan
   */
  
  public interface ContextListener extends EventListener {
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Invoked immediately after execution of the related Activity has
       * been completed normally, been suspended, or been aborted by
       * the throwing of a StepException.  The Step included in this event
       * will be the last one to be executed.
       *
       * @param event The <code>ContextEvent</code> that has occurred
       */
      public void afterActivity(ContextEvent event);
  
  
  
      /**
       * Invoked immediately after the specified Step was executed.
       *
       * @param event The <code>ContextEvent</code> that has occurred
       */
      public void afterStep(ContextEvent event);
  
  
      /**
       * Invoked immediately before execution of the related Activity has
       * started.  The Step included in this event will be the first one
       * to be executed.
       *
       * @param event The <code>ContextEvent</code> that has occurred
       */
      public void beforeActivity(ContextEvent event);
  
  
      /**
       * Invoked immediately before the specified Step is executed.
       *
       * @param event The <code>ContextEvent</code> that has occurred
       */
      public void beforeStep(ContextEvent event);
  
  
  }
  
  
  
  1.3       +68 -6     
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContext.java
  
  Index: BaseContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContext.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BaseContext.java  2001/08/17 05:15:48     1.2
  +++ BaseContext.java  2001/08/18 21:06:50     1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContext.java,v
 1.2 2001/08/17 05:15:48 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/08/17 05:15:48 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContext.java,v
 1.3 2001/08/18 21:06:50 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/08/18 21:06:50 $
    *
    * ====================================================================
    * 
  @@ -66,9 +66,12 @@
   import org.apache.commons.collections.ArrayStack;
   import org.apache.commons.workflow.Activity;
   import org.apache.commons.workflow.Context;
  +import org.apache.commons.workflow.ContextEvent;
  +import org.apache.commons.workflow.ContextListener;
   import org.apache.commons.workflow.Step;
   import org.apache.commons.workflow.StepException;
   import org.apache.commons.workflow.Scope;
  +import org.apache.commons.workflow.util.ContextSupport;
   
   
   /**
  @@ -80,7 +83,7 @@
    * class.  If it is used in a multiple thread environment, callers must
    * take suitable precations.</p>
    *
  - * @version $Revision: 1.2 $ $Date: 2001/08/17 05:15:48 $
  + * @version $Revision: 1.3 $ $Date: 2001/08/18 21:06:50 $
    * @author Craig R. McClanahan
    */
   
  @@ -143,6 +146,12 @@
   
   
       /**
  +     * The event listener support object for this <code>Context</code>.
  +     */
  +    protected ContextSupport support = new ContextSupport(this);
  +
  +
  +    /**
        * The suspension flag.  If this is set when a particular <code>Step</code>
        * returns, control will be returned from our <code>execute()</code>
        * method to allow interaction with the rest of the application.  The
  @@ -480,7 +489,12 @@
           // Reset the suspend flag until set by another step
           suspend = false;
   
  +        // Send a beforeActivity() event to interested listeners
  +        support.fireBeforeActivity(nextStep);
  +
           // Perform execution until suspended or completed
  +        Step thisStep = null;
  +        StepException exception = null;
           while (true) {
   
               if (suspend)
  @@ -488,12 +502,31 @@
               if (nextStep == null)
                   break;                // We have completed this Activity
   
  -            Step thisStep = nextStep;
  +            thisStep = nextStep;
               nextStep = thisStep.getNextStep();
  -            thisStep.execute(this);
  +            try {
  +                support.fireBeforeStep(thisStep);
  +                thisStep.execute(this);
  +                support.fireAfterStep(thisStep);
  +            } catch (StepException e) {
  +                exception = e;
  +                support.fireAfterStep(thisStep, exception);
  +                break;
  +            } catch (Throwable t) {
  +                exception = new StepException(t, thisStep);
  +                support.fireAfterStep(thisStep, exception);
  +                break;
  +            }
   
           }
   
  +        // Send an afterActivity event to interested listeners
  +        support.fireAfterActivity(thisStep, exception);
  +
  +        // Rethrow any StepException that was thrown
  +        if (exception != null)
  +            throw exception;
  +
       }
   
   
  @@ -589,6 +622,35 @@
       public void setSuspend(boolean suspend) {
   
           this.suspend = suspend;
  +
  +    }
  +
  +
  +    // ------------------------------------------------- Event Listener Methods
  +
  +
  +    /**
  +     * Add a listener that is notified each time beans are added,
  +     * replaced, or removed in this context.
  +     *
  +     * @param listener The ContextListener to be added
  +     */
  +    public void addContextListener(ContextListener listener) {
  +
  +        support.addContextListener(listener);
  +
  +    }
  +
  +
  +    /**
  +     * Remove a listener that is notified each time beans are added,
  +     * replaced, or removed in this context.
  +     *
  +     * @param listener The ContextListener to be removed
  +     */
  +    public void removeContextListener(ContextListener listener) {
  +
  +        support.removeContextListener(listener);
   
       }
   
  
  
  
  1.1                  
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/util/ContextSupport.java
  
  Index: ContextSupport.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/util/ContextSupport.java,v
 1.1 2001/08/18 21:06:50 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2001/08/18 21:06:50 $
   *
   * ====================================================================
   * 
   * 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.util;
  
  
  import java.util.Map;
  import org.apache.commons.workflow.Context;
  import org.apache.commons.workflow.ContextEvent;
  import org.apache.commons.workflow.ContextListener;
  import org.apache.commons.workflow.Step;
  import org.apache.commons.workflow.StepException;
  
  
  /**
   * <strong>ContextSupport</strong> is a convenience class for managing the
   * firing of <code>ContextEvents</code> to registered
   * <code>ContextListeners</code>.
   *
   * @revision $Revision: 1.1 $ $Date: 2001/08/18 21:06:50 $
   * @author Craig R. McClanahan
   */
  
  public class ContextSupport {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a new ContextSupport object associated with the
       * specified Context.
       *
       * @param context Context for whom we will fire events
       */
      public ContextSupport(Context context) {
  
          super();
          this.context = context;
  
      }
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The set of registered <code>ContextListener</code> event listeners.
       */
      protected ContextListener listeners[] = new ContextListener[0];
  
  
      /**
       * The <code>Context</code> for whom we will fire events.
       */
      protected Context context = null;
  
  
      // ------------------------------------------------- Event Listener Methods
  
  
      /**
       * Add a listener that is notified each time beans are added,
       * replaced, or removed in this context.
       *
       * @param listener The ContextListener to be added
       */
      public void addContextListener(ContextListener listener) {
  
        synchronized (listeners) {
            ContextListener results[] =
              new ContextListener[listeners.length + 1];
            System.arraycopy(listeners, 0, results, 0, listeners.length);
            results[listeners.length] = listener;
            listeners = results;
        }
  
      }
  
  
      /**
       * Remove a listener that is notified each time beans are added,
       * replaced, or removed in this context.
       *
       * @param listener The ContextListener to be removed
       */
      public void removeContextListener(ContextListener listener) {
  
          synchronized (listeners) {
              int n = -1;
              for (int i = 0; i < listeners.length; i++) {
                  if (listeners[i] == listener) {
                      n = i;
                      break;
                  }
              }
              if (n < 0)
                  return;
              ContextListener results[] =
                new ContextListener[listeners.length - 1];
              int j = 0;
              for (int i = 0; i < listeners.length; i++) {
                  if (i != n)
                      results[j++] = listeners[i];
              }
              listeners = results;
          }
  
      }
  
  
      // --------------------------------------------------- Event Firing Methods
  
  
      /**
       * Fire a <code>afterActivity</code> event to all registered listeners.
       *
       * @param step Step that was executed last
       */
      public void fireAfterActivity(Step step) {
  
          if (listeners.length == 0)
              return;
          ContextEvent event = new ContextEvent(context, step);
          ContextListener interested[] = null;
          synchronized (listeners) {
              interested = (ContextListener[]) listeners.clone();
          }
          for (int i = 0; i < interested.length; i++)
              interested[i].afterActivity(event);
  
      }
  
  
      /**
       * Fire a <code>afterActivity</code> event to all registered listeners.
       *
       * @param step Step that was executed last
       * @param exception StepException thrown by the last Step
       */
      public void fireAfterActivity(Step step, StepException exception) {
  
          if (listeners.length == 0)
              return;
          ContextEvent event = new ContextEvent(context, step, exception);
          ContextListener interested[] = null;
          synchronized (listeners) {
              interested = (ContextListener[]) listeners.clone();
          }
          for (int i = 0; i < interested.length; i++)
              interested[i].afterActivity(event);
  
      }
  
  
      /**
       * Fire a <code>afterStep</code> event to all registered listeners.
       *
       * @param step Step that was executed
       */
      public void fireAfterStep(Step step) {
  
          if (listeners.length == 0)
              return;
          ContextEvent event = new ContextEvent(context, step);
          ContextListener interested[] = null;
          synchronized (listeners) {
              interested = (ContextListener[]) listeners.clone();
          }
          for (int i = 0; i < interested.length; i++)
              interested[i].afterStep(event);
  
      }
  
  
      /**
       * Fire a <code>afterStep</code> event to all registered listeners.
       *
       * @param step Step that was executed
       * @param exception StepException thrown by the executed step
       */
      public void fireAfterStep(Step step, StepException exception) {
  
          if (listeners.length == 0)
              return;
          ContextEvent event = new ContextEvent(context, step, exception);
          ContextListener interested[] = null;
          synchronized (listeners) {
              interested = (ContextListener[]) listeners.clone();
          }
          for (int i = 0; i < interested.length; i++)
              interested[i].afterStep(event);
  
      }
  
  
      /**
       * Fire a <code>beforeActivity</code> event to all registered listeners.
       *
       * @param step Step that will be executed first
       */
      public void fireBeforeActivity(Step step) {
  
          if (listeners.length == 0)
              return;
          ContextEvent event = new ContextEvent(context, step);
          ContextListener interested[] = null;
          synchronized (listeners) {
              interested = (ContextListener[]) listeners.clone();
          }
          for (int i = 0; i < interested.length; i++)
              interested[i].beforeActivity(event);
  
      }
  
  
      /**
       * Fire a <code>beforeStep</code> event to all registered listeners.
       *
       * @param step Step that is about to be executed
       */
      public void fireBeforeStep(Step step) {
  
          if (listeners.length == 0)
              return;
          ContextEvent event = new ContextEvent(context, step);
          ContextListener interested[] = null;
          synchronized (listeners) {
              interested = (ContextListener[]) listeners.clone();
          }
          for (int i = 0; i < interested.length; i++)
              interested[i].beforeStep(event);
  
      }
  
  
  }
  
  
  

Reply via email to