sunw.demo.encapsulatedEvents
Class EncapsulatedEventAdaptor

java.lang.Object
  |
  +--sunw.demo.encapsulatedEvents.EncapsulatedEventAdaptor

public abstract class EncapsulatedEventAdaptor
extends java.lang.Object

sunw.demo.encapsulatedEvents.EncapsulatedEventAdaptor is an abstract base class designed to support the dynamic generation of java.util.EventListener sub-interface adaptor classes.

These dynamically generated adaptor classes can be used to take arbitrary events and "wrap" them in sunw.demo.encapsulatedEvent.EncapsulatedEvent objects. These "encapsulated" events are then fired on the sunw.demo.encapsulatedEventListener interface.

Using this dynamic adaptor class, objects that emits events on arbitrary` sub-interfaces of java.util.EventListener can be encapsulated and delivered onto a single EventListener interface, this allowing late binding of event behaviors and filtering applications.


Field Summary
protected  java.lang.reflect.Method addAdaptorMethod
          The Event Source's addListener method
protected  java.util.Vector listeners
           
protected  java.lang.reflect.Method removeAdaptorMethod
          The Event Source's removeListener method
protected  java.lang.Object source
          The Event Source
 
Constructor Summary
protected EncapsulatedEventAdaptor()
           default constructor.
 
Method Summary
protected  void addAdaptorToSource()
          Adds this Adaptor to the Event Source
 void addEncapsulatedEventListener(EncapsulatedEventListener el)
           
protected  void fire(EventObject e, java.lang.reflect.Method lm)
           This method is called from simple EventListener method stubs of dynamic subclasses in order to create and EncapsulatedEvent and deliver it to the registered listeners.
protected  void fire(java.lang.Object[] a, java.lang.reflect.Method lm)
           This method is called from cracked EventListener method stubs of dynamic subclasses in order to create and EncapsulatedEvent and deliver it to the registered listeners.
static EncapsulatedEventAdaptor getEncapsulatedEventAdaptor(java.lang.Class lc, java.lang.Object s)
          Generate an Adaptor instance for the Listener Interface and Event Source
static java.lang.Class getEncapsulatedEventAdaptorClass(java.lang.Class lc)
           
 int getEncapsulatedListenerCount()
           
 java.util.Vector getEncapsulatedListeners()
           
abstract  java.lang.Class getListenerClass()
           
 java.lang.String getListenerClassName()
           
 java.lang.Object getSource()
           
protected  void handleEncapsulatedEventException(EncapsulatedEventException ex, EncapsulatedEventListener eel, java.lang.reflect.Method lm)
           EncapsulatedEventListener's may raise exceptions to the originating event source through an adaptor by throwing the actual exception within an instance of EncapsulatedEventException.
protected  void removeAdaptorFromSource()
          Removes this Adaptor instance from the Event Source
 void removeEncapsulatedEventListener(EncapsulatedEventListener el)
           
 void setSource(java.lang.Object s)
           setSource sets the adaptor instance to listen to the specified source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

source

protected java.lang.Object source
The Event Source

addAdaptorMethod

protected java.lang.reflect.Method addAdaptorMethod
The Event Source's addListener method

removeAdaptorMethod

protected java.lang.reflect.Method removeAdaptorMethod
The Event Source's removeListener method

listeners

protected java.util.Vector listeners
Constructor Detail

EncapsulatedEventAdaptor

protected EncapsulatedEventAdaptor()

default constructor.

Method Detail

getEncapsulatedEventAdaptor

public static EncapsulatedEventAdaptor getEncapsulatedEventAdaptor(java.lang.Class lc,
                                                                   java.lang.Object s)
                                                            throws java.lang.ClassNotFoundException,
                                                                   java.lang.InstantiationException,
                                                                   java.lang.IllegalAccessException,
                                                                   java.beans.IntrospectionException
Generate an Adaptor instance for the Listener Interface and Event Source
Parameters:
lc - The java.lang.Class object for the listener to adapt.
s - The source object that the adaptor will listen to.
Returns:
The newly instantiated dynamic adaptor
Throws:
java.lang.ClassNotFoundException -  
java.lang.IllegalArgumentException -  

getEncapsulatedEventAdaptorClass

public static java.lang.Class getEncapsulatedEventAdaptorClass(java.lang.Class lc)
                                                        throws java.lang.ClassNotFoundException
Parameters:
lc - The java.lang.Class object for the listener to adapt.
Returns:
The Class object for the newly generated dynamic adaptor class.

getListenerClass

public abstract java.lang.Class getListenerClass()
Returns:
the java.lang.Class object for the java.util.EventListener subinterface this instance adapts.

getListenerClassName

public java.lang.String getListenerClassName()
Returns:
the name of the java.util.EventListener subinterface this instance adapts.

getSource

public java.lang.Object getSource()
Returns:
the event source object that this instance is adapting.

setSource

public void setSource(java.lang.Object s)
               throws java.beans.IntrospectionException,
                      java.lang.Exception

setSource sets the adaptor instance to listen to the specified source. This operation will fail if the source does not emit events on the EventListener subinterface this adaptor implements.

Parameters:
s - the prospective event source.
Throws:
java.beans.IntrospectionException -  

addEncapsulatedEventListener

public void addEncapsulatedEventListener(EncapsulatedEventListener el)
Parameters:
el - Adds the EncapsulatedEventListener to the listeners for this adaptor

removeEncapsulatedEventListener

public void removeEncapsulatedEventListener(EncapsulatedEventListener el)
Parameters:
el - Removes the EncapsulatedEventListener to the listeners for this adaptor

getEncapsulatedListenerCount

public int getEncapsulatedListenerCount()

getEncapsulatedListeners

public java.util.Vector getEncapsulatedListeners()

fire

protected void fire(EventObject e,
                    java.lang.reflect.Method lm)
             throws java.lang.Exception

This method is called from simple EventListener method stubs of dynamic subclasses in order to create and EncapsulatedEvent and deliver it to the registered listeners.

Parameters:
e - The EventObject being encapsulated
lm - The jav.lang.reflect.Method describing the listener Method.
Throws:
java.lang.Exception -  
java.lang.RuntimeException -  

fire

protected void fire(java.lang.Object[] a,
                    java.lang.reflect.Method lm)
             throws java.lang.Exception

This method is called from cracked EventListener method stubs of dynamic subclasses in order to create and EncapsulatedEvent and deliver it to the registered listeners.

Parameters:
a - The cracked Event arguments being encapsulated
lm - The jav.lang.reflect.Method describing the listener Method.
Throws:
java.lang.Exception -  
java.lang.RuntimeException -  

handleEncapsulatedEventException

protected final void handleEncapsulatedEventException(EncapsulatedEventException ex,
                                                      EncapsulatedEventListener eel,
                                                      java.lang.reflect.Method lm)
                                               throws java.lang.Exception

EncapsulatedEventListener's may raise exceptions to the originating event source through an adaptor by throwing the actual exception within an instance of EncapsulatedEventException.

This method is called to verify that it is allowable to re-raise the exception from the adaptor to the source, by checking that the listener method on the adaptor that the source delivered the original event to is permitted to throw such an exception, otherwise a RuntimeException is raised.

Parameters:
ex - the exception thrown by the listener
eel - the listener instance that threw it
lm - the adaptors listener method that must re-raise it

addAdaptorToSource

protected void addAdaptorToSource()
Adds this Adaptor to the Event Source

removeAdaptorFromSource

protected void removeAdaptorFromSource()
Removes this Adaptor instance from the Event Source