[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Method parameter annotations...

I am trying to define a pointcut that will match any method parameters that are annotated with @Untrusted. Among other things, I would like to be able to perform some operations on this parameter before allowing it to be used by the following method body (eg. data invalid character filtering, string truncation, etc...). Here is an example of the code with which I am testing:


Class:

public class TestData {

    private String m_stringValue;
   
    public String getStringValue() {
        return m_stringValue;
    }
   
    public void setStringValue( @Untrusted String p_stringValue) {
        m_stringValue = p_stringValue;
    }
}

 

Aspect:

@Target( value = ElementType.PARAMETER )

public @interface Untrusted {}

 

AspectJ Pointcut:
public aspect UntrustedAspect {

    pointcut truncate(String stringValue, Untrusted annot ) :
 @args(annot) && args(stringValue) && (call( * *.*( *, @Untrusted String, * ) ) );

    before(String stringValue, Untrusted annot) : truncate(stringValue, annot) {
        System.out.println( "*** My poincut! ***" );
        throw new RuntimeException( "Param too long!" );
    }
}


To this point I cannot get the aspect to match on TestData.setStringValue(String). If anyone would point me in the right direction, I would greatly appreciate it.

 

-Kyle



Join the next generation of Hotmail and you could win a trip to Africa Upgrade today