001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package org.codehaus.aspectwerkz.joinpoint.impl;
008:
009: import org.codehaus.aspectwerkz.annotation.Annotation;
010: import org.codehaus.aspectwerkz.annotation.Annotations;
011: import org.codehaus.aspectwerkz.joinpoint.FieldSignature;
012:
013: import java.lang.reflect.Field;
014: import java.util.List;
015:
016: /**
017: * Implementation for the field signature.
018: *
019: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
020: */
021: public class FieldSignatureImpl implements FieldSignature {
022: private final Class m_declaringType;
023:
024: private final Field m_field;
025:
026: /**
027: * @param field
028: * @param declaringType
029: */
030: public FieldSignatureImpl(final Class declaringType,
031: final Field field) {
032: m_declaringType = declaringType;
033: m_field = field;
034: m_field.setAccessible(true);
035: }
036:
037: /**
038: * Returns the declaring class.
039: *
040: * @return the declaring class
041: */
042: public Class getDeclaringType() {
043: return m_declaringType;
044: }
045:
046: /**
047: * Returns the modifiers for the signature. <p/>Could be used like this:
048: * <p/>
049: * <pre>
050: * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
051: * </pre>
052: *
053: * @return the mofifiers
054: */
055: public int getModifiers() {
056: return m_field.getModifiers();
057: }
058:
059: /**
060: * Returns the name (f.e. name of method of field).
061: *
062: * @return the name
063: */
064: public String getName() {
065: return m_field.getName();
066: }
067:
068: /**
069: * Returns the field.
070: *
071: * @return the field
072: */
073: public Field getField() {
074: return m_field;
075: }
076:
077: /**
078: * Returns the field type.
079: *
080: * @return the field type
081: */
082: public Class getFieldType() {
083: return m_field.getType();
084: }
085:
086: /**
087: * Return the annotation with a specific name.
088: *
089: * @param annotationName the annotation name
090: * @return the annotation or null
091: */
092: public Annotation getAnnotation(final String annotationName) {
093: return Annotations.getAnnotation(annotationName, m_field);
094: }
095:
096: /**
097: * Return a list with the annotations with a specific name.
098: *
099: * @param annotationName the annotation name
100: * @return the annotations in a list (can be empty)
101: */
102: public List getAnnotations(final String 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 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 toString() {
122: return m_field.toString();
123: }
124: }
|