Author: rahul
Date: Tue Jan  8 12:43:38 2008
New Revision: 610138

URL: http://svn.apache.org/viewvc?rev=610138&view=rev
Log:
Attempt to simplify the NotificationRegistry using a new Observable marker 
interface.
 * NBC (commit message marker to help dig up commits that break compatibility, 
so these can be easily revisited)
 * TODO Use J5 for

Added:
    
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Observable.java
   (with props)
Modified:
    
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/NotificationRegistry.java
    
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
    
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/SCXML.java
    
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Transition.java
    
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java

Modified: 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/NotificationRegistry.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/NotificationRegistry.java?rev=610138&r1=610137&r2=610138&view=diff
==============================================================================
--- 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/NotificationRegistry.java
 (original)
+++ 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/NotificationRegistry.java
 Tue Jan  8 12:43:38 2008
@@ -17,13 +17,14 @@
 package org.apache.commons.scxml;
 
 import java.io.Serializable;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.commons.scxml.model.SCXML;
+import org.apache.commons.scxml.model.Observable;
 import org.apache.commons.scxml.model.Transition;
 import org.apache.commons.scxml.model.TransitionTarget;
 
@@ -46,13 +47,13 @@
     /**
      * The Map of all listeners keyed by Observable.
      */
-    private Map regs = new HashMap();
+    private final Map<Observable, Set<SCXMLListener>> regs;
 
     /**
      * Constructor.
      */
     public NotificationRegistry() {
-        super();
+        this.regs = Collections.synchronizedMap(new HashMap<Observable, 
Set<SCXMLListener>>());
     }
 
     /**
@@ -61,11 +62,10 @@
      * @param source The observable this listener wants to listen to
      * @param lst The listener
      */
-    synchronized void addListener(final Object source,
-            final SCXMLListener lst) {
-        Set entries = (Set) regs.get(source);
+    synchronized void addListener(final Observable source, final SCXMLListener 
lst) {
+        Set<SCXMLListener> entries = regs.get(source);
         if (entries == null) {
-            entries = new HashSet();
+            entries = new HashSet<SCXMLListener>();
             regs.put(source, entries);
         }
         entries.add(lst);
@@ -77,9 +77,8 @@
      * @param source The observable this listener wants to stop listening to
      * @param lst The listener
      */
-    synchronized void removeListener(final Object source,
-            final SCXMLListener lst) {
-        Set entries = (Set) regs.get(source);
+    synchronized void removeListener(final Observable source, final 
SCXMLListener lst) {
+        Set<SCXMLListener> entries = regs.get(source);
         if (entries != null) {
             entries.remove(lst);
             if (entries.size() == 0) {
@@ -92,41 +91,15 @@
      * Inform all relevant listeners that a TransitionTarget has been
      * entered.
      *
-     * @param observable The Observable
-     * @param state The TransitionTarget that was entered
-     */
-    public void fireOnEntry(final TransitionTarget observable,
-            final TransitionTarget state) {
-        Object source = observable;
-        fireOnEntry(source, state);
-    }
-
-    /**
-     * Inform all relevant listeners that a TransitionTarget has been
-     * entered.
-     *
-     * @param observable The Observable
-     * @param state The TransitionTarget that was entered
-     */
-    public void fireOnEntry(final SCXML observable,
-            final TransitionTarget state) {
-        Object source = observable;
-        fireOnEntry(source, state);
-    }
-
-    /**
-     * Inform all relevant listeners that a TransitionTarget has been
-     * entered.
-     *
      * @param source The Observable
      * @param state The TransitionTarget that was entered
      */
-    private synchronized void fireOnEntry(final Object source,
+    public synchronized void fireOnEntry(final Observable source,
             final TransitionTarget state) {
-        Set entries = (Set) regs.get(source);
+        Set<SCXMLListener> entries = regs.get(source);
         if (entries != null) {
-            for (Iterator iter = entries.iterator(); iter.hasNext();) {
-                SCXMLListener lst = (SCXMLListener) iter.next();
+            for (Iterator<SCXMLListener> iter = entries.iterator(); 
iter.hasNext();) {
+                SCXMLListener lst = iter.next();
                 lst.onEntry(state);
             }
         }
@@ -136,41 +109,15 @@
      * Inform all relevant listeners that a TransitionTarget has been
      * exited.
      *
-     * @param observable The Observable
-     * @param state The TransitionTarget that was exited
-     */
-    public void fireOnExit(final TransitionTarget observable,
-            final TransitionTarget state) {
-        Object source = observable;
-        fireOnExit(source, state);
-    }
-
-    /**
-     * Inform all relevant listeners that a TransitionTarget has been
-     * exited.
-     *
-     * @param observable The Observable
-     * @param state The TransitionTarget that was exited
-     */
-    public void fireOnExit(final SCXML observable,
-            final TransitionTarget state) {
-        Object source = observable;
-        fireOnExit(source, state);
-    }
-
-    /**
-     * Inform all relevant listeners that a TransitionTarget has been
-     * exited.
-     *
      * @param source The Observable
      * @param state The TransitionTarget that was exited
      */
-    private synchronized void fireOnExit(final Object source,
+    public synchronized void fireOnExit(final Observable source,
             final TransitionTarget state) {
-        Set entries = (Set) regs.get(source);
+        Set<SCXMLListener> entries = regs.get(source);
         if (entries != null) {
-            for (Iterator iter = entries.iterator(); iter.hasNext();) {
-                SCXMLListener lst = (SCXMLListener) iter.next();
+            for (Iterator<SCXMLListener> iter = entries.iterator(); 
iter.hasNext();) {
+                SCXMLListener lst = iter.next();
                 lst.onExit(state);
             }
         }
@@ -179,48 +126,18 @@
     /**
      * Inform all relevant listeners of a transition that has occured.
      *
-     * @param observable The Observable
-     * @param from The source TransitionTarget
-     * @param to The destination TransitionTarget
-     * @param transition The Transition that was taken
-     */
-    public void fireOnTransition(final Transition observable,
-            final TransitionTarget from, final TransitionTarget to,
-            final Transition transition) {
-        Object source = observable;
-        fireOnTransition(source, from, to, transition);
-    }
-
-    /**
-     * Inform all relevant listeners of a transition that has occured.
-     *
-     * @param observable The Observable
-     * @param from The source TransitionTarget
-     * @param to The destination TransitionTarget
-     * @param transition The Transition that was taken
-     */
-    public void fireOnTransition(final SCXML observable,
-            final TransitionTarget from, final TransitionTarget to,
-            final Transition transition) {
-        Object source = observable;
-        fireOnTransition(source, from, to, transition);
-    }
-
-    /**
-     * Inform all relevant listeners of a transition that has occured.
-     *
      * @param source The Observable
      * @param from The source TransitionTarget
      * @param to The destination TransitionTarget
      * @param transition The Transition that was taken
      */
-    private synchronized void fireOnTransition(final Object source,
+    public synchronized void fireOnTransition(final Observable source,
             final TransitionTarget from, final TransitionTarget to,
             final Transition transition) {
-        Set entries = (Set) regs.get(source);
+        Set<SCXMLListener> entries = regs.get(source);
         if (entries != null) {
-            for (Iterator iter = entries.iterator(); iter.hasNext();) {
-                SCXMLListener lst = (SCXMLListener) iter.next();
+            for (Iterator<SCXMLListener> iter = entries.iterator(); 
iter.hasNext();) {
+                SCXMLListener lst = iter.next();
                 lst.onTransition(from, to, transition);
             }
         }

Modified: 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java?rev=610138&r1=610137&r2=610138&view=diff
==============================================================================
--- 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
 (original)
+++ 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/SCXMLExecutor.java
 Tue Jan  8 12:43:38 2008
@@ -29,6 +29,7 @@
 import org.apache.commons.scxml.model.Datamodel;
 import org.apache.commons.scxml.model.History;
 import org.apache.commons.scxml.model.ModelException;
+import org.apache.commons.scxml.model.Observable;
 import org.apache.commons.scxml.model.SCXML;
 import org.apache.commons.scxml.model.State;
 import org.apache.commons.scxml.model.Transition;
@@ -404,76 +405,23 @@
     }
 
     /**
-     * Add a listener to the document root.
+     * Add a listener to the [EMAIL PROTECTED] Observable}.
      *
-     * @param scxml The document root to attach listener to.
+     * @param observable The [EMAIL PROTECTED] Observable} to attach the 
listener to.
      * @param listener The SCXMLListener.
      */
-    public void addListener(final SCXML scxml, final SCXMLListener listener) {
-        Object observable = scxml;
+    public void addListener(final Observable observable, final SCXMLListener 
listener) {
         scInstance.getNotificationRegistry().addListener(observable, listener);
     }
 
     /**
-     * Remove this listener from the document root.
+     * Remove this listener from the [EMAIL PROTECTED] Observable}.
      *
-     * @param scxml The document root.
+     * @param scxml The [EMAIL PROTECTED] Observable}.
      * @param listener The SCXMLListener to be removed.
      */
-    public void removeListener(final SCXML scxml,
+    public void removeListener(final Observable observable,
             final SCXMLListener listener) {
-        Object observable = scxml;
-        scInstance.getNotificationRegistry().removeListener(observable,
-            listener);
-    }
-
-    /**
-     * Add a listener to this transition target.
-     *
-     * @param transitionTarget The <code>TransitionTarget</code> to
-     *                         attach listener to.
-     * @param listener The SCXMLListener.
-     */
-    public void addListener(final TransitionTarget transitionTarget,
-            final SCXMLListener listener) {
-        Object observable = transitionTarget;
-        scInstance.getNotificationRegistry().addListener(observable, listener);
-    }
-
-    /**
-     * Remove this listener for this transition target.
-     *
-     * @param transitionTarget The <code>TransitionTarget</code>.
-     * @param listener The SCXMLListener to be removed.
-     */
-    public void removeListener(final TransitionTarget transitionTarget,
-            final SCXMLListener listener) {
-        Object observable = transitionTarget;
-        scInstance.getNotificationRegistry().removeListener(observable,
-            listener);
-    }
-
-    /**
-     * Add a listener to this transition.
-     *
-     * @param transition The <code>Transition</code> to attach listener to.
-     * @param listener The SCXMLListener.
-     */
-    public void addListener(final Transition transition,
-            final SCXMLListener listener) {
-        Object observable = transition;
-        scInstance.getNotificationRegistry().addListener(observable, listener);
-    }
-
-    /**
-     * Remove this listener for this transition.
-     *
-     * @param transition The <code>Transition</code>.
-     * @param listener The SCXMLListener to be removed.
-     */
-    public void removeListener(final Transition transition,
-            final SCXMLListener listener) {
-        Object observable = transition;
         scInstance.getNotificationRegistry().removeListener(observable,
             listener);
     }

Added: 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Observable.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Observable.java?rev=610138&view=auto
==============================================================================
--- 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Observable.java
 (added)
+++ 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Observable.java
 Tue Jan  8 12:43:38 2008
@@ -0,0 +1,29 @@
+/*
+ * 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.commons.scxml.model;
+
+/**
+ * Marker interface to flag elements of the SCXML object model whose progress
+ * can be observed using the [EMAIL PROTECTED] NotificationRegistry}. These 
include
+ * individual [EMAIL PROTECTED] TransitionTarget}s, [EMAIL PROTECTED] 
Transition}s or entire state
+ * machines, [EMAIL PROTECTED] SCXML}.
+ *
+ */
+public interface Observable {
+
+}
+

Propchange: 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Observable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Observable.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/SCXML.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/SCXML.java?rev=610138&r1=610137&r2=610138&view=diff
==============================================================================
--- 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/SCXML.java
 (original)
+++ 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/SCXML.java
 Tue Jan  8 12:43:38 2008
@@ -29,7 +29,7 @@
  * root&quot;.
  *
  */
-public class SCXML implements Serializable {
+public class SCXML implements Serializable, Observable {
 
     /**
      * Serial version UID.

Modified: 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Transition.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Transition.java?rev=610138&r1=610137&r2=610138&view=diff
==============================================================================
--- 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Transition.java
 (original)
+++ 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/Transition.java
 Tue Jan  8 12:43:38 2008
@@ -28,7 +28,7 @@
  *
  */
 public class Transition extends Executable
-        implements NamespacePrefixesHolder {
+        implements NamespacePrefixesHolder, Observable {
 
     /**
      * Serial version UID.

Modified: 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java
URL: 
http://svn.apache.org/viewvc/commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java?rev=610138&r1=610137&r2=610138&view=diff
==============================================================================
--- 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java
 (original)
+++ 
commons/proper/scxml/branches/J5/src/main/java/org/apache/commons/scxml/model/TransitionTarget.java
 Tue Jan  8 12:43:38 2008
@@ -25,7 +25,7 @@
  * &lt;target&gt; for a &lt;transition&gt;, such as State or Parallel.
  *
  */
-public abstract class TransitionTarget implements Serializable {
+public abstract class TransitionTarget implements Serializable, Observable {
 
     /**
      * Identifier for this transition target. Other parts of the SCXML


Reply via email to