KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > joinpoint > impl > FieldSignatureImpl


1 /**************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- *
5  * The software in this package is published under the terms of the LGPL license *
6  * a copy of which has been included with this distribution in the license.txt file. *
7  **************************************************************************************/

8 package org.codehaus.aspectwerkz.joinpoint.impl;
9
10 import org.codehaus.aspectwerkz.annotation.Annotation;
11 import org.codehaus.aspectwerkz.annotation.Annotations;
12 import org.codehaus.aspectwerkz.joinpoint.FieldSignature;
13
14 import java.lang.reflect.Field JavaDoc;
15 import java.util.List JavaDoc;
16
17 /**
18  * Implementation for the field signature.
19  *
20  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
21  */

22 public class FieldSignatureImpl implements FieldSignature {
23     private final Class JavaDoc m_declaringType;
24
25     private final Field JavaDoc m_field;
26
27     /**
28      * @param field
29      * @param declaringType
30      */

31     public FieldSignatureImpl(final Class JavaDoc declaringType, final Field JavaDoc field) {
32         m_declaringType = declaringType;
33         m_field = field;
34         m_field.setAccessible(true);
35     }
36
37     /**
38      * Returns the declaring class.
39      *
40      * @return the declaring class
41      */

42     public Class JavaDoc getDeclaringType() {
43         return m_declaringType;
44     }
45
46     /**
47      * Returns the modifiers for the signature. <p/>Could be used like this:
48      * <p/>
49      * <pre>
50      * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
51      * </pre>
52      *
53      * @return the mofifiers
54      */

55     public int getModifiers() {
56         return m_field.getModifiers();
57     }
58
59     /**
60      * Returns the name (f.e. name of method of field).
61      *
62      * @return the name
63      */

64     public String JavaDoc getName() {
65         return m_field.getName();
66     }
67
68     /**
69      * Returns the field.
70      *
71      * @return the field
72      */

73     public Field JavaDoc getField() {
74         return m_field;
75     }
76
77     /**
78      * Returns the field type.
79      *
80      * @return the field type
81      */

82     public Class JavaDoc getFieldType() {
83         return m_field.getType();
84     }
85
86     /**
87      * Return the annotation with a specific name.
88      *
89      * @param annotationName the annotation name
90      * @return the annotation or null
91      */

92     public Annotation getAnnotation(final String JavaDoc annotationName) {
93         return Annotations.getAnnotation(annotationName, m_field);
94     }
95
96     /**
97      * Return a list with the annotations with a specific name.
98      *
99      * @param annotationName the annotation name
100      * @return the annotations in a list (can be empty)
101      */

102     public List JavaDoc getAnnotations(final String JavaDoc annotationName) {
103         return Annotations.getAnnotations(annotationName, m_field);
104     }
105
106     /**
107      * Return all the annotations <p/>Each annotation is wrapped in
108      * {@link org.codehaus.aspectwerkz.annotation.AnnotationInfo}instance.
109      *
110      * @return a list with the annotations
111      */

112     public List JavaDoc getAnnotationInfos() {
113         return Annotations.getAnnotationInfos(m_field);
114     }
115
116     /**
117      * Returns a string representation of the signature.
118      *
119      * @return a string representation
120      */

121     public String JavaDoc toString() {
122         return m_field.toString();
123     }
124 }
Popular Tags