KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > joinpoint > impl > ConstructorRttiImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.joinpoint.impl;
5
6 import com.tc.aspectwerkz.joinpoint.ConstructorRtti;
7 import com.tc.aspectwerkz.joinpoint.Rtti;
8
9 import java.lang.ref.WeakReference JavaDoc;
10 import java.lang.reflect.Constructor JavaDoc;
11
12 /**
13  * Implementation for the constructor RTTI.
14  *
15  * @author <a HREF="mailto:jboner@codehaus.org">Jonas BonŽr </a>
16  */

17 public class ConstructorRttiImpl implements ConstructorRtti {
18   private static final Object JavaDoc[] EMPTY_OBJECT_ARRAY = new Object JavaDoc[]{};
19
20   private final ConstructorSignatureImpl m_signature;
21
22   private WeakReference JavaDoc m_thisRef;
23
24   private WeakReference JavaDoc m_targetRef;
25
26   private Object JavaDoc[] m_parameterValues = EMPTY_OBJECT_ARRAY;
27
28   /**
29    * Creates a new constructor RTTI.
30    *
31    * @param signature
32    * @param thisInstance
33    * @param targetInstance
34    */

35   public ConstructorRttiImpl(final ConstructorSignatureImpl signature,
36                              final Object JavaDoc thisInstance,
37                              final Object JavaDoc targetInstance) {
38     m_signature = signature;
39     m_thisRef = new WeakReference JavaDoc(thisInstance);
40     m_targetRef = new WeakReference JavaDoc(targetInstance);
41   }
42
43   /**
44    * Clones the RTTI instance.
45    *
46    * @param thisInstance
47    * @param targetInstance
48    * @return
49    */

50   public Rtti cloneFor(final Object JavaDoc thisInstance, final Object JavaDoc targetInstance) {
51     return new ConstructorRttiImpl(m_signature, thisInstance, targetInstance);
52   }
53
54   /**
55    * Returns the target instance.
56    *
57    * @return the target instance
58    */

59   public Object JavaDoc getTarget() {
60     return m_targetRef.get();
61   }
62
63   /**
64    * Returns the instance currently executing.
65    *
66    * @return the instance currently executing
67    */

68   public Object JavaDoc getThis() {
69     return m_thisRef.get();
70   }
71
72   /**
73    * Returns the constructor.
74    *
75    * @return the constructor
76    */

77   public Constructor JavaDoc getConstructor() {
78     return m_signature.getConstructor();
79   }
80
81   /**
82    * Returns the declaring class.
83    *
84    * @return the declaring class
85    */

86   public Class JavaDoc getDeclaringType() {
87     return m_signature.getDeclaringType();
88   }
89
90   /**
91    * Returns the modifiers for the signature. <p/>Could be used like this:
92    * <p/>
93    * <pre>
94    * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
95    * </pre>
96    *
97    * @return the mofifiers
98    */

99   public int getModifiers() {
100     return m_signature.getModifiers();
101   }
102
103   /**
104    * Returns the name (f.e. name of method of field).
105    *
106    * @return
107    */

108   public String JavaDoc getName() {
109     return m_signature.getName();
110   }
111
112   /**
113    * Returns the exception types declared by the code block.
114    *
115    * @return the exception types
116    */

117   public Class JavaDoc[] getExceptionTypes() {
118     return m_signature.getExceptionTypes();
119   }
120
121   /**
122    * Returns the parameter types.
123    *
124    * @return the parameter types
125    */

126   public Class JavaDoc[] getParameterTypes() {
127     return m_signature.getParameterTypes();
128   }
129
130   /**
131    * Sets the values of the parameters.
132    *
133    * @param parameterValues
134    */

135   public void setParameterValues(final Object JavaDoc[] parameterValues) {
136     m_parameterValues = parameterValues;
137   }
138
139   /**
140    * Returns the values of the parameters.
141    *
142    * @return the values of the parameters
143    */

144   public Object JavaDoc[] getParameterValues() {
145     return m_parameterValues;
146   }
147
148   /**
149    * Returns a string representation of the signature.
150    *
151    * @return a string representation
152    * @TODO: implement toString to something meaningful
153    */

154   public String JavaDoc toString() {
155     return super.toString();
156   }
157
158 }
Popular Tags