org.perfectjpattern.core.structural.adapter
Class Adapter<T,A>

java.lang.Object
  extended by org.perfectjpattern.core.structural.AbstractSurrogate<T,A>
      extended by org.perfectjpattern.core.structural.adapter.Adapter<T,A>
Type Parameters:
T - Target element type
A - Adaptee element type
All Implemented Interfaces:
InvocationHandler, IAdapter<T,A>, ISurrogate<T>
Direct Known Subclasses:
EntityManagerAdapter, EntityTransactionAdapter, HibernateQueryAdapter, HibernateSessionAdapter, HibernateTransactionAdapter, JpaQueryAdapter, List2QueueAdapter

public class Adapter<T,A>
extends AbstractSurrogate<T,A>
implements IAdapter<T,A>

Concrete implementation of IAdapter

Version:
$Revision: 1.0 $Date: Jan 28, 2009 1:43:35 PM $
Author:
Giovanni Azua
 

Constructor Summary
Adapter(Class<T> anInterface, A anAdaptee)
          Constructs an Adapter instance having the target interface, the adaptee instance and assigning the default adapting strategy
Adapter(Class<T> aTargetInterface, A anAdaptee, IAdaptingStrategy anAdaptingStrategy)
          Constructs an Adapter taking as input the Target interface type, an Adaptee instance and the IAdaptingStrategy for matching those interfaces.
 
Method Summary
 A getAdaptee()
          Returns the Adaptee instance
 T getTarget()
          Returns the Target instance
protected  Object invokeUnderlying(Method aMethod, Object[] anArguments)
          Returns the result of the Method invocation.
 void setAdaptingStrategy(IAdaptingStrategy anAdaptingStrategy)
          Sets the adapting strategy e.g.
 
Methods inherited from class org.perfectjpattern.core.structural.AbstractSurrogate
equals, getComponent, getComponentClass, getUnderlying, hashCode, invoke
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.perfectjpattern.core.api.structural.ISurrogate
getComponent
 
Methods inherited from interface java.lang.reflect.InvocationHandler
invoke
 

Constructor Detail

Adapter

public Adapter(Class<T> aTargetInterface,
               A anAdaptee,
               IAdaptingStrategy anAdaptingStrategy)
        throws IllegalArgumentException
Constructs an Adapter taking as input the Target interface type, an Adaptee instance and the IAdaptingStrategy for matching those interfaces.

Parameters:
aTargetInterface - Target interface class type
anAdaptee - Adaptee instance
anAdaptingStrategy - Strategy for matching the Target and Adaptee interfaces
Throws:
IllegalArgumentException - 'aTargetInterface' must not be null
IllegalArgumentException - 'anAdaptee' must not be null
IllegalArgumentException - 'anAdaptingStrategy' must not be null

Adapter

public Adapter(Class<T> anInterface,
               A anAdaptee)
        throws IllegalArgumentException
Constructs an Adapter instance having the target interface, the adaptee instance and assigning the default adapting strategy

Parameters:
aTargetInterface - Target interface type
anAdaptee - Adaptee instance
Throws:
IllegalArgumentException - 'aTargetInterface' must not be null
IllegalArgumentException - 'anAdaptee' must not be null
Method Detail

getAdaptee

public A getAdaptee()
Returns the Adaptee instance

Specified by:
getAdaptee in interface IAdapter<T,A>
Returns:
Adaptee instance

getTarget

public T getTarget()
Returns the Target instance

Specified by:
getTarget in interface IAdapter<T,A>
Returns:
Target instance

setAdaptingStrategy

public final void setAdaptingStrategy(IAdaptingStrategy anAdaptingStrategy)
                               throws IllegalArgumentException
Sets the adapting strategy e.g. exact, name, user-defined

Specified by:
setAdaptingStrategy in interface IAdapter<T,A>
Parameters:
anAdaptingStrategy - IAdaptingStrategy instance to assign
Throws:
IllegalArgumentException - 'anAdaptingStrategy' must not be null

invokeUnderlying

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

Overrides:
invokeUnderlying in class AbstractSurrogate<T,A>
Parameters:
aMethod - Method to invoke
anArguments - Array of input arguments for the Method to invoke
Returns:
result of the Method invocation
Throws:
Throwable


Copyright © 2007-2009. All Rights Reserved.