Author: craigmcc
Date: Mon Dec  4 13:25:07 2006
New Revision: 482364

URL: http://svn.apache.org/viewvc?view=rev&rev=482364
Log:
First round of supporting events when DialogContextManager.create() or
DialogContextManager.remove() is called.  You can now register listeners of
type DialogContextManagerListener on the DialogContextManager instance.  One
remaining FIXME is to make it possible to be notified when DialogContextManager
instances themselves are placed in and out of service -- since these instances
are typically a session scoped managed bean, we need to do something
interesting in order to fire the necessary events.

Also did a bit of other cleanup:

* Renamed DialogListener to DialogContextListener (with associated
  ripple effects on method names) for naming consistency

* Added synchronization in a couple of missing cases

* Provided getXxxxxListener() methods that returned an array of
  registered listeners for each type

* Used the "get" methods in the abstract base classes to (a) avoid
  problems if the list of listeners is modified while being traversed
  to fire events, and (b) took the event firing calls out of the
  synchronization blocks to avoid overhead when an event listener
  might take a long time to return.

SHALE-251

Added:
    
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextListener.java
      - copied, changed from r482329, 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogListener.java
    
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManagerListener.java
   (with props)
    
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextListener.java
      - copied, changed from r482329, 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogListener.java
    
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java
   (with props)
Removed:
    
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogListener.java
    
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogListener.java
Modified:
    
shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogManager.java
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
    
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogManager.java
    
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContext.java
    
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManager.java
    
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContext.java

Modified: 
shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogManager.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogManager.java?view=diff&rev=482364&r1=482363&r2=482364
==============================================================================
--- 
shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogManager.java
 (original)
+++ 
shale/framework/trunk/shale-dialog-basic/src/main/java/org/apache/shale/dialog/basic/BasicDialogManager.java
 Mon Dec  4 13:25:07 2006
@@ -28,16 +28,17 @@
 import org.apache.shale.dialog.Constants;
 import org.apache.shale.dialog.DialogContext;
 import org.apache.shale.dialog.DialogContextManager;
+import org.apache.shale.dialog.base.AbstractDialogContextManager;
 import org.apache.shale.dialog.basic.model.Dialog;
 
 /**
  * <p>Implementation of [EMAIL PROTECTED] DialogContextManager} for integrating
  * basic dialog support into the Shale Dialog Manager.</p>
  *
- *
  * @since 1.0.4
  */
-public final class BasicDialogManager implements DialogContextManager, 
Serializable {
+public final class BasicDialogManager extends AbstractDialogContextManager
+  implements DialogContextManager, Serializable {
 
 
     // ------------------------------------------------- DialogContext 
Variables
@@ -112,8 +113,11 @@
         // Configure a new BasicDialogContext instance
         BasicDialogContext instance = new BasicDialogContext(this, dialog, 
generateId(),
                                                               parentDialogId);
-        map.put(instance.getId(), instance);
+        synchronized (map) {
+            map.put(instance.getId(), instance);
+        }
         
context.getExternalContext().getRequestMap().put(Constants.CONTEXT_BEAN, 
instance);
+        fireOnCreate(instance);
         return instance;
 
     }
@@ -127,8 +131,13 @@
 
     /** @{inheritDoc} */
     public void remove(DialogContext instance) {
-        if (map.remove(instance.getId()) == instance) {
+        boolean found = false;
+        synchronized (map) {
+            found = map.remove(instance.getId()) == instance;
+        }
+        if (found) {
             ((BasicDialogContext) instance).deactivate();
+            fireOnRemove(instance);
         }
     }
 

Modified: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java?view=diff&rev=482364&r1=482363&r2=482364
==============================================================================
--- 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
 (original)
+++ 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogContext.java
 Mon Dec  4 13:25:07 2006
@@ -42,7 +42,7 @@
 import org.apache.shale.dialog.Constants;
 import org.apache.shale.dialog.DialogContext;
 import org.apache.shale.dialog.DialogContextManager;
-import org.apache.shale.dialog.DialogListener;
+import org.apache.shale.dialog.DialogContextListener;
 import org.apache.shale.dialog.base.AbstractDialogContext;
 import org.apache.shale.dialog.scxml.config.DialogMetadata;
 

Modified: 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogManager.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogManager.java?view=diff&rev=482364&r1=482363&r2=482364
==============================================================================
--- 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogManager.java
 (original)
+++ 
shale/framework/trunk/shale-dialog-scxml/src/main/java/org/apache/shale/dialog/scxml/SCXMLDialogManager.java
 Mon Dec  4 13:25:07 2006
@@ -32,6 +32,7 @@
 import org.apache.shale.dialog.Constants;
 import org.apache.shale.dialog.DialogContext;
 import org.apache.shale.dialog.DialogContextManager;
+import org.apache.shale.dialog.base.AbstractDialogContextManager;
 import org.apache.shale.dialog.scxml.config.ConfigurationParser;
 import org.apache.shale.dialog.scxml.config.DialogMetadata;
 
@@ -41,7 +42,8 @@
  *
  * @since 1.0.4
  */
-public final class SCXMLDialogManager implements DialogContextManager, 
Serializable {
+public final class SCXMLDialogManager
+  extends AbstractDialogContextManager implements Serializable {
 
 
     // ------------------------------------------------------ 
SCXMLDialogManager Variables
@@ -127,8 +129,11 @@
         SCXMLDialogContext instance = new SCXMLDialogContext(this, dialog, 
generateId(),
                 parentDialogId);
         instance.setData(new HashMap());
-        map.put(instance.getId(), instance);
+        synchronized (map) {
+            map.put(instance.getId(), instance);
+        }
         
context.getExternalContext().getRequestMap().put(Constants.CONTEXT_BEAN, 
instance);
+        fireOnCreate(instance);
         return instance;
     }
 
@@ -141,8 +146,13 @@
 
     /** [EMAIL PROTECTED] */
     public void remove(DialogContext instance) {
-        if (map.remove(instance.getId()) == instance) {
+        boolean found = false;
+        synchronized (map) {
+            found = map.remove(instance.getId()) == instance;
+        }
+        if (found) {
             ((SCXMLDialogContext) instance).deactivate();
+            fireOnRemove(instance);
         }
     }
 

Modified: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContext.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContext.java?view=diff&rev=482364&r1=482363&r2=482364
==============================================================================
--- 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContext.java
 (original)
+++ 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContext.java
 Mon Dec  4 13:25:07 2006
@@ -138,26 +138,32 @@
     public void stop(FacesContext context);
 
 
-    //------------------------------------------------- DialogContext Listeners
+    // ------------------------------------------------- DialogContext 
Listeners
 
 
     /**
-     * Register given [EMAIL PROTECTED] DialogListener} for this [EMAIL 
PROTECTED] DialogContext}.
+     * Register given [EMAIL PROTECTED] DialogContextListener} for this [EMAIL 
PROTECTED] DialogContext}.
      * Listener cannot be <code>null</code>.
      *
-     * @param listener The [EMAIL PROTECTED] DialogListener} instance.
+     * @param listener The [EMAIL PROTECTED] DialogContextListener} instance.
      */
-    public void addDialogListener(DialogListener listener);
+    public void addDialogContextListener(DialogContextListener listener);
 
 
     /**
-     * Remove this previously registered [EMAIL PROTECTED] DialogListener} for 
this
+     * Return the set of currently registered [EMAIL PROTECTED] 
DialogContextListener}s.
+     */
+    public DialogContextListener[] getDialogContextListeners();
+
+
+    /**
+     * Remove this previously registered [EMAIL PROTECTED] 
DialogContextListener} for this
      * [EMAIL PROTECTED] DialogContext}. The listener will no longer receive 
any
      * associated callbacks.
      *
-     * @param listener The [EMAIL PROTECTED] DialogListener} instance.
+     * @param listener The [EMAIL PROTECTED] DialogContextListener} instance.
      */
-    public void removeDialogListener(DialogListener listener);
+    public void removeDialogContextListener(DialogContextListener listener);
 
 
 }

Copied: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextListener.java
 (from r482329, 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogListener.java)
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextListener.java?view=diff&rev=482364&p1=shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogListener.java&r1=482329&p2=shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextListener.java&r2=482364
==============================================================================
--- 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogListener.java
 (original)
+++ 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextListener.java
 Mon Dec  4 13:25:07 2006
@@ -26,7 +26,7 @@
  *
  * @since 1.0.4
  */
-public interface DialogListener {
+public interface DialogContextListener {
 
 
     //----------------------------------------------- Coarse grained callbacks
@@ -88,7 +88,7 @@
 
     /**
      * <p>Return the [EMAIL PROTECTED] DialogContext} instance associated with 
this
-     * [EMAIL PROTECTED] DialogListener}.</p>
+     * [EMAIL PROTECTED] DialogContextListener}.</p>
      *
      * @return The [EMAIL PROTECTED] DialogContext} whose execution we are 
listening to
      */
@@ -97,7 +97,7 @@
 
     /**
      * <p>Set the [EMAIL PROTECTED] DialogContext} instance associated with 
this
-     * [EMAIL PROTECTED] DialogListener}.</p>
+     * [EMAIL PROTECTED] DialogContextListener}.</p>
      *
      * @param dialogContext The [EMAIL PROTECTED] DialogContext} whose 
execution we
      *                      will track

Modified: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManager.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManager.java?view=diff&rev=482364&r1=482363&r2=482364
==============================================================================
--- 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManager.java
 (original)
+++ 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManager.java
 Mon Dec  4 13:25:07 2006
@@ -105,4 +105,32 @@
     public void remove(DialogContext instance);
 
 
+    // ------------------------------------------ DialogContextManager 
Listeners
+
+
+    /**
+     * Register given [EMAIL PROTECTED] DialogContextManagerListener} for this
+     * [EMAIL PROTECTED] DialogContextManager}.  Listener cannot be 
<code>null</code>.
+     *
+     * @param listener The [EMAIL PROTECTED] DialogContextManagerListener} 
instance.
+     */
+    public void addDialogContextManagerListener(DialogContextManagerListener 
listener);
+
+
+    /**
+     * Return the set of currently registered [EMAIL PROTECTED] 
DialogContextManagerListener}s.
+     */
+    public DialogContextManagerListener[] getDialogContextManagerListeners();
+
+
+    /**
+     * Remove this previously registered [EMAIL PROTECTED] 
DialogContextManagerListener}
+     * for this [EMAIL PROTECTED] DialogContextManager}. The listener will no 
longer receive
+     * any associated callbacks.
+     *
+     * @param listener The [EMAIL PROTECTED] DialogContextManagerListener} 
instance.
+     */
+    public void 
removeDialogContextManagerListener(DialogContextManagerListener listener);
+
+
 }

Added: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManagerListener.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManagerListener.java?view=auto&rev=482364
==============================================================================
--- 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManagerListener.java
 (added)
+++ 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManagerListener.java
 Mon Dec  4 13:25:07 2006
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.dialog;
+
+/**
+ * <p>JavaBeans event listener for events on a [EMAIL PROTECTED] 
DialogContextManager}
+ * instance.</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 DialogContextManagerListener {
+    
+
+    // ------------------------------------------------ Coarse Grained 
Callbacks
+
+
+    /**
+     * <p>Handle the case where a new [EMAIL PROTECTED] DialogContext} 
instance has
+     * been created.  This event will be fired <strong>before</strong> the
+     * instance has been started; however, it is legitimate to do things
+     * like register fine grained listeners on this instance.</p>
+     *
+     * @param context The [EMAIL PROTECTED] DialogContext} instance being 
created
+     */
+    public void onCreate(DialogContext context);
+
+
+    /**
+     * <p>Handle the case where a new [EMAIL PROTECTED] DialogContext} 
instance has
+     * been removed.  This event will be fired <strong>after</strong> the
+     * instance has been stopped; however, it is legitimate to do things
+     * like deregister fine grained listeners on this instance.</p>
+     *
+     * @param context The [EMAIL PROTECTED] DialogContext} instance being 
created
+     */
+    public void onRemove(DialogContext context);
+
+
+    // --------------------------------------------------------------- 
Ownership
+
+
+    /**
+     * <p>Return the [EMAIL PROTECTED] DialogContextManager} instance 
associated with
+     * this [EMAIL PROTECTED] DialogContextManagerListener}.</p>
+     */
+    public DialogContextManager getDialogContextManager();
+
+
+    /**
+     * <p>Set the [EMAIL PROTECTED] DialogContextManager} instance associated 
with
+     * this [EMAIL PROTECTED] DialogContextManagerListener}.</p>
+     *
+     * @param manager The new [EMAIL PROTECTED] DialogContextManager}
+     */
+    public void setDialogContextManager(DialogContextManager manager);
+
+
+}

Propchange: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManagerListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/DialogContextManagerListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContext.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContext.java?view=diff&rev=482364&r1=482363&r2=482364
==============================================================================
--- 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContext.java
 (original)
+++ 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContext.java
 Mon Dec  4 13:25:07 2006
@@ -17,27 +17,28 @@
 
 package org.apache.shale.dialog.base;
 
-import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.shale.dialog.DialogContext;
-import org.apache.shale.dialog.DialogListener;
+import org.apache.shale.dialog.DialogContextListener;
 
 /**
- * <p>Convenience abstract [EMAIL PROTECTED] DialogContext} implementation. 
Subclasses
- * are expected to be serializable.</p>
+ * <p>Convenience abstract [EMAIL PROTECTED] DialogContext} implementation.
+ * Provides listener registration and convenience event firing methods.</p>
  *
  * @since 1.0.4
  */
-public abstract class AbstractDialogContext implements DialogContext, 
Serializable {
+public abstract class AbstractDialogContext implements DialogContext {
+
+
+    // -------------------------------------------------------------- 
Properties
 
-    //------------------------------------------------------------- Properties
 
     /**
-     * The list of all registered [EMAIL PROTECTED] DialogListener}s for this
+     * The list of all registered [EMAIL PROTECTED] DialogContextListener}s 
for this
      * [EMAIL PROTECTED] DialogContext}.
      */
     private List listeners = new ArrayList();
@@ -49,23 +50,24 @@
     private transient Log log;
 
 
-    //--------------------------------------------------- Listener Bookkeeping
+    // ---------------------------------------------------- Listener 
Bookkeeping
+
 
     /**
-     * Register given [EMAIL PROTECTED] DialogListener} for this [EMAIL 
PROTECTED] DialogContext}.
+     * Register given [EMAIL PROTECTED] DialogContextListener} for this [EMAIL 
PROTECTED] DialogContext}.
      * Listener cannot be <code>null</code>.
      *
-     * @param listener The [EMAIL PROTECTED] DialogListener} instance.
+     * @param listener The [EMAIL PROTECTED] DialogContextListener} instance.
      */
-    public void addDialogListener(DialogListener listener) {
+    public void addDialogContextListener(DialogContextListener listener) {
 
         if (listener == null) {
-            throw new IllegalArgumentException("Cannot register null 
DialogListener");
+            throw new IllegalArgumentException("Cannot register null 
DialogContextListener");
         }
 
         synchronized (listeners) {
             if (listeners.contains(listener)) {
-                throw new IllegalArgumentException("DialogListener already 
registered");
+                throw new IllegalArgumentException("DialogContextListener 
already registered");
             }
             listener.setDialogContext(this); // attach self reference
             listeners.add(listener);
@@ -74,21 +76,34 @@
 
 
     /**
-     * Remove this previously registered [EMAIL PROTECTED] DialogListener} for 
this
+     * Return the set of currently registered [EMAIL PROTECTED] 
DialogContextListener}s.
+     */
+    public DialogContextListener[] getDialogContextListeners() {
+
+        synchronized (listeners) {
+            return (DialogContextListener[])
+              listeners.toArray(new DialogContextListener[listeners.size()]);
+        }
+
+    }
+
+
+    /**
+     * Remove this previously registered [EMAIL PROTECTED] 
DialogContextListener} for this
      * [EMAIL PROTECTED] DialogContext}. The listener will no longer receive 
any
      * associated callbacks.
      *
-     * @param listener The [EMAIL PROTECTED] DialogListener} instance.
+     * @param listener The [EMAIL PROTECTED] DialogContextListener} instance.
      */
-    public void removeDialogListener(DialogListener listener) {
+    public void removeDialogContextListener(DialogContextListener listener) {
 
         if (listener == null) {
-            throw new IllegalArgumentException("Cannot remove null 
DialogListener");
+            throw new IllegalArgumentException("Cannot remove null 
DialogContextListener");
         }
 
         boolean removed;
         synchronized (listeners) {
-                removed = listeners.remove(listener);
+            removed = listeners.remove(listener);
         }
         if (removed) {
             listener.setDialogContext(null); // detach self reference
@@ -97,56 +112,41 @@
     }
 
 
-    /**
-     * 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() {
+    // -------------------- Utilities for firing DialogContextListener 
callbacks
 
-        return listeners;
-
-    }
-
-
-    //-------------------------- Utilities for firing DialogListener callbacks
 
     /**
-     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the dialog
+     * Inform all registered [EMAIL PROTECTED] DialogContextListener}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();
-            }
+        DialogContextListener[] listeners = getDialogContextListeners();
+        for (int i = 0; i < listeners.length; i++) {
+            listeners[i].onStart();
         }
 
     }
 
 
     /**
-     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the dialog
+     * Inform all registered [EMAIL PROTECTED] DialogContextListener}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();
-            }
+        DialogContextListener[] listeners = getDialogContextListeners();
+        for (int i = 0; i < listeners.length; i++) {
+            listeners[i].onStop();
         }
 
     }
 
 
     /**
-     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the dialog
+     * Inform all registered [EMAIL PROTECTED] DialogContextListener}s that 
the dialog
      * instance has encountered an unexpected error condition. The exception
      * is first logged for archival.
      *
@@ -157,18 +157,16 @@
 
         log().error(exception.getMessage(), exception);
 
-        synchronized (listeners) {
-            for (int i = 0; i < listeners.size(); i++) {
-                DialogListener listener = (DialogListener) listeners.get(i);
-                listener.onException(exception);
-            }
+        DialogContextListener[] listeners = getDialogContextListeners();
+        for (int i = 0; i < listeners.length; i++) {
+            listeners[i].onException(exception);
         }
 
     }
 
 
     /**
-     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the 
dialog instance
+     * Inform all registered [EMAIL PROTECTED] DialogContextListener}s that 
the dialog instance
      * execution has entered a particular state.
      *
      * @param stateId Implementation specific identifier of the state
@@ -176,18 +174,16 @@
      */
     protected void fireOnEntry(String stateId) {
 
-        synchronized (listeners) {
-            for (int i = 0; i < listeners.size(); i++) {
-                DialogListener listener = (DialogListener) listeners.get(i);
-                listener.onEntry(stateId);
-            }
+        DialogContextListener[] listeners = getDialogContextListeners();
+        for (int i = 0; i < listeners.length; i++) {
+            listeners[i].onEntry(stateId);
         }
 
     }
 
 
     /**
-     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the 
dialog instance
+     * Inform all registered [EMAIL PROTECTED] DialogContextListener}s that 
the dialog instance
      * execution has exited a particular state.
      *
      * @param stateId Implementation specific identifier of the state
@@ -195,18 +191,16 @@
      */
     protected void fireOnExit(String stateId) {
 
-        synchronized (listeners) {
-            for (int i = 0; i < listeners.size(); i++) {
-                DialogListener listener = (DialogListener) listeners.get(i);
-                listener.onExit(stateId);
-            }
+        DialogContextListener[] listeners = getDialogContextListeners();
+        for (int i = 0; i < listeners.length; i++) {
+            listeners[i].onExit(stateId);
         }
 
     }
 
 
     /**
-     * Inform all registered [EMAIL PROTECTED] DialogListener}s that the 
dialog instance
+     * Inform all registered [EMAIL PROTECTED] DialogContextListener}s that 
the dialog instance
      * execution has followed a particular transition.
      *
      * @param fromStateId Implementation specific identifier of the source
@@ -216,11 +210,9 @@
      */
     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);
-            }
+        DialogContextListener[] listeners = getDialogContextListeners();
+        for (int i = 0; i < listeners.length; i++) {
+            listeners[i].onTransition(fromStateId, toStateId);
         }
 
     }

Copied: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextListener.java
 (from r482329, 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogListener.java)
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextListener.java?view=diff&rev=482364&p1=shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogListener.java&r1=482329&p2=shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextListener.java&r2=482364
==============================================================================
--- 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogListener.java
 (original)
+++ 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextListener.java
 Mon Dec  4 13:25:07 2006
@@ -20,15 +20,15 @@
 import java.io.Serializable;
 
 import org.apache.shale.dialog.DialogContext;
-import org.apache.shale.dialog.DialogListener;
+import org.apache.shale.dialog.DialogContextListener;
 
 /**
- * <p>Convenience abstract [EMAIL PROTECTED] DialogListener} implementation. 
Subclasses
+ * <p>Convenience abstract [EMAIL PROTECTED] DialogContextListener} 
implementation. Subclasses
  * are expected to be serializable.</p>
  *
  * @since 1.0.4
  */
-public abstract class AbstractDialogListener implements DialogListener, 
Serializable {
+public abstract class AbstractDialogContextListener implements 
DialogContextListener, Serializable {
 
     //------------------------------------------------------------- Properties
 
@@ -38,12 +38,12 @@
     private DialogContext dialogContext;
 
 
-    //------------------------------------------------- DialogListener methods
+    //------------------------------------------------- DialogContextListener 
methods
 
     /**
      * [EMAIL PROTECTED]
      *
-     * @see org.apache.shale.dialog.DialogListener#onStart()
+     * @see org.apache.shale.dialog.DialogContextListener#onStart()
      */
     public void onStart() {
 
@@ -54,7 +54,7 @@
     /**
      * [EMAIL PROTECTED]
      *
-     * @see org.apache.shale.dialog.DialogListener#onStop()
+     * @see org.apache.shale.dialog.DialogContextListener#onStop()
      */
     public void onStop() {
 
@@ -65,7 +65,7 @@
     /**
      * [EMAIL PROTECTED]
      *
-     * @see 
org.apache.shale.dialog.DialogListener#onException(java.lang.Exception)
+     * @see 
org.apache.shale.dialog.DialogContextListener#onException(java.lang.Exception)
      */
     public void onException(Exception e) {
 
@@ -76,7 +76,7 @@
     /**
      * [EMAIL PROTECTED]
      *
-     * @see org.apache.shale.dialog.DialogListener#onEntry(java.lang.String)
+     * @see 
org.apache.shale.dialog.DialogContextListener#onEntry(java.lang.String)
      */
     public void onEntry(String stateId) {
 
@@ -87,7 +87,7 @@
     /**
      * [EMAIL PROTECTED]
      *
-     * @see org.apache.shale.dialog.DialogListener#onExit(java.lang.String)
+     * @see 
org.apache.shale.dialog.DialogContextListener#onExit(java.lang.String)
      */
     public void onExit(String stateId) {
 
@@ -98,7 +98,7 @@
     /**
      * [EMAIL PROTECTED]
      *
-     * @see 
org.apache.shale.dialog.DialogListener#onTransition(java.lang.String,java.lang.String)
+     * @see 
org.apache.shale.dialog.DialogContextListener#onTransition(java.lang.String,java.lang.String)
      */
     public void onTransition(String fromStateId, String toStateId) {
 
@@ -109,7 +109,7 @@
     /**
      * [EMAIL PROTECTED]
      *
-     * @see org.apache.shale.dialog.DialogListener#getDialogContext()
+     * @see org.apache.shale.dialog.DialogContextListener#getDialogContext()
      */
     public DialogContext getDialogContext() {
 
@@ -120,7 +120,7 @@
     /**
      * [EMAIL PROTECTED]
      *
-     * @see 
org.apache.shale.dialog.DialogListener#setDialogContext(org.apache.shale.dialog.DialogContext)
+     * @see 
org.apache.shale.dialog.DialogContextListener#setDialogContext(org.apache.shale.dialog.DialogContext)
      */
     public void setDialogContext(DialogContext dialogContext) {
 

Added: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java
URL: 
http://svn.apache.org/viewvc/shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java?view=auto&rev=482364
==============================================================================
--- 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java
 (added)
+++ 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java
 Mon Dec  4 13:25:07 2006
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.dialog.base;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.shale.dialog.DialogContext;
+import org.apache.shale.dialog.DialogContextManager;
+import org.apache.shale.dialog.DialogContextManagerListener;
+
+/**
+ * <p>Abstract base class for [EMAIL PROTECTED] DialogContextManager} 
implementations.
+ * Provides listener registration and event firing convenience methods.</p>
+ *
+ * @since 1.0.4
+ */
+public abstract class AbstractDialogContextManager implements 
DialogContextManager {
+    
+
+    // ------------------------------------------------------ Instance 
Variables
+
+
+    /**
+     * <p><code>List</code> of registered [EMAIL PROTECTED] 
DialogContextManagerListener}
+     * instances.</p>
+     */
+    private List listeners = new ArrayList();
+
+
+    // --------------------------------------------------- Listener 
Registration
+
+
+    /**
+     * <p>Register a new [EMAIL PROTECTED] DialogContextManagerListener} 
instance.</p>
+     *
+     * @param listener The new listener instance to be registered
+     */
+    public void addDialogContextManagerListener(DialogContextManagerListener 
listener) {
+
+        if (listener == null) {
+            throw new IllegalArgumentException("Cannot register null 
DialogContextManagerListener");
+        }
+
+        synchronized (listeners) {
+            if (listeners.contains(listener)) {
+                throw new 
IllegalArgumentException("DialogContextManagerListener already registered");
+            }
+            listener.setDialogContextManager(this); // attach self reference
+            listeners.add(listener);
+        }
+
+    }
+
+
+    /**
+     * <p>Return the set of currently registered [EMAIL PROTECTED] 
DialogContextManagerListener}s.
+     * If there are no registered listeners, a zero-length array is 
returned.</p>
+     */
+    public DialogContextManagerListener[] getDialogContextManagerListeners() {
+
+        synchronized (listeners) {
+            return (DialogContextManagerListener[])
+              listeners.toArray(new 
DialogContextManagerListener[listeners.size()]);
+        }
+
+    }
+
+
+    /**
+     * <p>Deregister an existing [EMAIL PROTECTED] 
DialogContextManagerListener} instance.</p>
+     *
+     * @param listener The existing listener to be deregistered
+     */
+    public void 
removeDialogContextManagerListener(DialogContextManagerListener listener) {
+
+        if (listener == null) {
+            throw new IllegalArgumentException("Cannot remove null 
DialogContextManagerListener");
+        }
+
+        boolean removed;
+        synchronized (listeners) {
+            removed = listeners.remove(listener);
+        }
+        if (removed) {
+            listener.setDialogContextManager(null); // detach self reference
+        }
+
+
+    }
+
+
+    // ---------------------------------------------------- Event Firing 
Methods
+
+
+    /**
+     * <p>Fire an <code>onCreate()</code> event to all registered 
listeners.</p>
+     *
+     * @param context The [EMAIL PROTECTED] DialogContext} instance that has 
been created
+     */
+    protected void fireOnCreate(DialogContext context) {
+
+        DialogContextManagerListener[] listeners =
+          getDialogContextManagerListeners();
+        for (int i = 0; i < listeners.length; i++) {
+            listeners[i].onCreate(context);
+        }
+
+    }
+
+
+    /**
+     * <p>Fire an <code>onRemove()</code> event to all registered 
listeners.</p>
+     *
+     * @param context The [EMAIL PROTECTED] DialogContext} instance that has 
been removed
+     */
+    protected void fireOnRemove(DialogContext context) {
+
+        DialogContextManagerListener[] listeners =
+          getDialogContextManagerListeners();
+        for (int i = 0; i < listeners.length; i++) {
+            listeners[i].onRemove(context);
+        }
+
+    }
+
+
+}

Propchange: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
shale/framework/trunk/shale-dialog/src/main/java/org/apache/shale/dialog/base/AbstractDialogContextManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL


Reply via email to