org.perfectjpattern.core.structural
Class AbstractSurrogate<C,U>

java.lang.Object
  extended by org.perfectjpattern.core.structural.AbstractSurrogate<C,U>
Type Parameters:
C - Component or wrapper element type
U - Underlying wrapped element type
All Implemented Interfaces:
InvocationHandler, ISurrogate<C>
Direct Known Subclasses:
AbstractDecorator, AbstractProxy, Adapter

public abstract class AbstractSurrogate<C,U>
extends Object
implements ISurrogate<C>

Concrete implementation of ISurrogate that groups common functionality for single instance surrogates.

Version:
$Revision: 1.0 $Date: Apr 5, 2008 4:04:47 PM $
Author:
Giovanni Azua
 

Constructor Summary
AbstractSurrogate(Class<C> aSurrogateClass, U anUnderlying)
          Creates an AbstractSurrogate<C> given a Component interface type and an instance of the underlying wrapped object.
 
Method Summary
 boolean equals(Object anObject)
          
 C getComponent()
          Returns the Component interface view <C> of this ISurrogate

Client code calls this method to receive an instance of type <C> making accessible the Component business methods while the underlying implementation is wrapped by this surrogate.
protected  Class<C> getComponentClass()
          Returns the Component class
protected  U getUnderlying()
          
 int hashCode()
          
 Object invoke(Object aProxy, Method aMethod, Object[] anArguments)
           
protected  Object invokeUnderlying(Method aMethod, Object[] anArguments)
          Returns the result of the Method invocation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSurrogate

public AbstractSurrogate(Class<C> aSurrogateClass,
                         U anUnderlying)
                  throws IllegalArgumentException
Creates an AbstractSurrogate<C> given a Component interface type and an instance of the underlying wrapped object.

Parameters:
aSurrogateClass - The desired Surrogate interface type
anUnderlying - Underlying instance to surrogate
Throws:
IllegalArgumentException - 'anInterface' must not be null
IllegalArgumentException - 'anInterface' must be an interface type
IllegalArgumentException - 'aComponent' must not be null
Method Detail

getComponent

public final C getComponent()
Returns the Component interface view <C> of this ISurrogate

Client code calls this method to receive an instance of type <C> making accessible the Component business methods while the underlying implementation is wrapped by this surrogate.

Specified by:
getComponent in interface ISurrogate<C>
Returns:
Component interface view <C> of this ISurrogate type

invoke

public final Object invoke(Object aProxy,
                           Method aMethod,
                           Object[] anArguments)
                    throws Throwable
Specified by:
invoke in interface InvocationHandler
Throws:
Throwable

equals

public final boolean equals(Object anObject)

Overrides:
equals in class Object

hashCode

public final int hashCode()

Overrides:
hashCode in class Object

getUnderlying

protected final U getUnderlying()


invokeUnderlying

protected Object invokeUnderlying(Method aMethod,
                                  Object[] anArguments)
                           throws Throwable
Returns the result of the Method invocation. This method has two main purposes:

Parameters:
aMethod - Method to invoke
anArguments - Array of input arguments for the Method to invoke
Returns:
result of the Method invocation
Throws:
Throwable

getComponentClass

protected final Class<C> getComponentClass()
Returns the Component class

Returns:
the Component class


Copyright © 2007-2009. All Rights Reserved.