Skip to main content

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

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.

Back to the top