Section A.1. org.aspectj.lang


A.1. org.aspectj.lang

Similar to the familiar java.lang package that conatins the most fundamental constructs for the Java language, the org.aspectj.lang package provides a set of classes for interacting with join points at the most basic and common level.

JoinPoint and JoinPoint.StaticPart

Figure A-1Figure A-1 shows the structure of the JoinPoint and JoinPoint.StaticPart interfaces.

Figure A-2. The JoinPoint and JoinPoint.StaticPart interfaces


The JoinPoint interface

The JoinPoint interface is most commonly used by the thisJoinPoint reference that is made available to any advice block. The interface provides access to the dynamic and static information that is available about a specific join point.


public String toString( )

Overrides the default toString( ) method on an object to return a string representation of the join point. An example of the string returned from the toString() method on a method call join point is:

call(void com.oreilly.aspectjcookbook.MyClass.foo(int, String))


public String toShortString( )

Provides an alternative to the toString( ) method that returns an abbreviated version of the string representation of the join point. An example of the string returned from the toShortString( ) method on a method call join point is:

call(MyClass.foo(..))


public String toLongString( )

Provides an alternative to the toString( ) method that returns an extended version of the string representation of the join point. An example of the string returned from the toLongString( ) method on a method call join point is:

call(public void com.oreilly.aspectjcookbook.MyClass.foo(int, java.lang.String))


public Object getThis( )

Returns the object, if any, that is executingi.e., the value of this referenceat the join point. Returns null if there is no reference at the corresponding join point, as is the case with static blocks of code.


public Object getTarget( )

Returns the object, if any, that is the target of the join point. For example, the target of a method call join point is the object being called. Returns null if there is no target object at the corresponding join point.


public Object[] getArgs( )

Returns an array containing the arguments, if any, available at a join point. For example, the getArgs( ) method returns the parameters being passed on a method call join point.


public Signature getSignature( )

Returns the signature at the join point.

Note that the JoinPoint.StaticPart.getSignature( ) method returns the same value as this method.


public SourceLocation getSourceLocation( )

Returns an object that contains all information available, if any, about the source location of the join point. A null will be returned if no source location information is available.

Note that the JoinPoint.StaticPart.getSourceLocation() method returns the same value as this method.


public String getKind( )

Returns a string enumeration indicating the type of the join point. The JoinPoint interface declares the following constants that can be compared against the string that is returned from this method to determine the type of the join point:


METHOD_CALL

Indicates that the join point occurred on the call to a method. See Recipe 4.1 for the pointcut declaration that specifically captures this kind of pointcut.


METHOD_EXECUTION

Indicates that the join point occurred during the execution of a method. See Recipe 4.2 for the pointcut declaration that specifically captures this kind of pointcut.


ADVICE_EXECUTION

Indicates that the join point occurred during advice execution. See Recipe 4.3 for the pointcut declaration that specifically captures this kind of pointcut.


FIELD_GET

Indicates that the join point occurred when an attribute was accessed. See Recipe 4.4 for the pointcut declaration that specifically captures this kind of pointcut.


FIELD_SET

Indicates that the join point occurred when an attribute is modified. See Recipe 4.5 for the pointcut declaration that specifically captures this kind of pointcut.


EXCEPTION_HANDLER

Indicates that the join point occurred when an exception was handled. See Recipe 4.6 for the pointcut declaration that specifically captures this kind of pointcut.


CONSTRUCTOR_CALL

Indicates that the join point occurred on the call to a constructor. See Recipe 4.7 for the pointcut declaration that specifically captures this kind of join point.


CONSTRUCTOR_EXECUTION

Indicates that the join point occurred during the execution of a constructor. See Recipe 4.8 for the pointcut declaration that specifically captures this kind of join point.


INITIALIZATION

Indicates that the join point occurred during the initialization of an object. See Recipe 4.9 for the pointcut declaration that specifically captures this kind of join point.


PREINITIALIZATION

Indicates that the join point occurred before the initialization of an object. See Recipe 4.10 for the pointcut declaration that specifically captures this kind of join point.


STATICINITIALIZATION

Indicates that the join point occurred during the initialization of a class. See Recipe 4.11 for the pointcut declaration that specifically captures this kind of join point.

Note that the JoinPoint.StaticPart.getKind( ) method returns the same value as this method.


public JoinPoint.StaticPart getStaticPart( )

Returns an object that contains the information about a join point that can be statically determined. An alternative method for accessing the static information is to use the thisJoinPointStaticPart reference available to any advice block.

The JoinPoint.StaticPart interface

The JoinPoint.StaticPart interface is most commonly accessed using the thisJoinPointStaticPart reference available to all advice blocks. An alternative method is to use the getStaticPart( ) method on the JoinPoint interface that can be accessed using the thisJoinPoint reference.


public String toString( )

Overrides the default toString( ) method on an object to return a string representation of the join point.

Note that the JoinPoint.toString( ) method returns the same value as this method.


public String toShortString( )

Provides an alternative to the toString( ) method that returns an abbreviated version of the string representation of the join point.

Note that the JoinPoint.toShortString( ) method returns the same value as this method.


public String toLongString( )

Provides an alternative to the toString( ) method that returns an extended version of the string representation of the join point.

Note that the JoinPoint.toLongString( ) method returns the same value as this method.


public Signature getSignature( )

Returns the signature at the join point.

Note that the JoinPoint.getSignature( ) method returns the same value as this method.


public SourceLocation getSourceLocation( )

Returns an object that contains all information available, if any, about the source location of the join point. A null will be returned if no source location information is available.

Note that the JoinPoint.getSourceLocation( ) method returns the same value as this method.


public String getKind( )

Returns a string enumeration indicating the type of the join point.

Note that the description of the JoinPoint.getKind() method shows the different enumerations that are supported by AspectJ.



AspectJ Cookbook
Aspectj Cookbook
ISBN: 0596006543
EAN: 2147483647
Year: 2006
Pages: 203
Authors: Russ Miles

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net