org.codehaus.aspectwerkz
Class AspectWerkz

java.lang.Object
  extended byorg.codehaus.aspectwerkz.AspectWerkz

public final class AspectWerkz
extends java.lang.Object

Manages the aspects in the AspectWerkz system.
Handles the initialization and configuration of the system.
Stores and indexes the aspects defined in the system.
Stores and indexes the advised methods.
Stores and indexes the introduced methods.

Author:
Jonas Bonér

Field Summary
static java.lang.String DEFAULT_SYSTEM
          The UUID of the single AspectWerkz system if only one definition is used.
 
Method Summary
static java.lang.Integer calculateHash(java.lang.String className, MetaData metaData)
          Calculates the hash for the class name and the meta-data.
 void createAdvice(java.lang.String name, java.lang.String className, java.lang.String deploymentModel, java.lang.ClassLoader loader)
          Creates and registers new advice at runtime.
 void enteringControlFlow(ClassNameMethodMetaDataTuple metaData)
          Registers entering of a control flow join point.
 void exitingControlFlow(ClassNameMethodMetaDataTuple metaData)
          Registers exiting from a control flow join point.
static void fakeStackTrace(java.lang.Throwable exception, java.lang.String className)
          Removes the AspectWerkz specific elements from the stack trace.
 Advice getAdvice(int index)
          Retrieves a specific advice based setfield's index.
 Advice getAdvice(java.lang.String name)
          Returns the advice for a specific name.
 int getAdviceIndexFor(java.lang.String name)
          Returns the index for a specific name to advice mapping.
 Aspect getAspect(ClassPattern classPattern)
          Returns the aspect for the class pattern specified.
 Aspect getAspect(java.lang.String name)
          Returns the aspect for the name specified.
 java.util.Collection getAspects()
          Returns a list with all the aspects.
 java.util.List getCallerSidePointcuts(java.lang.String className, MethodMetaData methodMetaData)
          Returns the caller side pointcut list for the class and method specified.
 java.util.List getCFlowPointcuts(java.lang.String className, MethodMetaData methodMetaData)
          Returns a list with the cflow pointcuts that affects the join point with the class name and the method name specified.
static AspectWerkz getDefaultSystem()
          Returns the AspectWerkz system, no system UUID is needed to be specified.
 java.util.List getGetFieldPointcuts(ClassMetaData classMetaData, FieldMetaData fieldMetaData)
          Returns the get field pointcut list for the class and field specified.
 Introduction getIntroduction(int index)
          Retrieves a specific introduction based it's index.
 Introduction getIntroduction(java.lang.String name)
          Returns the introduction for a specific name.
 int getIntroductionIndex(java.lang.String name)
          Returns the index for a specific name to introduction mapping.
 Introduction[] getIntroductions()
          Returns an array with all the introductions in the system.
 java.lang.reflect.Method getMethod(java.lang.Class klass, int index)
          Returns a specific method by the class and the method index.
 java.util.List getMethodPointcuts(ClassMetaData classMetaData, MethodMetaData methodMetaData)
          Returns the method pointcut list for the class and method specified.
 java.util.List getSetFieldPointcuts(ClassMetaData classMetaData, FieldMetaData fieldMetaData)
          Returns the set field pointcut list for the class and field specified.
static AspectWerkz getSystem(java.lang.String uuid)
          Returns the AspectWerkz system with a specific UUID.
 java.util.List getThrowsPointcuts(ClassMetaData classMetaData, MethodMetaData methodMetaData)
          Returns the throws pointcut list for the class and method specified.
 boolean hasAspect(java.lang.String name)
          Checks if a specific class has an aspect defined.
 void initialize()
          Initializes the system.
 boolean isInControlFlowOf(PointcutPatternTuple patternTuple)
          Checks if we are in the control flow of a specific cflow pointcut.
 void register(Aspect aspect)
          Registers a new aspect for a specific class.
 void register(java.lang.String name, Advice advice)
          Registers a new advice and maps it to a name.
 void register(java.lang.String name, Introduction introduction)
          Registers an introduction and maps it to a name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_SYSTEM

public static final java.lang.String DEFAULT_SYSTEM
The UUID of the single AspectWerkz system if only one definition is used.

See Also:
Constant Field Values
Method Detail

getDefaultSystem

public static AspectWerkz getDefaultSystem()
Returns the AspectWerkz system, no system UUID is needed to be specified.

Only to be used when:
1. only an XML definition is used.
2. only one weave model with the UUID set to "default" is used.

Returns:
the AspectWerkz system for the default UUID

getSystem

public static AspectWerkz getSystem(java.lang.String uuid)
Returns the AspectWerkz system with a specific UUID.

Parameters:
uuid - the UUID for the system (the UUID specified when compiling the weave model, if autogenerated can it be read in the name of the weave model file, ex: "weaveModel_.ser")
Returns:
the AspectWerkz system for the UUID specified

fakeStackTrace

public static void fakeStackTrace(java.lang.Throwable exception,
                                  java.lang.String className)
Removes the AspectWerkz specific elements from the stack trace.

Parameters:
exception - the Throwable to modify the stack trace on
className - the name of the fake origin class of the exception

calculateHash

public static java.lang.Integer calculateHash(java.lang.String className,
                                              MetaData metaData)
Calculates the hash for the class name and the meta-data.

Parameters:
className - the class name
metaData - the meta-data
Returns:
the hash

initialize

public void initialize()
Initializes the system.


register

public void register(Aspect aspect)
Registers a new aspect for a specific class.

Parameters:
aspect - the aspect to register

register

public void register(java.lang.String name,
                     Advice advice)
Registers a new advice and maps it to a name.

Parameters:
name - the name to map the advice to
advice - the advice to register

register

public void register(java.lang.String name,
                     Introduction introduction)
Registers an introduction and maps it to a name. At the moment it is not possible to add new introductions at runtime (don't know if it makes sense).

Parameters:
name - the name to map the introduction to
introduction - the introduction to register

enteringControlFlow

public void enteringControlFlow(ClassNameMethodMetaDataTuple metaData)
Registers entering of a control flow join point.

Parameters:
metaData - the classname:methodMetaData metaData

exitingControlFlow

public void exitingControlFlow(ClassNameMethodMetaDataTuple metaData)
Registers exiting from a control flow join point.

Parameters:
metaData - the classname:methodMetaData metaData

isInControlFlowOf

public boolean isInControlFlowOf(PointcutPatternTuple patternTuple)
Checks if we are in the control flow of a specific cflow pointcut.

Parameters:
patternTuple - the compiled tuple with the class pattern and the method pattern of the cflow pointcut
Returns:
boolean

createAdvice

public void createAdvice(java.lang.String name,
                         java.lang.String className,
                         java.lang.String deploymentModel,
                         java.lang.ClassLoader loader)
Creates and registers new advice at runtime.

Parameters:
name - the name of the advice
className - the class name of the advice
deploymentModel - the deployment model for the advice
loader - an optional class loader (if null it uses the context classloader)

getAspect

public Aspect getAspect(java.lang.String name)
Returns the aspect for the name specified.

Parameters:
name - the name of the aspect
Returns:
the aspect

getAspect

public Aspect getAspect(ClassPattern classPattern)
Returns the aspect for the class pattern specified.

Parameters:
classPattern - the class pattern
Returns:
the aspect

getAspects

public java.util.Collection getAspects()
Returns a list with all the aspects.

Returns:
the aspects

getMethodPointcuts

public java.util.List getMethodPointcuts(ClassMetaData classMetaData,
                                         MethodMetaData methodMetaData)
Returns the method pointcut list for the class and method specified. Caches the list, needed since the actual method call is expensive and is made each time a new instance of an advised class is created.

Parameters:
classMetaData - the meta-data for the class
methodMetaData - meta-data for the method
Returns:
the pointcuts for this join point

getGetFieldPointcuts

public java.util.List getGetFieldPointcuts(ClassMetaData classMetaData,
                                           FieldMetaData fieldMetaData)
Returns the get field pointcut list for the class and field specified. Caches the list, needed since the actual method call is expensive and is made each time a new instance of an advised class is created.

Parameters:
classMetaData - the meta-data for the class
Returns:
the pointcuts for this join point

getSetFieldPointcuts

public java.util.List getSetFieldPointcuts(ClassMetaData classMetaData,
                                           FieldMetaData fieldMetaData)
Returns the set field pointcut list for the class and field specified. Caches the list, needed since the actual method call is expensive and is made each time a new instance of an advised class is created.

Parameters:
classMetaData - the meta-data for the class
Returns:
the pointcuts for this join point

getThrowsPointcuts

public java.util.List getThrowsPointcuts(ClassMetaData classMetaData,
                                         MethodMetaData methodMetaData)
Returns the throws pointcut list for the class and method specified. Caches the list, needed since the actual method call is expensive and is made each time a new instance of an advised class is created.

Parameters:
classMetaData - the meta-data for the class
methodMetaData - meta-data for the method
Returns:
the pointcuts for this join point

getCallerSidePointcuts

public java.util.List getCallerSidePointcuts(java.lang.String className,
                                             MethodMetaData methodMetaData)
Returns the caller side pointcut list for the class and method specified. Caches the list, needed since the actual method call is expensive and is made each time a new instance of an advised class is created.

Parameters:
className - the class name
methodMetaData - meta-data for the method
Returns:
the pointcuts for this join point

getCFlowPointcuts

public java.util.List getCFlowPointcuts(java.lang.String className,
                                        MethodMetaData methodMetaData)
Returns a list with the cflow pointcuts that affects the join point with the class name and the method name specified.

Parameters:
className - the name of the class for the join point
methodMetaData - the meta-data for the method for the join point
Returns:
a list with the cflow pointcuts

getAdviceIndexFor

public int getAdviceIndexFor(java.lang.String name)
Returns the index for a specific name to advice mapping.

Parameters:
name - the name of the advice
Returns:
the index of the advice

getAdvice

public Advice getAdvice(int index)
Retrieves a specific advice based setfield's index.

Parameters:
index - the index of the advice
Returns:
the advice

getAdvice

public Advice getAdvice(java.lang.String name)
Returns the advice for a specific name.

Parameters:
name - the name of the advice
Returns:
the the advice

getIntroductions

public Introduction[] getIntroductions()
Returns an array with all the introductions in the system.

Returns:
the introductions

getIntroductionIndex

public int getIntroductionIndex(java.lang.String name)
Returns the index for a specific name to introduction mapping.

Parameters:
name - the name of the introduction
Returns:
the index of the introduction

getIntroduction

public Introduction getIntroduction(int index)
Retrieves a specific introduction based it's index.

Parameters:
index - the index of the introduction
Returns:
the introduction

getIntroduction

public Introduction getIntroduction(java.lang.String name)
Returns the introduction for a specific name.

Parameters:
name - the name of the introduction
Returns:
the the introduction

hasAspect

public boolean hasAspect(java.lang.String name)
Checks if a specific class has an aspect defined.

Parameters:
name - the name of the aspect
Returns:
boolean true if the class has an aspect defined

getMethod

public java.lang.reflect.Method getMethod(java.lang.Class klass,
                                          int index)
Returns a specific method by the class and the method index.

Parameters:
klass - the class housing the method
index - the method index
Returns:
the method


Copyright (c) 2002-2004 The AspectWerkz Team. All Rights Reserved.