Reviewers: jlabanca,

Description:
Public (steph...@gmail.com):

Adds two protected static methods to EventBus that expose otherwise
inaccessible methods on Event (setSource and dispatch) to subclasses
of EventBus. Allows alternative EventBus implementations without
muddying the public API events show to handlers.

Tweaks the original patch (1443804) by making SimpleEventBus use the
new methods, and updating javadoc and a method name.


Please review this at http://gwt-code-reviews.appspot.com/1450802/

Affected files:
  M user/src/com/google/web/bindery/event/shared/Event.java
  M user/src/com/google/web/bindery/event/shared/EventBus.java
  M user/src/com/google/web/bindery/event/shared/SimpleEventBus.java


Index: user/src/com/google/web/bindery/event/shared/Event.java
===================================================================
--- user/src/com/google/web/bindery/event/shared/Event.java     (revision 10204)
+++ user/src/com/google/web/bindery/event/shared/Event.java     (working copy)
@@ -106,9 +106,10 @@
   /**
    * Implemented by subclasses to to invoke their handlers in a type safe
    * manner. Intended to be called by {@link EventBus#fireEvent(Event)} or
-   * {@link EventBus#fireEventFromSource(Event, Object)}.
+   * {@link EventBus#fireEventFromSource(Event, Object)}.
    *
    * @param handler handler
+   * @see EventBus#dispatchEvent(Event, Object)
    */
   protected abstract void dispatch(H handler);

@@ -118,6 +119,7 @@
    *
    * @param source the source of this event.
    * @see EventBus#fireEventFromSource(Event, Object)
+   * @see EventBus#setSourceOfEvent(Event, Object)
    */
   protected void setSource(Object source) {
     this.source = source;
Index: user/src/com/google/web/bindery/event/shared/EventBus.java
===================================================================
--- user/src/com/google/web/bindery/event/shared/EventBus.java (revision 10204) +++ user/src/com/google/web/bindery/event/shared/EventBus.java (working copy)
@@ -29,6 +29,26 @@
  * @see com.google.web.bindery.event.shared.testing.CountingEventBus
  */
 public abstract class EventBus {
+
+  /**
+   * Invokes {@code event.dispatch} with {@code handler}.
+   * <p>
+   * Protected to allow EventBus implementations in different packages to
+ * dispatch events even though the {@code event.dispatch} method is protected.
+   */
+  protected static <H> void dispatchEvent(Event<H> event, H handler) {
+    event.dispatch(handler);
+  }
+
+  /**
+   * Sets {@code source} as the source of {@code event}.
+   * <p>
+ * Protected to allow EventBus implementations in different packages to set an + * event source even though the {@code event.setSource} method is protected.
+   */
+  protected static void setSourceOfEvent(Event<?> event, Object source) {
+    event.setSource(source);
+  }

   /**
* Adds an unfiltered handler to receive events of this type from all sources.
@@ -70,7 +90,7 @@
    * from executing.
    *
    * @throws UmbrellaException wrapping exceptions thrown by handlers
-   *
+   *
    * @param event the event to fire
    */
   public abstract void fireEvent(Event<?> event);
Index: user/src/com/google/web/bindery/event/shared/SimpleEventBus.java
===================================================================
--- user/src/com/google/web/bindery/event/shared/SimpleEventBus.java (revision 10204) +++ user/src/com/google/web/bindery/event/shared/SimpleEventBus.java (working copy)
@@ -178,7 +178,7 @@
       firingDepth++;

       if (source != null) {
-        event.setSource(source);
+        setSourceOfEvent(event, source);
       }

List<H> handlers = getDispatchList(event.getAssociatedType(), source);
@@ -190,7 +190,7 @@
         H handler = isReverseOrder ? it.previous() : it.next();

         try {
-          event.dispatch(handler);
+          dispatchEvent(event, handler);
         } catch (Throwable e) {
           if (causes == null) {
             causes = new HashSet<Throwable>();


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to