View Javadoc

1   /***************************************************************************************
2    * Copyright (c) Jonas Bonér, Alexandre Vasseur. All rights reserved.                 *
3    * http://aspectwerkz.codehaus.org                                                    *
4    * ---------------------------------------------------------------------------------- *
5    * The software in this package is published under the terms of the LGPL license      *
6    * a copy of which has been included with this distribution in the license.txt file.  *
7    **************************************************************************************/
8   package org.codehaus.aspectwerkz.joinpoint.impl;
9   
10  import org.codehaus.aspectwerkz.ConstructorTuple;
11  import org.codehaus.aspectwerkz.annotation.Annotation;
12  import org.codehaus.aspectwerkz.annotation.Annotations;
13  import org.codehaus.aspectwerkz.joinpoint.ConstructorSignature;
14  
15  import java.lang.reflect.Constructor;
16  import java.util.List;
17  
18  /***
19   * Implementation for the constructor signature.
20   * 
21   * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
22   */
23  public class ConstructorSignatureImpl implements ConstructorSignature {
24      private final Class m_declaringType;
25  
26      private final ConstructorTuple m_constructorTuple;
27  
28      /***
29       * @param declaringType
30       * @param constructorTuple
31       */
32      public ConstructorSignatureImpl(final Class declaringType, final ConstructorTuple constructorTuple) {
33          m_declaringType = declaringType;
34          m_constructorTuple = constructorTuple;
35      }
36  
37      /***
38       * Returns the constructor tuple.
39       * 
40       * @return the constructor tuple
41       */
42      public ConstructorTuple getConstructorTuple() {
43          return m_constructorTuple;
44      }
45  
46      /***
47       * Returns the constructor.
48       * 
49       * @return the constructor
50       */
51      public Constructor getConstructor() {
52          return m_constructorTuple.getOriginalConstructor();
53      }
54  
55      /***
56       * Returns the declaring class.
57       * 
58       * @return the declaring class
59       */
60      public Class getDeclaringType() {
61          return m_declaringType;
62      }
63  
64      /***
65       * Returns the modifiers for the signature. <p/>Could be used like this:
66       * 
67       * <pre>
68       * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
69       * </pre>
70       * 
71       * @return the mofifiers
72       */
73      public int getModifiers() {
74          return m_constructorTuple.getOriginalConstructor().getModifiers();
75      }
76  
77      /***
78       * Returns the name (f.e. name of method of field).
79       * 
80       * @return
81       */
82      public String getName() {
83          return m_constructorTuple.getName();
84      }
85  
86      /***
87       * Returns the exception types declared by the code block.
88       * 
89       * @return the exception types
90       */
91      public Class[] getExceptionTypes() {
92          return m_constructorTuple.getOriginalConstructor().getExceptionTypes();
93      }
94  
95      /***
96       * Returns the parameter types.
97       * 
98       * @return the parameter types
99       */
100     public Class[] getParameterTypes() {
101         return m_constructorTuple.getOriginalConstructor().getParameterTypes();
102     }
103 
104     /***
105      * Return the annotation with a specific name.
106      * 
107      * @param annotationName the annotation name
108      * @return the annotation or null
109      */
110     public Annotation getAnnotation(final String annotationName) {
111         return Annotations.getAnnotation(annotationName, m_constructorTuple.getWrapperConstructor());
112     }
113 
114     /***
115      * Return a list with the annotations with a specific name.
116      * 
117      * @param annotationName the annotation name
118      * @return the annotations in a list (can be empty)
119      */
120     public List getAnnotations(final String annotationName) {
121         return Annotations.getAnnotations(annotationName, m_constructorTuple.getWrapperConstructor());        
122     }
123 
124     /***
125      * Return all the annotations <p/>Each annotation is wrapped in
126      * {@link org.codehaus.aspectwerkz.annotation.AnnotationInfo}instance.
127      * 
128      * @return a list with the annotations
129      */
130     public List getAnnotationInfos() {
131         return Annotations.getAnnotationInfos(m_constructorTuple.getWrapperConstructor());
132     }
133 
134     /***
135      * Returns a string representation of the signature.
136      * 
137      * @return a string representation
138      * @TODO: implement toString to something meaningful
139      */
140     public String toString() {
141         return super.toString();
142     }
143 }