public abstract class ERXMulticastingDelegate extends Object
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.
Constructor and Description |
---|
ERXMulticastingDelegate() |
Modifier and Type | Method and Description |
---|---|
void |
addDelegate(Object delegate)
Adds
delegate at the end of the chain. |
void |
addDelegateAtStart(Object delegate)
Adds
delegate at the start of the chain. |
protected boolean |
booleanPerform(String methodName,
boolean defaultResult) |
protected boolean |
booleanPerform(String methodName,
Object[] args,
boolean defaultResult) |
protected boolean |
booleanPerform(String methodName,
Object arg,
boolean defaultResult) |
protected boolean |
booleanPerform(String methodName,
Object arg1,
Object arg2,
boolean defaultResult) |
protected boolean |
booleanPerform(String methodName,
Object arg1,
Object arg2,
Object arg3,
boolean defaultResult) |
NSArray |
delegates()
This method returns an array of
com.webobjects.foundation._NSDelegate , not
the delegate objects originally added by calling addDelegate... |
boolean |
hasDelegate(Object delegate)
Returns
true if delegate is represented in delegates(). |
protected Object |
perform(String methodName,
Object defaultResult) |
protected Object |
perform(String methodName,
Object[] args,
Object defaultResult)
This is the central method for dispatching messages to the delegates aggregated by this object.
|
protected Object |
perform(String methodName,
Object arg,
Object defaultResult) |
protected Object |
perform(String methodName,
Object arg1,
Object arg2,
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 arg3,
Object arg4,
Object arg5,
Object defaultResult) |
void |
removeDelegate(Object delegate)
Removes
delegate from the delegates called. |
void |
setDelegateOrder(NSArray orderedDelegates)
Use this to set the delegate order if the addDelegate...
|
public void addDelegate(Object delegate)
delegate
at the end of the chain. It becomes the last delegate called.delegate
- Object to add as one of the delegates calledpublic void addDelegateAtStart(Object delegate)
delegate
at the start of the chain. It becomes the first delegate called.delegate
- Object to add as one of the delegates calledpublic void removeDelegate(Object delegate)
delegate
from the delegates called.delegate
- Object to remove as one of the delegates calledpublic boolean hasDelegate(Object delegate)
true
if delegate is represented in delegates().delegate
- Object to test for membership in delegates()true
if delegate is represented in delegates()public NSArray delegates()
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...public void setDelegateOrder(NSArray orderedDelegates)
orderedDelegates
should be a re-arrangement of the list returned by delegates()
.orderedDelegates
- array of com.webobjects.foundation._NSDelegate
in the order in which delegates should be calledprotected Object perform(String methodName, Object[] args, Object defaultResult)
methodName
- the name of the delegate method to callargs
- 0 or more arguments to pass to the delegate methoddefaultResult
- the value to return if none of the delegates implement this methodprotected Object perform(String methodName, Object arg1, Object arg2, Object arg3, Object defaultResult)
protected Object perform(String methodName, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object defaultResult)
protected boolean booleanPerform(String methodName, boolean defaultResult)
protected boolean booleanPerform(String methodName, Object arg, boolean defaultResult)
protected boolean booleanPerform(String methodName, Object arg1, Object arg2, boolean defaultResult)
protected boolean booleanPerform(String methodName, Object arg1, Object arg2, Object arg3, boolean defaultResult)
Copyright © 2002 – 2024 Project Wonder.