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

My next step is to make the aspect more generic.  Ideally, it should work for any kind of Object of which I wish to disable any arbitrary set of functions.

I first changed the context of disableJoinPoints to capture any Object.  The execution joint point still depends on Order, but that can be eliminated by making disableJoinPoints abstract.  This code is all well except that Object doesn't have a function or a field that captures whether an instance is read-only. 

privileged public aspect DynamicSetDisabler { 
pointcut disableJoinPoints( Object object ) :
execution( void Order.set*( .. ) ) && this( object );

void around( Object object ) : disableJoinPoints( object )  {
if( object.isReadOnly() ) {
throw new IllegalAccessError( "Blocked Access" );
} else {
proceed( object );
}
}
}

To solve the readOnly problem, I tried statically altering the structure of Object to

privileged public aspect DynamicSetDisabler { 
private boolean Object.readOnly;
pointcut disableJoinPoints( Object object ) :
execution( void Order.set*( .. ) ) && this( object );

void around( Object object ) : disableJoinPoints( object )  {
if( object.isReadOnly() ) {
throw new IllegalAccessError( "Blocked Access" );
} else {
proceed( object );
}
}
public boolean Object.isReadOnly() {
return this.readOnly;
}
}

This doesn't compile.  isReadOnly() is not recognized by the around() advice.  At the end, I tried introducing an interface - IReadonlyConfigurable which contains only one fucntion - boolean isReadOnly().  I then changed my aspect to:

privileged public aspect DynamicSetDisabler { 
pointcut disableJoinPoints( IReadonlyConfigurable object ) :
execution( void Order.set*( .. ) ) && this( object );

void around( IReadonlyConfigurable object ) : disableJoinPoints( object )  {
if( object.isReadOnly() ) {
throw new IllegalAccessError( "Blocked Access" );
} else {
proceed( object );
}
}
}

This works, but any object wishes to take advantage of this facility needs to implement an interface on top of extending DynamicSetDisabler to provides its own specifications of disableJoinPoints.  The solution seems too complicated.  Is there a simpler solution?

Thanks.


Back to the top