I think you'll probably end up implementing your own version of a map
that would look something like this:
Map<Class<?>, List<Listener<?>> handledEventClasses;
<T extends Event> List<Listener<T>> get(Class<T> eventClass) {
List<Listenter<T>> result = new ArrayList<Listener<T>>
for ( Entry<Class<T>, List<Listener<T> entry :
handledEventClasses.entrySet() ) {
if ( eventClass.isAssignableFrom(entry.getKey()) {
result.addAll((List<Listener<T>>)entry.getValue());
}
}
return result;
}
Of course, I neglect any null checking, and I don't know if that will
compile or not, but I think you can follow the basic logic.
Also, this method will probably need to be better optimized since it
runs in linear time according to the number of event classes you
register. This could be done by making the put method intelligent
enough to put the listeners into bins for each class you register.
On Feb 19, 4:43 am, Chris Lercher <[email protected]> wrote:
> The JRE Emulation Reference says, that getSuperclass() is
> supported.http://code.google.com/webtoolkit/doc/latest/RefJreEmulation.html
> Maybe you can make do with this?
>
> Chris
>
> On Feb 19, 3:58 am, Dominik Steiner <[email protected]>
> wrote:
>
>
>
> > Hi there,
>
> > I'm trying to implement an event bus that will receive register
> > listeners like this
>
> > public <T extends Event> void registerListener(Class<T>
> > eventClassname, EventListener<T> eventListener);
> > (Event is a custom interface)
>
> > what i would like then to achieve would be to be able to fire an event
>
> > public void fireEvent(Event event);
>
> > and be able to trigger all my event listeners that either are of the
> > same event.getClass() or that are assignable from the event class that
> > has been fired. Getting all the listeners that correspond to the event
> > class itself is no problem, but how can i achieve getting all the
> > listeners that registered to a interface that the event class might
> > implement without being able to use Class.isAssignableFrom()?
>
> > Thanks for any hints and help in advance.
>
> > Dominik
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.