[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-dev] dynamically disable set functions
|
This modification wouldn't compile because proceed needs to forward the arguments of the set functions. Since the set* functions can have any number of arguments, I don't know how to capture them in the advice's context.
On Sun, Feb 21, 2010 at 3:07 PM, Ramnivas Laddad
<ramnivas@xxxxxxxxxxxxxxx> wrote:
You can simplify your aspect by modifying the around advice as follows:
void around( Order order ) : allSetFunctions( order ) {
if( !order.enableSet ) {
System.out.println( "Set disabled" );
} else {
System.out.println( "Set enabled" );
proceed();
}
}
I'd want to build an aspect to dynamically disable set function based on a boolean field.
Order is a domain object which contains only getters and setters.
package org.talz;
import org.aspectj.lang.reflect.MethodSignature;
privileged public aspect DynamicSetDisabler perthis( allSetFunctions( Order ) ) {
pointcut allSetFunctions( Order order ) :
execution( * Order.set*(..) ) && this( order )
&& !within(DynamicSetDisabler)
&& !within(sun.reflect..*);
void around( Order order ) : allSetFunctions( order ) {
if( !order.enableSet ) {
System.out.println( "Set disabled" );
} else {
System.out.println( "Set enabled" );
try {
MethodSignature method = (MethodSignature) thisJoinPoint.getSignature();
method.getMethod().invoke( order, thisJoinPoint.getArgs() );
}
catch( Exception e ) {
e.printStackTrace();
}
}
}
}
Is there a way to achieve my use case? Thanks.
_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev
_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev