Public (stephenh@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.

Review at http://gwt-code-reviews.appspot.com/1450802

Review by: jlabanca@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10214 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/web/bindery/event/shared/Event.java b/user/src/com/google/web/bindery/event/shared/Event.java
index 487771f..bf28e5b 100644
--- a/user/src/com/google/web/bindery/event/shared/Event.java
+++ b/user/src/com/google/web/bindery/event/shared/Event.java
@@ -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;
diff --git a/user/src/com/google/web/bindery/event/shared/EventBus.java b/user/src/com/google/web/bindery/event/shared/EventBus.java
index 91ed3dc..79c8dac 100644
--- a/user/src/com/google/web/bindery/event/shared/EventBus.java
+++ b/user/src/com/google/web/bindery/event/shared/EventBus.java
@@ -31,6 +31,26 @@
 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.
    * <p>
    * It is rare to call this method directly. More typically an {@link Event}
@@ -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);
diff --git a/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java b/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java
index 14a1f3c..7e33728 100644
--- a/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java
+++ b/user/src/com/google/web/bindery/event/shared/SimpleEventBus.java
@@ -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>();