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