DynamicAspects is a aspect-oriented framework for Java using only pure Java.
Aspects are written in pure Java.
Aspects can be installed and deinstalled during runtime.
Target classes can be written on a SUN JDK 1.4 or a SUN JDK 5.0 ( 1.5 ) basis.
DynamicAspects needs the Runtime Environment SUN JRE 5.0.
DynamicAspects uses the JavaAgent technology introduced in SUN JDK 5.0.
DynamicAspects lets you write Advices that can be installed around Method/Constructor-executions or -calls.
DynamicAspects lets you write Cflow-Advices.
DynamicAspects lets you write MixIns/IntertypeDeclarations ( which are currently loaded at program start and not deinstallable ).
Regular expressions are used for describing the pointcuts.
The current release of DynamicAspects is beta.
Download DynamicAspects here.
Please report bugs to Marco Petris
Using DynamicAspects
You can let your Aspect inherit from DefaultBeforeAfterAdvice or implement BeforeAfterAdvice. You can install the aspect via the AspectAgent using WeaveTypes or via the methods of the DefaultBeforeAfterAdvice. Currently implemented WeavetTypes are Execution, Call and Cflow. So you can wrap your Advice around a method- or constructor-call or around a method- or constructor-execution and you can restrict the execution of your advice using Cflow.
Your Aspect implements the following two methods of the interface BeforeAfterAdvice:
public abstract void before( ArgumentInfo ai );
public abstract void after( ReturnInfo ri );
Use the arguments ArgumentInfo and ReturnInfo to obtain informations about the method execution which triggered your Aspect.
Start your application passing the dynamic aspects library to the JVM via the javaagent option:
java -javaagent:lib\dynamicaspects.jar mypackage.MyMain
Use your aspects:
MyTargetClass target1 = new MyTargetClass(); MyAspect ma1 = new MyAspect(); // MyAspect inherits from DefaultBeforeAfterAdvice or implements BeforeAfterAdvice // install your Aspect to all public method: ma1.installArounCall( MyTargetClass.class, PointcutFactory.PATTERN_ALL_PUBLIC_METHODS ); MyAspect ma2 = new MyAspect( myArg ); // install aspect to the methods “public long doIt( double arg1, int arg2 )” and “public long doIt( double arg1, ArrayList arg2 )” in class MySecondTargetClass: ma2.installAroundExecution( MySecondTargetClass.class, new PointcutFactory(). addModifierList( Modifier.PUBLIC ). addReturnType( long.class ). addDeclaringClass( MySecondTargetClass.class ). addMethodName( "doIt" ). addParamTypeList( new Class[] { double.class, int.class } ). // or addParamTypeList( new Class[] { double.class, ArrayList.class } ); // ... use your target classes with aspects: target1.use(); MySecondTargetClass target2 = new MySecondTargetClass(); MySecondTargetClass target2 = new MySecondTargetClass(); target2.myMethod( “testArg” ); ma1.deinstall( MyTargetClass.class ); ma2.deinstall( MySecondTargetClass.class ); // ... use your target classes without aspects
As you might noticed it does not matter when you create instances of the target classes.
Of course you can create your regular expressions without the PointcutFactory.
For more details see the little sample application in the documentation/sample directory.
Upcoming features
use the AspectAgent to save a version of the target class with aspects woven in to a new .class-file
an ExceptionHandler Weave Type ( current aspects are notified of the exception but the exception is rethrown after the call of the after()-method of the aspect ).
testing
documentation