ERXMulticastingDelegate Class Reference

Inherited by ERXDatabaseContextMulticastingDelegate.

Collaboration diagram for ERXMulticastingDelegate:

Collaboration graph
[legend]

List of all members.

Public Member Functions

void addDelegate (Object delegate)
void addDelegateAtStart (Object delegate)
NSArray delegates ()
boolean hasDelegate (Object delegate)
void removeDelegate (Object delegate)
void setDelegateOrder (NSArray orderedDelegates)

Protected Member Functions

boolean booleanPerform (String methodName, Object args[], boolean defaultResult)
boolean booleanPerform (String methodName, Object arg1, Object arg2, Object arg3, boolean defaultResult)
boolean booleanPerform (String methodName, Object arg1, Object arg2, boolean defaultResult)
boolean booleanPerform (String methodName, Object arg, boolean defaultResult)
boolean booleanPerform (String methodName, boolean defaultResult)
Object perform (String methodName, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object defaultResult)
Object perform (String methodName, Object arg1, Object arg2, Object arg3, Object defaultResult)
Object perform (String methodName, Object arg1, Object arg2, Object defaultResult)
Object perform (String methodName, Object arg, Object defaultResult)
Object perform (String methodName, Object defaultResult)
Object perform (String methodName, Object args[], Object defaultResult)

Private Attributes

NSMutableArray delegates = new NSMutableArray()


Detailed Description

By design, WebObjects' classes that accept a delegate only accept a single object. ERXMulticastingDelegate allows multiple delegate objects to be aggregated and presented as a single delegate object.

Delegates are called in the order they are added. Methods are called until one of the delegates handles the message. Delegate methods that have a Object or boolean return type are called until one returns a non-null response that is not the default value. Delegate methods that have a void return type are always called.

Here is an example if you have multiple delegates that you want to set up.

 ERXDatabaseContextMulticastingDelegate multiDelegate = new ERXDatabaseContextMulticastingDelegate();
 multiDeletegate.addDelegate(new ERXDatabaseContextDelegate());
 multiDeletegate.addDelegate(new ERXEntityDependencyOrderingDelegate());
 EODatabaseContext.setDefaultDelegate(multiDelegate);
 

Here is a usage example to handle the case where a deletegate may already be set

 Object newDelegate = new ERXEntityDependencyOrderingDelegate();
 ERXDatabaseContextMulticastingDelegate multiDelegate;
 if (EODatabaseContext.defaultDelegate() == null) {
     multiDelegate = new ERXDatabaseContextMulticastingDelegate();
 }
 else {
     if (EODatabaseContext.defaultDelegate() instanceof ERXDatabaseContextMulticastingDelegate) {
            multiDelegate = (ERXDatabaseContextMulticastingDelegate)EODatabaseContext.defaultDelegate();
     }
     else {
         multiDelegate = new ERXDatabaseContextMulticastingDelegate();
         multiDelegate.addDelegate(EODatabaseContext.defaultDelegate());
     }
 }
 multiDelegate.addDelegate(newDelegate);
 EODatabaseContext.setDefaultDelegate(multiDelegate);
 

This class needs to be implemented for each delegate interface. All methods on the interface should be implemented and should call one of the perform... or booleanPerform... methods on this class. See ERXDatabaseContextMulticastingDelegate for example usage. One result of this implementation is that delegates can be added and removed at any time.

Author:
chill

Member Function Documentation

void addDelegate ( Object  delegate  ) 

Adds delegate at the end of the chain. It becomes the last delegate called.

Parameters:
delegate Object to add as one of the delegates called

void addDelegateAtStart ( Object  delegate  ) 

Adds delegate at the start of the chain. It becomes the first delegate called.

Parameters:
delegate Object to add as one of the delegates called

boolean booleanPerform ( String  methodName,
Object  args[],
boolean  defaultResult 
) [protected]

boolean booleanPerform ( String  methodName,
Object  arg1,
Object  arg2,
Object  arg3,
boolean  defaultResult 
) [protected]

boolean booleanPerform ( String  methodName,
Object  arg1,
Object  arg2,
boolean  defaultResult 
) [protected]

boolean booleanPerform ( String  methodName,
Object  arg,
boolean  defaultResult 
) [protected]

boolean booleanPerform ( String  methodName,
boolean  defaultResult 
) [protected]

NSArray delegates (  ) 

This method returns an array of com.webobjects.foundation._NSDelegate, not the delegate objects originally added by calling addDelegate... Call delegate() on the elements in this list to examine the delegate objects originally added by calling addDelegate...

Returns:
the delegates in the order they will be called

boolean hasDelegate ( Object  delegate  ) 

Returns true if delegate is represented in delegates().

Parameters:
delegate Object to test for membership in delegates()
Returns:
true if delegate is represented in delegates()

Object perform ( String  methodName,
Object  arg1,
Object  arg2,
Object  arg3,
Object  arg4,
Object  arg5,
Object  defaultResult 
) [protected]

Object perform ( String  methodName,
Object  arg1,
Object  arg2,
Object  arg3,
Object  defaultResult 
) [protected]

Object perform ( String  methodName,
Object  arg1,
Object  arg2,
Object  defaultResult 
) [protected]

Object perform ( String  methodName,
Object  arg,
Object  defaultResult 
) [protected]

Object perform ( String  methodName,
Object  defaultResult 
) [protected]

Object perform ( String  methodName,
Object  args[],
Object  defaultResult 
) [protected]

This is the central method for dispatching messages to the delegates aggregated by this object. The other perform... and booleanPerform... methods simply call this method.

Parameters:
methodName the name of the delegate method to call
args 0 or more arguments to pass to the delegate method
defaultResult the value to return if none of the delegates implement this method
Returns:
value returned by the last delegate called

void removeDelegate ( Object  delegate  ) 

Removes delegate from the delegates called.

Parameters:
delegate Object to remove as one of the delegates called

void setDelegateOrder ( NSArray  orderedDelegates  ) 

Use this to set the delegate order if the addDelegate... methods are not sufficient. orderedDelegates should be a re-arrangement of the list returned by delegates().

Parameters:
orderedDelegates array of com.webobjects.foundation._NSDelegate in the order in which delegates should be called


Member Data Documentation


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:13 2012 for Project Wonder by  doxygen 1.5.8