Announcement Announcement Module
Collapse
No announcement yet.
convert my DLA to @AspectJ5 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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.

      Comment


      • #4
        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";

        Comment

        Working...
        X