[jboss-user] [JBoss AOP] - Introducing annotations only on classes which don't have it
jaikiran
do-not-reply at jboss.com
Thu Apr 2 07:04:45 EDT 2009
I have been trying the examples hosted in the aop project SVN https://svn.jboss.org/repos/jbossas/projects/aop/trunk/aop/docs/examples/. Specifically, the annotation-introduction example. The sample application that i am trying contains a couple of POJOs and my own custom annotation:
POJO 1 (which is not annotated):
public class SimplePOJO
| {
| private int someInt;
|
| public String someMethod()
| {
| ...
| }
|
| }
|
POJO 2 (which is already annotated) :
@MyOwnAnnotation
| public class AlreadyAnnotatedPOJO
| {
| private int something;
|
| public String hello()
| {
| ...
| }
| }
|
|
My custom annotation :
@Retention(RetentionPolicy.RUNTIME)
| @Target(value=ElementType.TYPE)
| public @interface MyOwnAnnotation
| {
| String value();
| }
|
In this example, i am trying to add/introduce the @MyOwnAnnotation *on a class* which does not have one. So in the above code, i want the @MyOwnAnnotation to be added to SimplePOJO but not to AlreadyAnnotatedPOJO.
I have this jboss-aop.xml which tries to accomplish this:
<aop>
| <!-- Add the annotation at *class level* on classes which do not have
| this annotation already -->
| <annotation-introduction expr="!class(@MyOwnAnnotation)">
| @MyOwnAnnotation (value="i am testing something")
| </annotation-introduction>
|
| </aop>
|
This does not give the desired results (but infact leads to interesting output - see #2 and #3 below):
Questions:
1) Am i using the correct expression? expr="!class(@MyOwnAnnotation)"
2) This annotation-introduction expression results, in the @MyOwnAnnotation being applied to SimplePOJO class at:
- class level
- method level (all methods)
- field level (all fields)
So effectively the annotation is applied to all the methods, all fields and the class itself. Is this expected?
3) From what i showed in the annotation definition:
@Target(value=ElementType.TYPE)
| public @interface MyOwnAnnotation
|
The "target" of MyOwnAnnotation is a ElementType.TYPE, but it got applied to methods and fields by AOP (as explained in #2). Doesn't AOP validate the target type before applying the annotations and throw an error if adding the annotation is incorrect?
Let me know, if you need the sample application which demonstrates this along with the logs - its just a simple modified version of what is available in the examples/annotation-introduction in SVN.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4222982#4222982
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4222982
More information about the jboss-user
mailing list