org.perfectjpattern.core.extras.delegate
Class AbstractDelegator<I>

java.lang.Object
  extended by org.perfectjpattern.core.extras.delegate.AbstractDelegator<I>
Type Parameters:
I - Interface type built by this Delegator instance.
All Implemented Interfaces:
IDelegator<I>
Direct Known Subclasses:
Delegator, DynamicDelegator

public abstract class AbstractDelegator<I>
extends Object
implements IDelegator<I>

Abstract base implementation of IDelegator interface.

Notes: Base source code implemented by Steve Lewis and Wilhelm Fitzpatrick and adapted to fit PerfectJPattern componentization criteria and code conventions.

Version:
$Revision: 1.0 $ $Date: Jun 25, 2007 7:01:04 AM $
Author:
Steve Lewis, Wilhelm Fitzpatrick, Giovanni Azua
See Also:
IDelegator
 

Nested Class Summary
protected  class AbstractDelegator.DelegateProxy
           
 
Constructor Summary
protected AbstractDelegator(Class<I> anInterface)
          Constructs Delegator instance using an interface type that implements exactly one method.
protected AbstractDelegator(Class aReturnClass, Class... aParameters)
          Constructs Delegator instance using a method signature.
 
Method Summary
protected static Method findMethod(Class anInterface)
          Returns suitable Method found for the given interface type.
protected  Method findMethod(Class aTargetClass, String aMethodName, AbstractDelegator aDelegator)
          Returns suitable Method within class type that matches the given Delegator signature.
protected static Method[] findMethod(Class aTargetClass, String aMethodName, int aNumberOfArguments)
          Returns all candidate methods within a class that match the given signature.
protected  Class[] getArguments()
          Returns the Arguments class types.
protected  Class getReturn()
          Returns the Return class type.
protected  boolean isSuitableMethod(Method aTestMethod, Class aReturnClass, Class... anArguments)
          Returns true if the Method matches the given signature specified by Arguments and Return, false otherwise.
protected  boolean isValidReturn(Method aTestMethod, Class aReturnClass)
          Returns true if return type matches the expected type, false otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.perfectjpattern.core.api.extras.delegate.IDelegator
build, build
 

Constructor Detail

AbstractDelegator

protected AbstractDelegator(Class aReturnClass,
                            Class... aParameters)
Constructs Delegator instance using a method signature.

Parameters:
aReturnClass - Return class type.
aParameters - Parameter class types.

AbstractDelegator

protected AbstractDelegator(Class<I> anInterface)
Constructs Delegator instance using an interface type that implements exactly one method.

Parameters:
anInterface - Interface with EXACTLY one method.
Throws:
IllegalArgumentException - DelegateTemplate must be constructed with an interface implementing exactly one method!
Method Detail

isSuitableMethod

protected boolean isSuitableMethod(Method aTestMethod,
                                   Class aReturnClass,
                                   Class... anArguments)
Returns true if the Method matches the given signature specified by Arguments and Return, false otherwise.

Parameters:
aTestMethod -
anArguments -
aReturnClass -
Returns:
true if the Method matches the given signature specified by Arguments and Return, false otherwise.

isValidReturn

protected boolean isValidReturn(Method aTestMethod,
                                Class aReturnClass)
Returns true if return type matches the expected type, false otherwise.

Parameters:
aTestMethod -
aReturnClass -
Returns:
true if return type matches the expected type, false otherwise.

findMethod

protected static Method[] findMethod(Class aTargetClass,
                                     String aMethodName,
                                     int aNumberOfArguments)
Returns all candidate methods within a class that match the given signature.

Parameters:
aTargetClass -
aMethodName -
aNumberOfArguments -
Returns:
all candidate methods within a class that match the given signature.

findMethod

protected Method findMethod(Class aTargetClass,
                            String aMethodName,
                            AbstractDelegator aDelegator)
                     throws IllegalArgumentException,
                            UnsupportedOperationException
Returns suitable Method within class type that matches the given Delegator signature.

Parameters:
aTargetClass - Class type to search for matching method.
aMethodName - Method name to search for.
aDelegator - Delegate specification.
Returns:
suitable Method within class type that matches the given Delegate specification.
Throws:
IllegalArgumentException - Requested method returns wrong type.
IllegalArgumentException - Requested method is not public.
UnsupportedOperationException - No suitable method found.

findMethod

protected static Method findMethod(Class anInterface)
Returns suitable Method found for the given interface type.

Parameters:
anInterface -
Returns:
The suitable Method
Throws:
IllegalArgumentException - 'anInterface' must not be null.
IllegalArgumentException - DelegateTemplate must be constructed with an interface implementing exactly one method!

getReturn

protected Class getReturn()
Returns the Return class type.

Returns:
the Return class type.

getArguments

protected Class[] getArguments()
Returns the Arguments class types.

Returns:
Arguments class types.


Copyright © 2007-2009. All Rights Reserved.