Packages
 In this topic

*Constructors

*Methods

 

Packages   PreviousThis PackageNext
Package com.ms.lang   Previous This
Package
Next

 


Class Delegate

public abstract class Delegate implements java.lang.Cloneable
{
  // Constructors
  protected Delegate(Object objTarget, String strMethodName,
        String strMethodSignature);

  // Methods
  public boolean equals(Object objOther);
  public Object clone();
  public int hashCode();
  public final Method getMethod();
  public final Object getTarget();
  protected Delegate combine(Delegate delTail)
        throws MulticastNotSupportedException;
  protected Delegate remove(Delegate delValue);
  public static final Delegate combine(Delegate delA, Delegate delB);
  public static final Delegate combine(Delegate[] rgDelegates);
  public static final Delegate remove(Delegate delSource,
        Delegate delValue);
  public Delegate[] getInvocationList();
  protected final Object invokeHelper(Object[] args) throws Throwable;
  public final Object dynamicInvoke(Object[] args)
        throws IllegalArgumentException, InvocationTargetException;
}

This class provides support for Delegates.

Constructors

Delegate

protected Delegate(Object objTarget, String strMethodName,
        String strMethodSignature);

Constructs a delegate that references a given object and a given method of that object. Since Delegate is an abstract class, subclasses of Delegate implement a constructor with the same parameters and call this inherited constructor. The methodName parameter must denote a method in the target object with a signature that is identical to the "invoke" method of the specific delegate implementation. If this is not the case, a RuntimeException is thrown.

ParameterDescription
objTargetthe target object of the delegate.
strMethodNameThe name of the target method of the delegate.
strMethodSignatureThe signature of the target method of the delegate.

Methods

clone

public Object clone();

Creates a copy of this delegate.

Return Value

Returns a copy of this delegate

combine

protected Delegate combine(Delegate delTail)
        throws MulticastNotSupportedException;

Combines this Delegate with the given Delegate. This method is overridden in the MulticastDelegate class to support multicasting.

combine

public static final Delegate combine(Delegate delA, Delegate delB);

Combines the two given Delegates to form a single Delegate. If both a and b are null, the result is null. If either a or b is null, the result is the non-null Delegate. If neither a nor b is null, the result is a new Delegate with an invocation list formed by concatenating the invocation lists of a and b, in that order. It is not considered an error for the invocation list to contain duplicate entries, that is, entries that refer to the same method on the same object. If neither a nor b is null, but a and b are of different actual types, an IllegalArgumentException is thrown. If neither a nor b is null, and a and b are of the same actual type, but that type doesn't derive from MulticastDelegate, a MulticastNotSupportedException exception is thrown.

combine

public static final Delegate combine(Delegate[] rgDelegates);

Combines the Delegates given by the Delegates array parameter to form a single Delegate with an invocation list consisting of the concatenation of the invocation lists of each of the Delegates in the array in order. The Delegates in the array must all be of the same actual type. The array may contain null entries, which are ignored. If the array parameter is null or empty, or if the resulting invocation list is empty, the result is null. If the Delegates in the array are not all of the same actual type, an IllegalArgumentException is thrown. If the Delegates in the array are of a type that doesn't derive from MulticastDelegate, and if the resulting invocation list would have more than one entry, a MulticastNotSupportedException exception is thrown.

dynamicInvoke

public final Object dynamicInvoke(Object[] args)
        throws IllegalArgumentException, InvocationTargetException;

Invokes the target method referenced by the delegate on the target object referenced by the delegate with the given parameters. The parameters must be packaged as an Object array according to the rules of Java Reflection. For a delegate with a void return type, "dynamicInvoke" returns null. For other return types, "dynamicInvoke" returns an Object that must be unwrapped or typecast to produce a correctly typed value.

equals

public boolean equals(Object objOther);

The result is true if and only if the argument is not null and is a Delegate object that has the same target and method as this Delegate object.

Note that two delegates do not need to be of the same type in order to equal one another, as defined by Delegate.equals().

getInvocationList

public Delegate[] getInvocationList();

Returns the invocation list of this Delegate. For unicast Delegates, the result is always an array with a single element. For multicast Delegates, the resulting array may have more than one element. The invocation list of each of the elements in the returned array is guaranteed to have only one entry.

getMethod

public final Method getMethod();

Returns the method referenced by this delegate.

getTarget

public final Object getTarget();

Returns the target object referenced by this delegate. The returned value is null if the delegate references a static method.

hashCode

public int hashCode();

Returns a hash code for this Delegate. If two Delegates compare equals according to Delegate.equals, they will have the same hash code.

invokeHelper

protected final Object invokeHelper(Object[] args) throws Throwable;

Invokes the target method referenced by the delegate on the target object referenced by the delegate with the given parameters. The parameters must be packaged as an Object array according to the rules of Java Reflection. For a delegate with a void return type, "invokeMethod" returns null. For other return types, "invokeMethod" returns an Object that must be unwrapped or typecast to produce a correctly typed value.

remove

protected Delegate remove(Delegate delValue);

Returns a Delegate with an invocation list formed by removing the last occurrence (if any) of the Delegate given by the value parameter from the invocation list of this Delegate. This method is overridden in the MulticastDelegate class to support multicasting.

remove

public static final Delegate remove(Delegate delSource,
        Delegate delValue);

Returns a Delegate with an invocation list formed by removing the last occurrence (if any) of the Delegate given by the value parameter from the invocation list of the Delegate given by the source parameter. The Delegate removed from the invocation list is the last Delegate that refers to the same method on the same object as the value parameter. If the value parameter is null, or if the Delegate given by the value parameter does not appear on the invocation list of the source, the result is the source parameter. If the resulting invocation list is empty, the result is null. If the source parameter is null, the result is null.