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.MethodSignature;
010:
011: import java.lang.reflect.Method;
012:
013: /**
014: * Implementation for the method signature.
015: *
016: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
017: */
018: public class MethodSignatureImpl implements MethodSignature {
019: private final Class m_declaringType;
020:
021: private final Method m_method;
022:
023: /**
024: * @param declaringType
025: * @param method
026: */
027: public MethodSignatureImpl(final Class declaringType,
028: final Method method) {
029: m_declaringType = declaringType;
030: m_method = method;
031: }
032:
033: /**
034: * Returns the method.
035: *
036: * @return the method
037: */
038: public Method getMethod() {
039: return m_method;
040: }
041:
042: /**
043: * Returns the declaring class.
044: *
045: * @return the declaring class
046: */
047: public Class getDeclaringType() {
048: return m_declaringType;
049: }
050:
051: /**
052: * Returns the modifiers for the signature. <p/>Could be used like this:
053: * <p/>
054: * <pre>
055: * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
056: * </pre>
057: *
058: * @return the mofifiers
059: */
060: public int getModifiers() {
061: return m_method.getModifiers();
062: }
063:
064: /**
065: * Returns the name (f.e. name of method of field).
066: *
067: * @return
068: */
069: public String getName() {
070: return m_method.getName();
071: }
072:
073: /**
074: * Returns the exception types declared by the code block.
075: *
076: * @return the exception types
077: */
078: public Class[] getExceptionTypes() {
079: return m_method.getExceptionTypes();
080: }
081:
082: /**
083: * Returns the parameter types.
084: *
085: * @return the parameter types
086: */
087: public Class[] getParameterTypes() {
088: return m_method.getParameterTypes();
089: }
090:
091: /**
092: * Returns the return type.
093: *
094: * @return the return type
095: */
096: public Class getReturnType() {
097: return m_method.getReturnType();
098: }
099:
100: /**
101: * Return the annotation with a specific class.
102: *
103: * @param annotationClass the annotation class
104: * @return the annotation or null
105: */
106: public Annotation getAnnotation(final Class annotationClass) {
107: return Annotations.getAnnotation(annotationClass, m_method);
108: }
109:
110: /**
111: * Return all the annotations.
112: *
113: * @return annotations
114: */
115: public Annotation[] getAnnotations() {
116: return Annotations.getAnnotations(m_method);
117: }
118:
119: /**
120: * Returns a string representation of the signature.
121: *
122: * @return a string representation
123: */
124: public String toString() {
125: return m_method.toString();
126: }
127: }
|