Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] @DeclareParents - @ManagedParents example


Goal:
Introduce an interface on any class that is marked with the MyAnnotation annotation.   I am using LTW

For an example of what I'm trying to do, see this following article by Coyler:   http://www-128.ibm.com/developerworks/java/library/j-aopwork8/ (see @DeclareParents("@ManagedComponent *") )

I can easily declare parents when matching on a class or package.  For example:
@DeclareParents(value="a.b.c.d.Test",defaultImpl=MyImpl.class)

works.   I can capture information by the LTW (I have the -showWeaveInfo option set).

However, if I try to base this on an annotation, it fails.   For example:
@DeclareParents(value="@MyAnnotation *",defaultImpl=MyImpl.class)

or, using fully qualified annotation name:
@DeclareParents(value="@a.b.c.d.MyAnnotation *",defaultImpl=MyImpl.class)

The @MyAnnotation annotation is defined as:
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface MyAnnotation{
}

Further, the example provided by Mr. Coyler in the article cited above suggests the following syntax:
@DeclareParents("@ManagedComponent *")
    class DefaultLifecycleImpl implements Lifecycle {
      private State state = State.INITIAL;
      public void initialize() {}
      public void start() {}
      public void stop() {}
      public void terminate() {}
      public boolean isBroken() { return state == State.BROKEN; }
      public State getState() { return state; }
    }

This does not compile for me, as @DeclareParents is set for ElementType.FIELD targets only.

I'm not sure what I might be overlooking.   The inter-type introduction I'm attempting works if I use the normal aspectj syntax (i.e. .aj files) and use LTW to weave in the advice.

Thanks in advance for the help,
Brian Yoffe




Compiler/vm:   Sun 1.5.0_06
AspectJ: 1.5.0

This communication is for informational purposes only. It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates.

This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you.

Back to the top