Results 1 to 4 of 4

Thread: convert my DLA to @AspectJ5

  1. #1
    Join Date
    Jan 2005
    Posts
    144

    Default convert my DLA to @AspectJ5

    Hello,

    I'm using Design Level Assertion in my project. I have a SystemArchitecture Aspect to map the application layers :

    Code:
    public aspect SystemArchitecture {
       pointcut inPersistenceLayer()
          : within(com.capgemini.quickstart.persistence..*);
    }
    .. and a DLA aspect to catch any unexpected cross-layer usage :

    Code:
    public aspect DesignLevelAssertions {
        declare error
        : SystemArchitecture.callPersistenceImplementation() && ! SystemArchitecture.inPersistenceLayer()
        : "Do not invoke persistence layer implementation";

    I'd like to convert this to AspcetJ 5 Annotation based syntax. Its ok for SystemArchitecture :

    Code:
    @Aspect
    public class SystemArchitecture {
        @Pointcut( "within(com.capgemini.quickstart.persistence..*) " )
        void inPersistenceLayer()    {}
    }
    But I can't find how to convert my declare error, as a String is expected by @DeclareError() :

    Code:
    @Aspect
    public class DesignLevelAssertions
    {
        @DeclareError( ??? )
        static final String INVOKE_PERSISTENCE_LAYER =  "Do not invoke persistence layer implementation";

    Any suggestion ?

  2. #2
    Join Date
    Sep 2007
    Location
    Oceanside, CA
    Posts
    187

    Default

    The parameter to @DeclareError should be the pointcut expression used to bind the error. The following link has some examples:

    http://www.eclipse.org/aspectj/doc/r...j-declare.html
    Mike Bingham

  3. #3
    Join Date
    Jan 2005
    Posts
    144

    Default

    I'm ok with what the DeclareError annotation expect, but I'm looking for a Java5 equivalent to existing aspectJ
    construct. AspectJ dedicated syntax allows to set pointcuts and use them latter. The annotation string would require me to copy/paste my pointcut many times, I'd liek to avoid this and keep my SystemArchitecture aspect clean.

  4. #4
    Join Date
    Sep 2007
    Location
    Oceanside, CA
    Posts
    187

    Default

    You can create named pointcuts with the @Pointcut annotation. The following links provide a few examples:

    http://www.eclipse.org/aspectj/doc/r...-pcadvice.html
    http://www.springframework.org/docs/...#aop-pointcuts

    Once you've created a named pointcut, you can reference it in other annotations such as @DeclareError. For example:

    Code:
    @Pointcut("within(com.xyz.someapp.dao..*)")
    public void inPersistenceLayer() {}
    
    @DeclareError("inPersistenceLayer()")
    static final String INVOKE_PERSISTENCE_LAYER =  "Do not invoke persistence layer implementation";
    Mike Bingham

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •