org.codehaus.aspectwerkz.aspect
Class AbstractAspectContainer

java.lang.Object
  extended byorg.codehaus.aspectwerkz.aspect.AbstractAspectContainer
All Implemented Interfaces:
AspectContainer
Direct Known Subclasses:
DefaultAspectContainerStrategy

public abstract class AbstractAspectContainer
extends Object
implements AspectContainer

Abstract base class for the aspect container implementations.

Author:
Jonas Bonér

Field Summary
protected  Object[] arrayWithSingleCrossCuttingInfo
          An array with the single cross-cutting info, needed to save one array creation per invocation.
static int ASPECT_CONSTRUCTION_TYPE_CROSS_CUTTING_INFO
           
static int ASPECT_CONSTRUCTION_TYPE_DEFAULT
           
static int ASPECT_CONSTRUCTION_TYPE_UNKNOWN
           
static Object[] EMPTY_OBJECT_ARRAY
           
protected  Method[] m_adviceRepository
          The advice repository.
protected  Object m_aspectPrototype
          The aspect instance prototype.
protected  int m_constructionType
          The aspect construction type.
protected  CrossCuttingInfo m_infoPrototype
          The cross-cutting info prototype.
protected  Map m_introductionContainers
          Introduction container containing introduction declared by this aspect, keys by introduction names
protected  Map m_perClass
          Holds references to the per class aspect instances.
protected  Map m_perInstance
          Holds references to the per instance aspect instances.
protected  Object m_perJvm
          Holds a reference to the sole per JVM aspect instance.
protected  Map m_perThread
          Holds references to the per thread aspect instances.
 
Constructor Summary
AbstractAspectContainer(CrossCuttingInfo crossCuttingInfo)
          Creates a new aspect container strategy.
 
Method Summary
 void addIntroductionContainer(String name, IntroductionContainer introContainer)
          Attach the introduction container to this aspect container to mirror the "aspect contains 0-n introduction"
protected  void createAdviceRepository()
          Creates a repository for the advice methods.
protected abstract  Object createAspect()
          To be implemented by the concrete aspect containers.
 Object createPerClassAspect(Class callingClass)
          Creates a new perClass cross-cutting instance, if it already exists then return it.
 Object createPerInstanceAspect(Object callingInstance)
          Creates a new perInstance cross-cutting instance, if it already exists then return it.
 Object createPerJvmAspect()
          Creates a new perJVM cross-cutting instance, if it already exists then return it.
 Object createPerThreadAspect(Thread thread)
          Creates a new perThread cross-cutting instance, if it already exists then return it.
 Method getAdvice(int index)
          Returns a specific advice by index.
 CrossCuttingInfo getCrossCuttingInfo()
          Returns the cross-cutting info.
 IntroductionContainer getIntroductionContainer(String name)
          Returns the introduction container of given name (introduction name) or null if not linked.
 Object invokeAdvice(int adviceIndex, JoinPoint joinPoint)
          Invokes an advice with the index specified.
 Object invokeAdvice(int adviceIndex, JoinPoint joinPoint, int[] methodToArgIndexes)
          Invokes the advice method on a per JVM basis.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ASPECT_CONSTRUCTION_TYPE_UNKNOWN

public static final int ASPECT_CONSTRUCTION_TYPE_UNKNOWN
See Also:
Constant Field Values

ASPECT_CONSTRUCTION_TYPE_DEFAULT

public static final int ASPECT_CONSTRUCTION_TYPE_DEFAULT
See Also:
Constant Field Values

ASPECT_CONSTRUCTION_TYPE_CROSS_CUTTING_INFO

public static final int ASPECT_CONSTRUCTION_TYPE_CROSS_CUTTING_INFO
See Also:
Constant Field Values

EMPTY_OBJECT_ARRAY

public static final Object[] EMPTY_OBJECT_ARRAY

m_constructionType

protected int m_constructionType
The aspect construction type.


m_introductionContainers

protected final Map m_introductionContainers
Introduction container containing introduction declared by this aspect, keys by introduction names


m_infoPrototype

protected final CrossCuttingInfo m_infoPrototype
The cross-cutting info prototype.


arrayWithSingleCrossCuttingInfo

protected final Object[] arrayWithSingleCrossCuttingInfo
An array with the single cross-cutting info, needed to save one array creation per invocation.


m_aspectPrototype

protected final Object m_aspectPrototype
The aspect instance prototype.


m_perJvm

protected Object m_perJvm
Holds a reference to the sole per JVM aspect instance.


m_perClass

protected final Map m_perClass
Holds references to the per class aspect instances.


m_perInstance

protected final Map m_perInstance
Holds references to the per instance aspect instances.


m_perThread

protected final Map m_perThread
Holds references to the per thread aspect instances.


m_adviceRepository

protected Method[] m_adviceRepository
The advice repository.

Constructor Detail

AbstractAspectContainer

public AbstractAspectContainer(CrossCuttingInfo crossCuttingInfo)
Creates a new aspect container strategy.

Parameters:
crossCuttingInfo - the cross-cutting info
Method Detail

invokeAdvice

public Object invokeAdvice(int adviceIndex,
                           JoinPoint joinPoint)
                    throws Throwable
Invokes an advice with the index specified.

Specified by:
invokeAdvice in interface AspectContainer
Parameters:
adviceIndex - the advice index
joinPoint - the join point
Returns:
the result from the invocation
Throws:
Throwable

invokeAdvice

public Object invokeAdvice(int adviceIndex,
                           JoinPoint joinPoint,
                           int[] methodToArgIndexes)
                    throws Throwable
Description copied from interface: AspectContainer
Invokes the advice method on a per JVM basis.

Specified by:
invokeAdvice in interface AspectContainer
Parameters:
adviceIndex - the method index
joinPoint - the join point
methodToArgIndexes -
Returns:
the result from the method invocation
Throws:
Throwable

getAdvice

public Method getAdvice(int index)
Returns a specific advice by index.

Specified by:
getAdvice in interface AspectContainer
Parameters:
index - the index
Returns:
the advice

getCrossCuttingInfo

public CrossCuttingInfo getCrossCuttingInfo()
Returns the cross-cutting info.

Specified by:
getCrossCuttingInfo in interface AspectContainer
Returns:
the cross-cutting info

createPerJvmAspect

public Object createPerJvmAspect()
Creates a new perJVM cross-cutting instance, if it already exists then return it.

Specified by:
createPerJvmAspect in interface AspectContainer
Returns:
the cross-cutting instance

createPerClassAspect

public Object createPerClassAspect(Class callingClass)
Creates a new perClass cross-cutting instance, if it already exists then return it.

Specified by:
createPerClassAspect in interface AspectContainer
Parameters:
callingClass -
Returns:
the cross-cutting instance

createPerInstanceAspect

public Object createPerInstanceAspect(Object callingInstance)
Creates a new perInstance cross-cutting instance, if it already exists then return it.

Specified by:
createPerInstanceAspect in interface AspectContainer
Parameters:
callingInstance -
Returns:
the cross-cutting instance

createPerThreadAspect

public Object createPerThreadAspect(Thread thread)
Creates a new perThread cross-cutting instance, if it already exists then return it.

Specified by:
createPerThreadAspect in interface AspectContainer
Parameters:
thread - the thread for the aspect
Returns:
the cross-cutting instance

addIntroductionContainer

public void addIntroductionContainer(String name,
                                     IntroductionContainer introContainer)
Attach the introduction container to this aspect container to mirror the "aspect contains 0-n introduction"

Specified by:
addIntroductionContainer in interface AspectContainer
Parameters:
name - of the introduction
introContainer - introduction container

getIntroductionContainer

public IntroductionContainer getIntroductionContainer(String name)
Returns the introduction container of given name (introduction name) or null if not linked.

Specified by:
getIntroductionContainer in interface AspectContainer
Parameters:
name - of the introduction
Returns:
introduction container

createAdviceRepository

protected void createAdviceRepository()
Creates a repository for the advice methods.


createAspect

protected abstract Object createAspect()
To be implemented by the concrete aspect containers.

Should return a new aspect instance.

Returns:
a new aspect instance


Copyright © 2002-2004 Jonas Bonér, Alexandre Vasseur. All Rights Reserved.