KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > introduction > AnnotationIntroduction


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.aop.introduction;
23
24 import javassist.CtClass;
25 import javassist.CtConstructor;
26 import javassist.CtField;
27 import javassist.CtMethod;
28 import org.jboss.aop.Advisor;
29 import org.jboss.aop.annotation.factory.duplicate.ast.ASTAnnotation;
30 import org.jboss.aop.annotation.factory.duplicate.ast.AnnotationParser;
31 import org.jboss.aop.annotation.factory.duplicate.ast.ParseException;
32 import org.jboss.aop.pointcut.AnnotationMatcher;
33 import org.jboss.aop.pointcut.ast.ASTStart;
34 import org.jboss.aop.pointcut.ast.TypeExpressionParser;
35
36 import java.io.StringReader JavaDoc;
37 import java.lang.reflect.Constructor JavaDoc;
38 import java.lang.reflect.Field JavaDoc;
39 import java.lang.reflect.Method JavaDoc;
40
41 /**
42  * Comment
43  *
44  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
45  * @version $Revision: 57019 $
46  */

47 public class AnnotationIntroduction
48 {
49    public static AnnotationIntroduction createMethodAnnotationIntroduction(String JavaDoc methodExpr, String JavaDoc annotationExpr, boolean invisible)
50    {
51       String JavaDoc expr = "method(" + methodExpr + ")";
52       return new AnnotationIntroduction(expr, annotationExpr, invisible);
53    }
54
55    public static AnnotationIntroduction createConstructorAnnotationIntroduction(String JavaDoc conExpr, String JavaDoc annotationExpr, boolean invisible)
56    {
57       String JavaDoc expr = "constructor(" + conExpr + ")";
58       return new AnnotationIntroduction(expr, annotationExpr, invisible);
59    }
60
61    public static AnnotationIntroduction createFieldAnnotationIntroduction(String JavaDoc fieldExpr, String JavaDoc annotationExpr, boolean invisible)
62    {
63       String JavaDoc expr = "field(" + fieldExpr + ")";
64       return new AnnotationIntroduction(expr, annotationExpr, invisible);
65    }
66
67    public static AnnotationIntroduction createClassAnnotationIntroduction(String JavaDoc classExpr, String JavaDoc annotationExpr, boolean invisible)
68    {
69       String JavaDoc expr = "class(" + classExpr + ")";
70       return new AnnotationIntroduction(expr, annotationExpr, invisible);
71    }
72
73    public static AnnotationIntroduction createComplexAnnotationIntroduction(String JavaDoc expr, String JavaDoc annotationExpr, boolean invisible)
74    {
75       return new AnnotationIntroduction(expr, annotationExpr, invisible);
76    }
77
78
79    private String JavaDoc originalExpression;
80    private String JavaDoc originalAnnotationExpr;
81    private ASTStart target;
82    private ASTAnnotation annotation;
83    private boolean invisible;
84
85    private AnnotationIntroduction(String JavaDoc expr, String JavaDoc annotationExpr, boolean invisible)
86    {
87       this.invisible = invisible;
88       originalAnnotationExpr = annotationExpr;
89       originalExpression = expr;
90       try
91       {
92          AnnotationParser parser = new AnnotationParser(new StringReader JavaDoc(annotationExpr));
93          org.jboss.aop.annotation.factory.duplicate.ast.ASTStart start = parser.Start();
94          annotation = (ASTAnnotation) start.jjtGetChild(0);
95       }
96       catch (ParseException e)
97       {
98          throw new RuntimeException JavaDoc(annotationExpr, e); //To change body of catch statement use Options | File Templates.
99
}
100       try
101       {
102          TypeExpressionParser parser = new TypeExpressionParser(new StringReader JavaDoc(expr));
103          target = parser.Start();
104       }
105       catch (org.jboss.aop.pointcut.ast.ParseException e)
106       {
107          throw new RuntimeException JavaDoc(expr, e); //To change body of catch statement use Options | File Templates.
108
}
109    }
110
111    public boolean matches(Advisor advisor, CtClass clazz)
112    {
113       AnnotationMatcher matcher = new AnnotationMatcher(advisor, clazz);
114       return ((Boolean JavaDoc) target.jjtAccept(matcher, null)).booleanValue();
115    }
116
117    public boolean matches(Advisor advisor, CtMethod method)
118    {
119       AnnotationMatcher matcher = new AnnotationMatcher(advisor, method);
120       return ((Boolean JavaDoc) target.jjtAccept(matcher, null)).booleanValue();
121    }
122
123    public boolean matches(Advisor advisor, CtConstructor con)
124    {
125       AnnotationMatcher matcher = new AnnotationMatcher(advisor, con);
126       return ((Boolean JavaDoc) target.jjtAccept(matcher, null)).booleanValue();
127    }
128
129    public boolean matches(Advisor advisor, CtField field)
130    {
131       AnnotationMatcher matcher = new AnnotationMatcher(advisor, field);
132       return ((Boolean JavaDoc) target.jjtAccept(matcher, null)).booleanValue();
133    }
134
135    public boolean matches(Advisor advisor, Class JavaDoc clazz)
136    {
137       AnnotationMatcher matcher = new AnnotationMatcher(advisor, clazz);
138       return ((Boolean JavaDoc) target.jjtAccept(matcher, null)).booleanValue();
139    }
140
141    public boolean matches(Advisor advisor, Method method)
142    {
143       AnnotationMatcher matcher = new AnnotationMatcher(advisor, method);
144       return ((Boolean JavaDoc) target.jjtAccept(matcher, null)).booleanValue();
145    }
146
147    public boolean matches(Advisor advisor, Constructor con)
148    {
149       AnnotationMatcher matcher = new AnnotationMatcher(advisor, con);
150       return ((Boolean JavaDoc) target.jjtAccept(matcher, null)).booleanValue();
151    }
152
153    public boolean matches(Advisor advisor, Field field)
154    {
155       AnnotationMatcher matcher = new AnnotationMatcher(advisor, field);
156       return ((Boolean JavaDoc) target.jjtAccept(matcher, null)).booleanValue();
157    }
158
159    public String JavaDoc getOriginalExpression()
160    {
161       return originalExpression;
162    }
163
164    public String JavaDoc getOriginalAnnotationExpr()
165    {
166       return originalAnnotationExpr;
167    }
168
169    public ASTAnnotation getAnnotation()
170    {
171       return annotation;
172    }
173
174    public boolean isInvisible()
175    {
176       return invisible;
177    }
178
179    public ASTStart getTarget()
180    {
181       return target;
182    }
183
184 }
185
Popular Tags