com.threerings.presents.dobj
Class DynamicListener<T extends DSet.Entry>

java.lang.Object
  extended by com.threerings.presents.dobj.DynamicListener<T>
All Implemented Interfaces:
AttributeChangeListener, ChangeListener, ElementUpdateListener, SetListener<T>

public class DynamicListener<T extends DSet.Entry>
extends Object
implements AttributeChangeListener, ElementUpdateListener, SetListener<T>

Maps distributed object events to methods using reflection.


Field Summary
protected  MethodFinder _finder
          Used to look up methods.
protected  HashMap<String,Method> _mcache
          A cache of already resolved methods.
protected  Object _target
          The object on which we will dynamically dispatch events.
 
Constructor Summary
DynamicListener(Object target)
          Creates a listener that dynamically dispatches events on the supplied target.
DynamicListener(Object target, MethodFinder finder)
          Creates a listener that dynamically dispatches events on the supplied target using the methods in finder.
 
Method Summary
 void attributeChanged(AttributeChangedEvent event)
          Called when an attribute changed event has been dispatched on an object.
 void dispatchMethod(String name, Object[] arguments)
          Dynamically looks up the method in question on our target and dispatches an event if it does.
 void elementUpdated(ElementUpdatedEvent event)
          Called when an element updated event has been dispatched on an object.
 void entryAdded(EntryAddedEvent<T> event)
          Called when an entry added event has been dispatched on an object.
 void entryRemoved(EntryRemovedEvent<T> event)
          Called when an entry removed event has been dispatched on an object.
 void entryUpdated(EntryUpdatedEvent<T> event)
          Called when an entry updated event has been dispatched on an object.
protected  Method resolveMethod(String name, Object[] arguments)
          Looks for a method that matches the supplied signature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_target

protected Object _target
The object on which we will dynamically dispatch events.


_finder

protected MethodFinder _finder
Used to look up methods.


_mcache

protected HashMap<String,Method> _mcache
A cache of already resolved methods.

Constructor Detail

DynamicListener

public DynamicListener(Object target)
Creates a listener that dynamically dispatches events on the supplied target.


DynamicListener

public DynamicListener(Object target,
                       MethodFinder finder)
Creates a listener that dynamically dispatches events on the supplied target using the methods in finder.

Method Detail

attributeChanged

public void attributeChanged(AttributeChangedEvent event)
Description copied from interface: AttributeChangeListener
Called when an attribute changed event has been dispatched on an object. This will be called after the event has been applied to the object. So fetching the attribute during this call will provide the new value for the attribute.

Specified by:
attributeChanged in interface AttributeChangeListener
Parameters:
event - The event that was dispatched on the object.

elementUpdated

public void elementUpdated(ElementUpdatedEvent event)
Description copied from interface: ElementUpdateListener
Called when an element updated event has been dispatched on an object. This will be called after the event has been applied to the object. So fetching the element during this call will provide the new value for the element.

Specified by:
elementUpdated in interface ElementUpdateListener
Parameters:
event - The event that was dispatched on the object.

entryAdded

public void entryAdded(EntryAddedEvent<T> event)
Description copied from interface: SetListener
Called when an entry added event has been dispatched on an object. This will be called after the event has been applied to the object.

Specified by:
entryAdded in interface SetListener<T extends DSet.Entry>
Parameters:
event - The event that was dispatched on the object.

entryUpdated

public void entryUpdated(EntryUpdatedEvent<T> event)
Description copied from interface: SetListener
Called when an entry updated event has been dispatched on an object. This will be called after the event has been applied to the object.

Specified by:
entryUpdated in interface SetListener<T extends DSet.Entry>
Parameters:
event - The event that was dispatched on the object.

entryRemoved

public void entryRemoved(EntryRemovedEvent<T> event)
Description copied from interface: SetListener
Called when an entry removed event has been dispatched on an object. This will be called after the event has been applied to the object.

Specified by:
entryRemoved in interface SetListener<T extends DSet.Entry>
Parameters:
event - The event that was dispatched on the object.

dispatchMethod

public void dispatchMethod(String name,
                           Object[] arguments)
Dynamically looks up the method in question on our target and dispatches an event if it does.


resolveMethod

protected Method resolveMethod(String name,
                               Object[] arguments)
Looks for a method that matches the supplied signature.