Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] dynamically disable set functions

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();
}
}

On Sat, Feb 20, 2010 at 11:43 PM, Candy Chiu <candy.chiu.ad@gmail.com> wrote:
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



Back to the top