Author: rahul
Date: Wed Oct  4 13:38:43 2006
New Revision: 453015

URL: http://svn.apache.org/viewvc?view=rev&rev=453015
Log:
1) shale-dialog2 module:

Added the concept of DialogListener, which is a JavaBean listener for a single 
instance of a Shale dialog, and receives callbacks on:
 * Dialog start
 * Dialog stop
 * Exceptions during dialog execution
 * State entry
 * State exit
 * Transition being followed

Accordingly, DialogContext now has the related add/remove listener methods.

Created a o.a.s.d.base package which contains two abstract implementations:
 * AbstractDialogListener - A convenience no-op DialogListener impl
 * AbstractDialogContext - A convenience superclass for DialogContexts which 
has management of DialogListeners built into it

2) shale-dialg2-legacy module:

 * LegacyDialogContext now inherits from AbstractDialogContext
 * Fixed a logical bug - the dialog was started at DialogContext 
initialization, rather than when the DialogContext was "started"
 * LegacyDialogContext now fires callbacks on associated DialogListeners

3) shale-dialog2-scxml module:

 * SCXMLDialogContext now inherits from AbstractDialogContext
 * Replaced the SimpleSCXMLListener with a DelegatingSCXMLListener which 
delegates state machine progress notifications to the registered 
DialogListeners (rather than a Log, which is what the SimpleSCXMLListener did)
 * SCXMLDialogContext now fires callbacks on associated DialogListeners

Discussion/comments welcome.

SHALE-268

Added:
    
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogListener.java
   (with props)
    shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/
    
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogContext.java
   (with props)
    
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogListener.java
   (with props)
Modified:
    
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java
    
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogContext.java
    
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContext.java

Modified: 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java?view=diff&rev=453015&r1=453014&r2=453015
==============================================================================
--- 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java
 (original)
+++ 
shale/sandbox/shale-dialog2-legacy/src/main/java/org/apache/shale/dialog2/legacy/LegacyDialogContext.java
 Wed Oct  4 13:38:43 2006
@@ -16,12 +16,10 @@
 
 package org.apache.shale.dialog2.legacy;
 
-import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
-import javax.faces.FacesException;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
@@ -29,6 +27,7 @@
 
 import org.apache.shale.dialog2.DialogContext;
 import org.apache.shale.dialog2.DialogContextManager;
+import org.apache.shale.dialog2.base.AbstractDialogContext;
 import org.apache.shale.dialog2.legacy.model.ActionState;
 import org.apache.shale.dialog2.legacy.model.Dialog;
 import org.apache.shale.dialog2.legacy.model.EndState;
@@ -47,7 +46,7 @@
  *
  * @since 1.0.4
  */
-final class LegacyDialogContext implements DialogContext, Serializable {
+final class LegacyDialogContext extends AbstractDialogContext {
 
 
     // ------------------------------------------------------------ 
Constructors
@@ -71,8 +70,6 @@
         this.id = id;
         this.parentDialogId = parentDialogId;
 
-        start(dialog);
-
     }
 
 
@@ -259,9 +256,13 @@
 
             if (state instanceof ActionState) {
                 ActionState astate = (ActionState) state;
-                MethodBinding mb = context.getApplication().
-                  createMethodBinding(astate.getMethod(), 
ACTION_STATE_SIGNATURE);
-                outcome = (String) mb.invoke(context, ACTION_STATE_PARAMETERS);
+                try {
+                    MethodBinding mb = context.getApplication().
+                      createMethodBinding(astate.getMethod(), 
ACTION_STATE_SIGNATURE);
+                    outcome = (String) mb.invoke(context, 
ACTION_STATE_PARAMETERS);
+                } catch (Exception e) {
+                    fireOnException(e);
+                }
                 transition(position, outcome);
                 state = position.getState();
                 continue;
@@ -317,6 +318,12 @@
         }
         started = true;
 
+        // inform listeners we've been started
+        fireOnStart();
+
+        // set the dialog in motion
+        start(dialog);
+
         // Advance the computation of our dialog until a view state
         // is encountered, then navigate to it
         advance(context, null);
@@ -336,6 +343,9 @@
         deactivate();
         manager.remove(this);
 
+        // inform listeners
+        fireOnStop();
+
     }
 
 
@@ -492,15 +502,16 @@
         Object data = null;
         try {
             data = dialog.getDataClass().newInstance();
-        } catch (RuntimeException e) {
-            throw e;
         } catch (Exception e) {
-            throw new FacesException(e);
+            fireOnException(e);
         }
 
         // Push a Position and corresponding data object to our stacks
         push(new Position(dialog, state, data));
 
+        // inform listeners
+        fireOnEntry(state.getName());
+
     }
 
 
@@ -519,15 +530,18 @@
             return;
         }
 
+        State current = position.getState();
+        String fromStateId = current.getName();
+
         // Select the next state based on the specified outcome
-        Transition transition = position.getState().findTransition(outcome);
+        Transition transition = current.findTransition(outcome);
         if (transition == null) {
             transition = position.getDialog().findTransition(outcome);
         }
         if (transition == null) {
             throw new IllegalStateException
               ("Cannot find transition '" + outcome
-               + "' for state '" + position.getState().getName()
+               + "' for state '" + fromStateId
                + "' of dialog '" + position.getDialog().getName() + "'");
         }
         State next = position.getDialog().findState(transition.getTarget());
@@ -536,7 +550,21 @@
               ("Cannot find state '" + transition.getTarget()
                + "' for dialog '" + position.getDialog().getName() + "'");
         }
+        String toStateId = next.getName();
         position.setState(next);
+
+        // We inform listeners at the end, the assumption being that a 
transition
+        // must be an atomic transaction, either all associated callbacks must
+        // occur as the application would expect, or none should be initiated
+
+        // On a temporal axis, we fire the source state exit handlers first ...
+        fireOnExit(fromStateId);
+
+        // ... followed by the transition handlers ...
+        fireOnTransition(fromStateId, toStateId);
+
+        // ... and finally, the target state entry handlers
+        fireOnEntry(toStateId);
 
     }
 

Modified: 
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogContext.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogContext.java?view=diff&rev=453015&r1=453014&r2=453015
==============================================================================
--- 
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogContext.java
 (original)
+++ 
shale/sandbox/shale-dialog2-scxml/src/main/java/org/apache/shale/dialog2/scxml/SCXMLDialogContext.java
 Wed Oct  4 13:38:43 2006
@@ -16,24 +16,26 @@
 
 package org.apache.shale.dialog2.scxml;
 
-import java.io.Serializable;
 import java.util.Iterator;
 
-import javax.faces.FacesException;
 import javax.faces.application.ViewHandler;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 
 import org.apache.commons.scxml.SCXMLExecutor;
+import org.apache.commons.scxml.SCXMLListener;
 import org.apache.commons.scxml.TriggerEvent;
 import org.apache.commons.scxml.env.SimpleDispatcher;
 import org.apache.commons.scxml.env.SimpleErrorReporter;
-import org.apache.commons.scxml.env.SimpleSCXMLListener;
 import org.apache.commons.scxml.model.ModelException;
 import org.apache.commons.scxml.model.SCXML;
 import org.apache.commons.scxml.model.State;
+import org.apache.commons.scxml.model.Transition;
+import org.apache.commons.scxml.model.TransitionTarget;
 import org.apache.shale.dialog2.DialogContext;
 import org.apache.shale.dialog2.DialogContextManager;
+import org.apache.shale.dialog2.DialogListener;
+import org.apache.shale.dialog2.base.AbstractDialogContext;
 import org.apache.shale.dialog2.scxml.config.DialogMetadata;
 
 /**
@@ -43,7 +45,7 @@
  *
  * @since 1.0.4
  */
-final class SCXMLDialogContext implements DialogContext, Serializable {
+final class SCXMLDialogContext extends AbstractDialogContext {
 
 
     // ------------------------------------------------------------ 
Constructors
@@ -73,7 +75,7 @@
                         new SimpleDispatcher(), new SimpleErrorReporter());
         SCXML statemachine = dialog.getStateMachine();
         this.executor.setStateMachine(statemachine);
-        this.executor.addListener(statemachine, new SimpleSCXMLListener());
+        this.executor.addListener(statemachine, new DelegatingSCXMLListener());
 
         // TODO - Consider adding an explicit root context backed by either the
         // request or session map for greater EL capacities in the SCXML
@@ -210,8 +212,7 @@
             dialogExecutor.triggerEvent(new 
TriggerEvent(Globals.POSTBACK_EVENT,
                                 TriggerEvent.SIGNAL_EVENT));
         } catch (ModelException me) {
-            // FIXME - Not an IAE
-            throw new IllegalArgumentException(me.getMessage());
+            fireOnException(me);
         }
 
         // TODO - Re-evaluate before leaving sandbox
@@ -234,6 +235,9 @@
     /** [EMAIL PROTECTED] */
     public void start(FacesContext context) {
 
+        // inform listeners we're good to go
+        fireOnStart();
+
         // Construct an appropriate data object for the specified dialog
         ClassLoader loader = Thread.currentThread().getContextClassLoader();
         if (loader == null) {
@@ -242,18 +246,14 @@
         Class dataClass = null;
         try {
             dataClass = loader.loadClass(dataClassName);
-        } catch (RuntimeException e) {
-            throw e;
         } catch (Exception e) {
-            throw new IllegalArgumentException(e.toString());
+            fireOnException(e);
         }
 
         try {
             this.data = dataClass.newInstance();
-        } catch (RuntimeException e) {
-            throw e;
         } catch (Exception e) {
-            throw new FacesException(e);
+            fireOnException(e);
         }
 
         SCXMLExecutor dialogExecutor = getExecutor(context);
@@ -263,9 +263,7 @@
         try {
             dialogExecutor.go();
         } catch (ModelException me) {
-            // FIXME - Better exception, for extra credit:
-            // TODO - need DialogListener
-            throw new IllegalArgumentException("SCXML dialog cannot start:" + 
name);
+            fireOnException(me);
         }
 
         // Using C/C, "View" state ID is JSF viewId, which is an acceptable
@@ -291,6 +289,9 @@
         deactivate();
         manager.remove(this);
 
+        // inform listeners
+        fireOnStop();
+
     }
 
 
@@ -336,8 +337,8 @@
      * Get the [EMAIL PROTECTED] SCXMLExecutor} instance driving this dialog, 
replenish
      * if needed.
      *
-     * @param The [EMAIL PROTECTED] FacesContext} for this request
-     * @return The [EMAIL PROTECTED] SCXMLExecutor} instance driving this 
dialog 
+     * @param context The [EMAIL PROTECTED] FacesContext} for this request
+     * @return The [EMAIL PROTECTED] SCXMLExecutor} instance driving this 
dialog
      */
     private SCXMLExecutor getExecutor(FacesContext context) {
 
@@ -348,11 +349,56 @@
             SCXML stateMachine = ((SCXMLDialogManager) 
manager).dialog(context, name).
                 getStateMachine();
             this.executor.setStateMachine(stateMachine);
-            this.executor.addListener(stateMachine, new SimpleSCXMLListener());
+            this.executor.addListener(stateMachine, new 
DelegatingSCXMLListener());
             
this.executor.getCurrentStatus().getStates().add(stateMachine.getTargets().get(stateId));
         }
 
         return this.executor;
+    }
+
+
+    /**
+     * A [EMAIL PROTECTED] SCXMLListener} that delegates to the Shale
+     * [EMAIL PROTECTED] DialogListener}s attached to this [EMAIL PROTECTED] 
DialogContext}.
+     */
+    class DelegatingSCXMLListener implements SCXMLListener {
+
+        /**
+         * Handle entry callbacks.
+         *
+         * @param tt The <code>TransitionTarget</code> being entered.
+         */
+        public void onEntry(TransitionTarget tt) {
+
+            fireOnEntry(tt.getId());
+
+        }
+
+        /**
+         * Handle transition callbacks.
+         *
+         * @param from The source <code>TransitionTarget</code>
+         * @param to The destination <code>TransitionTarget</code>
+         * @param t The <code>Transition</code>
+         */
+        public void onTransition(TransitionTarget from, TransitionTarget to,
+                                 Transition t) {
+
+            fireOnTransition(from.getId(), to.getId());
+
+        }
+
+        /**
+         * Handle exit callbacks.
+         *
+         * @param tt The <code>TransitionTarget</code> being exited.
+         */
+        public void onExit(TransitionTarget tt) {
+
+            fireOnExit(tt.getId());
+
+        }
+
     }
 
 }

Modified: 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContext.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContext.java?view=diff&rev=453015&r1=453014&r2=453015
==============================================================================
--- 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContext.java
 (original)
+++ 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogContext.java
 Wed Oct  4 13:38:43 2006
@@ -139,4 +139,30 @@
     public void stop(FacesContext context);
 
 
+    //------------------------------------------------- DialogContext Listeners
+
+
+    /**
+     * Register given [EMAIL PROTECTED] DialogListener} for this [EMAIL 
PROTECTED] DialogContext}.
+     * Listener cannot be <code>null</code>.
+     *
+     * @param listener The [EMAIL PROTECTED] DialogListener} instance.
+     * @return <code>true</code>, if the listener is added, or
+     *         <code>false</code>, if it has already been added
+     */
+    public boolean addListener(DialogListener listener);
+
+
+    /**
+     * Remove this previously registered [EMAIL PROTECTED] DialogListener} for 
this
+     * [EMAIL PROTECTED] DialogContext}. The listener will no longer receive 
any
+     * associated callbacks.
+     *
+     * @param listener The [EMAIL PROTECTED] DialogListener} instance.
+     * @return <code>true</code>, if this list was removed, or
+     *         <code>false</code>, if this listener was not registered
+     */
+    public boolean removeListener(DialogListener listener);
+
+
 }

Added: 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogListener.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogListener.java?view=auto&rev=453015
==============================================================================
--- 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogListener.java
 (added)
+++ 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogListener.java
 Wed Oct  4 13:38:43 2006
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.dialog2;
+
+
+/**
+ * <p>JavaBeans listener for a single instance of a Shale dialog.</p>
+ *
+ * <p><strong>IMPLEMENTATION NOTE</strong> - Implementations of this interface
+ * will be stored in session scope, so they should be serializable.</p>
+ *
+ * @since 1.0.4
+ */
+public interface DialogListener {
+
+
+    //----------------------------------------------- Coarse grained callbacks
+
+    /**
+     * <p>Handle the starting of the dialog instance.</p>
+     */
+    public void onStart();
+
+
+    /**
+     * <p>Handle the stopping of the dialog instance.</p>
+     */
+    public void onStop();
+
+
+    /**
+     * <p>Handle an unexpected failure during the execution of this dialg
+     * instance.</p>
+     *
+     * @param exception A potentially implementation specific exception
+     *                  during the execution of this dialog instance
+     */
+    public void onException(Exception exception);
+
+
+    //------------------------------------------------- Fine grained callbacks
+
+    /**
+     * <p>Handle an entry into a dialog state.</p>
+     *
+     * @param stateId Implementation specific identifier of the state
+     *                that has been entered
+     */
+    public void onEntry(String stateId);
+
+
+    /**
+     * <p>Handle an exit from a dialog state.</p>
+     *
+     * @param stateId Implementation specific identifier of the state
+     *                that has been exited
+     */
+    public void onExit(String stateId);
+
+
+    /**
+     * <p>Handle a transition being followed.</p>
+     *
+     * @param fromStateId Implementation specific identifier of the source
+     *                    state for the transition that has been followed
+     * @param toStateId Implementation specific identifier of the target
+     *                  state for the transition that has been followed
+     */
+    public void onTransition(String fromStateId, String toStateId);
+
+
+    //-------------------------------------------------------------- Ownership
+
+    /**
+     * <p>Return the [EMAIL PROTECTED] DialogContext} instance associated with 
this
+     * [EMAIL PROTECTED] DialogListener}.</p>
+     *
+     * @return The [EMAIL PROTECTED] DialogContext} whose execution we are 
listening to
+     */
+    public DialogContext getDialogContext();
+
+
+    /**
+     * <p>Set the [EMAIL PROTECTED] DialogContext} instance associated with 
this
+     * [EMAIL PROTECTED] DialogListener}.</p>
+     *
+     * @param dialogContext The [EMAIL PROTECTED] DialogContext} whose 
execution we
+     *                      will track
+     */
+    public void setDialogContext(DialogContext dialogContext);
+
+
+}
+

Propchange: 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/DialogListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogContext.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogContext.java?view=auto&rev=453015
==============================================================================
--- 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogContext.java
 (added)
+++ 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogContext.java
 Wed Oct  4 13:38:43 2006
@@ -0,0 +1,222 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.dialog2.base;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.shale.dialog2.DialogContext;
+import org.apache.shale.dialog2.DialogListener;
+
+/**
+ * <p>Convenience abstract [EMAIL PROTECTED] DialogContext} implementation. 
Subclasses
+ * are expected to be serializable.</p>
+ *
+ * @since 1.0.4
+ */
+public abstract class AbstractDialogContext implements DialogContext, 
Serializable {
+
+    //------------------------------------------------------------- Properties
+
+    /**
+     * The list of all registered [EMAIL PROTECTED] DialogListener}s for this
+     * [EMAIL PROTECTED] DialogContext}.
+     */
+    private List listeners = new ArrayList();
+
+
+    //--------------------------------------------------- Listener Bookkeeping
+
+    /**
+     * Register given [EMAIL PROTECTED] DialogListener} for this [EMAIL 
PROTECTED] DialogContext}.
+     * Listener cannot be <code>null</code>.
+     *
+     * @param listener The [EMAIL PROTECTED] DialogListener} instance.
+     * @return <code>true</code>, if the listener is added, or
+     *         <code>false</code>, if it has already been added
+     */
+    public boolean addListener(DialogListener listener) {
+
+        if (listener == null) {
+            throw new IllegalArgumentException("Cannot register null 
DialogListener");
+        }
+
+        synchronized (listeners) {
+            if (listeners.contains(listener)) {
+                return false;
+            }
+            listener.setDialogContext(this); // attach self reference
+            return listeners.add(listener);
+        }
+    }
+
+
+    /**
+     * Remove this previously registered [EMAIL PROTECTED] DialogListener} for 
this
+     * [EMAIL PROTECTED] DialogContext}. The listener will no longer receive 
any
+     * associated callbacks.
+     *
+     * @param listener The [EMAIL PROTECTED] DialogListener} instance.
+     * @return <code>true</code>, if this list was removed, or
+     *         <code>false</code>, if this listener was not registered
+     */
+    public boolean removeListener(DialogListener listener) {
+
+        if (listener == null) {
+            throw new IllegalArgumentException("Cannot remove null 
DialogListener");
+        }
+
+        boolean removed;
+        synchronized (listeners) {
+                removed = listeners.remove(listener);
+        }
+        if (removed) {
+            listener.setDialogContext(null); // detach self reference
+        }
+        return removed;
+
+    }
+
+
+    /**
+     * Make the list of [EMAIL PROTECTED] DialogListener}s available to 
subclasses.
+     *
+     * @return The mutable list of currently registered [EMAIL PROTECTED] 
DialogListener}s
+     */
+    protected List getListeners() {
+
+        return listeners;
+
+    }
+
+
+    //-------------------------- Utilities for firing DialogListener callbacks
+
+    /**
+     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the dialog
+     * instance has begun execution.
+     *
+     */
+    protected void fireOnStart() {
+
+        synchronized (listeners) {
+            for (int i = 0; i < listeners.size(); i++) {
+                DialogListener listener = (DialogListener) listeners.get(i);
+                listener.onStart();
+            }
+        }
+
+    }
+
+
+    /**
+     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the dialog
+     * instance has finished execution normally.
+     *
+     */
+    protected void fireOnStop() {
+
+        synchronized (listeners) {
+            for (int i = 0; i < listeners.size(); i++) {
+                DialogListener listener = (DialogListener) listeners.get(i);
+                listener.onStop();
+            }
+        }
+
+    }
+
+
+    /**
+     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the dialog
+     * instance has encountered an unexpected error condition.
+     *
+     * @param exception A potentially implementation specific exception
+     *                  during the execution of this dialog instance
+     */
+    protected void fireOnException(Exception exception) {
+
+        synchronized (listeners) {
+            for (int i = 0; i < listeners.size(); i++) {
+                DialogListener listener = (DialogListener) listeners.get(i);
+                listener.onException(exception);
+            }
+        }
+
+    }
+
+
+    /**
+     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the 
dialog instance
+     * execution has entered a particular state.
+     *
+     * @param stateId Implementation specific identifier of the state
+     *                that has been entered
+     */
+    protected void fireOnEntry(String stateId) {
+
+        synchronized (listeners) {
+            for (int i = 0; i < listeners.size(); i++) {
+                DialogListener listener = (DialogListener) listeners.get(i);
+                listener.onEntry(stateId);
+            }
+        }
+
+    }
+
+
+    /**
+     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the 
dialog instance
+     * execution has exited a particular state.
+     *
+     * @param stateId Implementation specific identifier of the state
+     *                that has been exited
+     */
+    protected void fireOnExit(String stateId) {
+
+        synchronized (listeners) {
+            for (int i = 0; i < listeners.size(); i++) {
+                DialogListener listener = (DialogListener) listeners.get(i);
+                listener.onExit(stateId);
+            }
+        }
+
+    }
+
+
+    /**
+     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the 
dialog instance
+     * execution has followed a particular transition.
+     *
+     * @param fromStateId Implementation specific identifier of the source
+     *                    state for the transition that has been followed
+     * @param toStateId Implementation specific identifier of the target
+     *                  state for the transition that has been followed
+     */
+    protected void fireOnTransition(String fromStateId, String toStateId) {
+
+        synchronized (listeners) {
+            for (int i = 0; i < listeners.size(); i++) {
+                DialogListener listener = (DialogListener) listeners.get(i);
+                listener.onTransition(fromStateId, toStateId);
+            }
+        }
+
+    }
+
+}
+

Propchange: 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogListener.java
URL: 
http://svn.apache.org/viewvc/shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogListener.java?view=auto&rev=453015
==============================================================================
--- 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogListener.java
 (added)
+++ 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogListener.java
 Wed Oct  4 13:38:43 2006
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shale.dialog2.base;
+
+import java.io.Serializable;
+
+import org.apache.shale.dialog2.DialogContext;
+import org.apache.shale.dialog2.DialogListener;
+
+/**
+ * <p>Convenience abstract [EMAIL PROTECTED] DialogListener} implementation. 
Subclasses
+ * are expected to be serializable.</p>
+ *
+ * @since 1.0.4
+ */
+public abstract class AbstractDialogListener implements DialogListener, 
Serializable {
+
+    //------------------------------------------------------------- Properties
+
+    /**
+     * The [EMAIL PROTECTED] DialogContext} we are interested in.
+     */
+    private DialogContext dialogContext;
+
+
+    //------------------------------------------------- DialogListener methods
+
+    /**
+     * [EMAIL PROTECTED]
+     *
+     * @see org.apache.shale.dialog2.DialogListener#onStart()
+     */
+    public void onStart() {
+
+        // Do nothing
+
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     *
+     * @see org.apache.shale.dialog2.DialogListener#onStop()
+     */
+    public void onStop() {
+
+        // Do nothing
+
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     *
+     * @see 
org.apache.shale.dialog2.DialogListener#onException(java.lang.Exception)
+     */
+    public void onException(Exception e) {
+
+        // Do nothing
+
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     *
+     * @see org.apache.shale.dialog2.DialogListener#onEntry(java.lang.String)
+     */
+    public void onEntry(String stateId) {
+
+        // Do nothing
+
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     *
+     * @see org.apache.shale.dialog2.DialogListener#onExit(java.lang.String)
+     */
+    public void onExit(String stateId) {
+
+        // Do nothing
+
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     *
+     * @see 
org.apache.shale.dialog2.DialogListener#onTransition(java.lang.String,java.lang.String)
+     */
+    public void onTransition(String fromStateId, String toStateId) {
+
+        // Do nothing
+
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     *
+     * @see org.apache.shale.dialog2.DialogListener#getDialogContext()
+     */
+    public DialogContext getDialogContext() {
+
+        return dialogContext;
+
+    }
+
+    /**
+     * [EMAIL PROTECTED]
+     *
+     * @see 
org.apache.shale.dialog2.DialogListener#setDialogContext(org.apache.shale.dialog2.DialogContext)
+     */
+    public void setDialogContext(DialogContext dialogContext) {
+
+        this.dialogContext = dialogContext;
+
+    }
+
+}
+

Propchange: 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
shale/sandbox/shale-dialog2/src/main/java/org/apache/shale/dialog2/base/AbstractDialogListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL


Reply via email to