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.annotation.Annotation;
11  import org.codehaus.aspectwerkz.annotation.Annotations;
12  import org.codehaus.aspectwerkz.joinpoint.ConstructorSignature;
13  
14  import java.lang.reflect.Constructor;
15  import java.util.List;
16  
17  /***
18   * Implementation for the constructor signature.
19   *
20   * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
21   */
22  public class ConstructorSignatureImpl implements ConstructorSignature {
23      private final Class m_declaringType;
24  
25      private final Constructor m_constructor;
26  
27      /***
28       * @param declaringType
29       * @param constructor
30       */
31      public ConstructorSignatureImpl(final Class declaringType, final Constructor constructor) {
32          m_declaringType = declaringType;
33          m_constructor = constructor;
34      }
35  
36      /***
37       * Returns the constructor.
38       *
39       * @return the constructor
40       */
41      public Constructor getConstructor() {
42          return m_constructor;
43      }
44  
45      /***
46       * Returns the declaring class.
47       *
48       * @return the declaring class
49       */
50      public Class getDeclaringType() {
51          return m_declaringType;
52      }
53  
54      /***
55       * Returns the modifiers for the signature. <p/>Could be used like this:
56       * <p/>
57       * <pre>
58       * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
59       * </pre>
60       *
61       * @return the mofifiers
62       */
63      public int getModifiers() {
64          return m_constructor.getModifiers();
65      }
66  
67      /***
68       * Returns the name (f.e. name of method of field).
69       *
70       * @return
71       */
72      public String getName() {
73          //return m_constructorTuple.getName();
74          return m_constructor.getName();
75      }
76  
77      /***
78       * Returns the exception types declared by the code block.
79       *
80       * @return the exception types
81       */
82      public Class[] getExceptionTypes() {
83          return m_constructor.getExceptionTypes();
84      }
85  
86      /***
87       * Returns the parameter types.
88       *
89       * @return the parameter types
90       */
91      public Class[] getParameterTypes() {
92          return m_constructor.getParameterTypes();
93      }
94  
95      /***
96       * Return the annotation with a specific name.
97       *
98       * @param annotationName the annotation name
99       * @return the annotation or null
100      */
101     public Annotation getAnnotation(final String annotationName) {
102         return Annotations.getAnnotation(annotationName, m_constructor);
103     }
104 
105     /***
106      * Return a list with the annotations with a specific name.
107      *
108      * @param annotationName the annotation name
109      * @return the annotations in a list (can be empty)
110      */
111     public List getAnnotations(final String annotationName) {
112         return Annotations.getAnnotations(annotationName, m_constructor);
113     }
114 
115     /***
116      * Return all the annotations <p/>Each annotation is wrapped in
117      * {@link org.codehaus.aspectwerkz.annotation.AnnotationInfo}instance.
118      *
119      * @return a list with the annotations
120      */
121     public List getAnnotationInfos() {
122         return Annotations.getAnnotationInfos(m_constructor);
123     }
124 
125     /***
126      * Returns a string representation of the signature.
127      *
128      * @return a string representation
129      */
130     public String toString() {
131         return m_constructor.toString();
132     }
133 }