KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > joinpoint > impl > FieldSignatureImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.joinpoint.impl;
5
6 import com.tc.backport175.Annotation;
7 import com.tc.backport175.Annotations;
8
9 import com.tc.aspectwerkz.joinpoint.FieldSignature;
10
11 import java.lang.reflect.Field JavaDoc;
12
13 /**
14  * Implementation for the field signature.
15  *
16  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
17  */

18 public class FieldSignatureImpl implements FieldSignature {
19   private final Class JavaDoc m_declaringType;
20
21   private final Field JavaDoc m_field;
22
23   /**
24    * @param field
25    * @param declaringType
26    */

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

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

51   public int getModifiers() {
52     return m_field.getModifiers();
53   }
54
55   /**
56    * Returns the name (f.e. name of method of field).
57    *
58    * @return the name
59    */

60   public String JavaDoc getName() {
61     return m_field.getName();
62   }
63
64   /**
65    * Returns the field.
66    *
67    * @return the field
68    */

69   public Field JavaDoc getField() {
70     return m_field;
71   }
72
73   /**
74    * Returns the field type.
75    *
76    * @return the field type
77    */

78   public Class JavaDoc getFieldType() {
79     return m_field.getType();
80   }
81
82   /**
83    * Return the annotation with a specific class.
84    *
85    * @param annotationClass the annotation class
86    * @return the annotation or null
87    */

88   public Annotation getAnnotation(final Class JavaDoc annotationClass) {
89     return Annotations.getAnnotation(annotationClass, m_field);
90   }
91
92   /**
93    * Return all the annotations.
94    *
95    * @return a list with the annotations
96    */

97   public Annotation[] getAnnotations() {
98     return Annotations.getAnnotations(m_field);
99   }
100
101   /**
102    * Returns a string representation of the signature.
103    *
104    * @return a string representation
105    */

106   public String JavaDoc toString() {
107     return m_field.toString();
108   }
109 }
Popular Tags