oranjestad.commons.beanutils.messaging
Class Channel

java.lang.Object
  extended by oranjestad.commons.beanutils.messaging.Channel
All Implemented Interfaces:
java.io.Serializable

public class Channel
extends java.lang.Object
implements java.io.Serializable

A Channel defines a means by which a bean sends notifications via a listener interface.

A Channel is typically inferred by two pairs of methods with the following signatures.


 public void addChannelName(ListenerInterface);
 public void/boolean removeChannelName)(ListenerInterface);
 

Since:
1.0
Author:
Bryant Harris
See Also:
Serialized Form

Constructor Summary
Channel()
           
 
Method Summary
 boolean equals(java.lang.Object o)
           
protected  java.lang.reflect.Method[] findSameNameLength(java.lang.Object producer, java.lang.reflect.Method originalMethod, java.lang.Object[] args, int listenerIndex)
          Internal method that searches for an add method that has the same name and number of arguments.
protected  java.lang.reflect.Method[] findSameNameSignature(java.lang.Object producer, java.lang.reflect.Method originalMethod, java.lang.Object[] args)
          Method for searching for a method with the same name but a different signature.
 java.lang.reflect.Method getAddListenerMethod()
           
 java.lang.reflect.Method getAddListenerMethod(java.lang.Object producer, java.lang.Object[] args, int listenerIndex)
          Method that tries to match the add-listener method with the supplied parameters.
 java.lang.Class<?> getListenerInterface()
          Gets the listener class that is parameter passed into the add and remove methods.
 java.lang.String getName()
           
 java.lang.reflect.Method getRemoveListenerMethod()
           
 int hashCode()
           
 void setAddListenerMethod(java.lang.reflect.Method method)
          Sets the add listener method (typically called during introspectoin).
 void setListenerInterface(java.lang.Class listenerInterface)
          Sets the listener interface (typically called during introspection).
 void setName(java.lang.String name)
          Sets the channel name (typically called during introspection).
 void setRemoveListenerMethod(java.lang.reflect.Method method)
          Sets the remove listener method (typically called during introspection).
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Channel

public Channel()
Method Detail

getName

public java.lang.String getName()
Returns:
The name of this channel.
Since:
1.0

setName

public void setName(java.lang.String name)
Sets the channel name (typically called during introspection).

Parameters:
name - Channel name.
Since:
1.0

getAddListenerMethod

public java.lang.reflect.Method getAddListenerMethod()
Returns:
The add listener method
Since:
1.0

getAddListenerMethod

public java.lang.reflect.Method getAddListenerMethod(java.lang.Object producer,
                                                     java.lang.Object[] args,
                                                     int listenerIndex)
Method that tries to match the add-listener method with the supplied parameters. This accounts for the case when there are multple add methods with different signatures.

Parameters:
producer - The producer to search for the method on.
args - The arguments to match against.
listenerIndex - The index of the listener (as supplied by caller).
Returns:
The add method.
Throws:
java.lang.IllegalArgumentException - if no method can be found.
Since:
1.3

setAddListenerMethod

public void setAddListenerMethod(java.lang.reflect.Method method)
Sets the add listener method (typically called during introspectoin).

Parameters:
method - Add listener method.
Since:
1.0

getRemoveListenerMethod

public java.lang.reflect.Method getRemoveListenerMethod()
Returns:
the remove listener method
Since:
1.0

setRemoveListenerMethod

public void setRemoveListenerMethod(java.lang.reflect.Method method)
Sets the remove listener method (typically called during introspection).

Parameters:
method - The remove listener method.
Since:
1.0

getListenerInterface

public java.lang.Class<?> getListenerInterface()
Gets the listener class that is parameter passed into the add and remove methods.

Returns:
The listener interface class.
Since:
1.0

setListenerInterface

public void setListenerInterface(java.lang.Class listenerInterface)
Sets the listener interface (typically called during introspection).

Parameters:
listenerInterface - The listener interface.
Since:
1.0

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

findSameNameSignature

protected java.lang.reflect.Method[] findSameNameSignature(java.lang.Object producer,
                                                           java.lang.reflect.Method originalMethod,
                                                           java.lang.Object[] args)

Method for searching for a method with the same name but a different signature.

Parameters:
producer - The producer to search for the method on.
originalMethod - The original method (whose signature doesn't match).
args - The arguments.
Returns:
An array of matching methods (hopefully of size 1).
Since:
1.3

findSameNameLength

protected java.lang.reflect.Method[] findSameNameLength(java.lang.Object producer,
                                                        java.lang.reflect.Method originalMethod,
                                                        java.lang.Object[] args,
                                                        int listenerIndex)

Internal method that searches for an add method that has the same name and number of arguments. Also, if the listenerIndex is supplied (i.e. greather than -1) then all parameters other than the listener index must match.

The listener index can potentially not match because a generic listener could be used to wrap this listener and adapt methods to invoke into an aribtrary listener.

Parameters:
producer - The producer of messages.
originalMethod - The original (default) add listener method.
args - The arguments to the add method being invoked.
listenerIndex - The index of the listener in the args array. This might be a negative number if the listener is unknown.
Returns:
All the methods that have the same name and same number of parameters.
Since:
1.3


Copyright © 2008. All Rights Reserved.