DynamicAspects is a aspect-oriented framework for Java using only pure Java.

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:
       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:
  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