KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > annotation > AnnotationElement


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.annotation;
23
24 import java.lang.annotation.Annotation JavaDoc;
25 import java.lang.reflect.Constructor JavaDoc;
26 import java.lang.reflect.Field JavaDoc;
27 import java.lang.reflect.Method JavaDoc;
28
29 /**
30  * Bridge/portability class for resolving annotations in JDK 1.4 and JDK1.5
31  * Should be usable in JDK 1.4 and also should support finding invisible annotations.
32  * This would be needed for aspect bindings
33  *
34  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
35  * @version $Revision: 43697 $
36  */

37 public class AnnotationElement extends PortableAnnotationElement
38 {
39    /**
40     * Get a visible annotation for a particle Method. If this is JDK 1.5
41     * then this is a wrapper for Method.getAnnotation
42     *
43     * @param method
44     * @param annotation
45     * @return
46     */

47    public static Object JavaDoc getVisibleAnnotation(Method JavaDoc method, Class JavaDoc annotation)
48    {
49       return method.getAnnotation(annotation);
50    }
51
52    /**
53     * If constructor has visible annotation return it. If this is JDK 1.5
54     * this is a wrapper for Constructor.getAnnotation()
55     *
56     * @param con
57     * @param annotation
58     * @return
59     */

60    public static Object JavaDoc getVisibleAnnotation(Constructor JavaDoc con, Class JavaDoc annotation)
61    {
62       return con.getAnnotation(annotation);
63    }
64
65    /**
66     * If field has a visible annotation return it. If this is JDK 1.5 this is a wrapper
67     * for Field.getAnnotation.
68     *
69     * @param field
70     * @param annotation
71     * @return
72     */

73    public static Object JavaDoc getVisibleAnnotation(Field JavaDoc field, Class JavaDoc annotation)
74    {
75       return field.getAnnotation(annotation);
76    }
77
78    /**
79     * If class has a visible annotation, return it. If this is JDK 1.5 this is a wrapper
80     * for Class.getAnnotation
81     *
82     * @param clazz
83     * @param annotation
84     * @return
85     */

86    public static Object JavaDoc getVisibleAnnotation(Class JavaDoc clazz, Class JavaDoc annotation)
87    {
88       return clazz.getAnnotation(annotation);
89    }
90
91    public static boolean isVisibleAnnotationPresent(Class JavaDoc clazz, Class JavaDoc annotation)
92    {
93       return clazz.isAnnotationPresent(annotation);
94    }
95
96    public static boolean isVisibleAnnotationPresent(Method JavaDoc m, Class JavaDoc annotation)
97    {
98       return m.isAnnotationPresent(annotation);
99    }
100
101    public static boolean isVisibleAnnotationPresent(Field JavaDoc f, Class JavaDoc annotation)
102    {
103       return f.isAnnotationPresent(annotation);
104    }
105
106    public static boolean isVisibleAnnotationPresent(Constructor JavaDoc con, Class JavaDoc annotation)
107    {
108       return con.isAnnotationPresent(annotation);
109    }
110
111    public static Object JavaDoc[] getVisibleAnnotations(Class JavaDoc clazz) throws Exception JavaDoc
112    {
113       return clazz.getAnnotations();
114    }
115
116    public static Object JavaDoc[] getVisibleAnnotations(Method JavaDoc m) throws Exception JavaDoc
117    {
118       return m.getAnnotations();
119    }
120    
121    public static Object JavaDoc[] getVisibleAnnotations(Field JavaDoc f) throws Exception JavaDoc
122    {
123       return f.getAnnotations();
124    }
125    
126    public static Object JavaDoc[] getVisibleAnnotations(Constructor JavaDoc c) throws Exception JavaDoc
127    {
128       return c.getAnnotations();
129    }
130 }
131
Popular Tags