001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.aspectwerkz.joinpoint.impl;
005:
006: import com.tc.backport175.Annotation;
007: import com.tc.backport175.Annotations;
008:
009: import com.tc.aspectwerkz.joinpoint.FieldSignature;
010:
011: import java.lang.reflect.Field;
012:
013: /**
014: * Implementation for the field signature.
015: *
016: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
017: */
018: public class FieldSignatureImpl implements FieldSignature {
019: private final Class m_declaringType;
020:
021: private final Field m_field;
022:
023: /**
024: * @param field
025: * @param declaringType
026: */
027: public FieldSignatureImpl(final Class declaringType,
028: final Field field) {
029: m_declaringType = declaringType;
030: m_field = field;
031: m_field.setAccessible(true);
032: }
033:
034: /**
035: * Returns the declaring class.
036: *
037: * @return the declaring class
038: */
039: public Class getDeclaringType() {
040: return m_declaringType;
041: }
042:
043: /**
044: * Returns the modifiers for the signature. <p/>Could be used like this:
045: * <p/>
046: * <pre>
047: * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
048: * </pre>
049: *
050: * @return the mofifiers
051: */
052: public int getModifiers() {
053: return m_field.getModifiers();
054: }
055:
056: /**
057: * Returns the name (f.e. name of method of field).
058: *
059: * @return the name
060: */
061: public String getName() {
062: return m_field.getName();
063: }
064:
065: /**
066: * Returns the field.
067: *
068: * @return the field
069: */
070: public Field getField() {
071: return m_field;
072: }
073:
074: /**
075: * Returns the field type.
076: *
077: * @return the field type
078: */
079: public Class getFieldType() {
080: return m_field.getType();
081: }
082:
083: /**
084: * Return the annotation with a specific class.
085: *
086: * @param annotationClass the annotation class
087: * @return the annotation or null
088: */
089: public Annotation getAnnotation(final Class annotationClass) {
090: return Annotations.getAnnotation(annotationClass, m_field);
091: }
092:
093: /**
094: * Return all the annotations.
095: *
096: * @return a list with the annotations
097: */
098: public Annotation[] getAnnotations() {
099: return Annotations.getAnnotations(m_field);
100: }
101:
102: /**
103: * Returns a string representation of the signature.
104: *
105: * @return a string representation
106: */
107: public String toString() {
108: return m_field.toString();
109: }
110: }
|