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.joinpoint.ConstructorRtti;
12 import org.codehaus.aspectwerkz.joinpoint.Rtti;
13
14 import java.lang.ref.WeakReference;
15 import java.lang.reflect.Constructor;
16
17 /***
18 * Implementation for the constructor RTTI.
19 *
20 * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
21 */
22 public class ConstructorRttiImpl implements ConstructorRtti {
23 private static final Object[] EMPTY_OBJECT_ARRAY = new Object[] {};
24
25 private final ConstructorSignatureImpl m_signature;
26
27 private WeakReference m_thisRef;
28
29 private WeakReference m_targetRef;
30
31 private Object[] m_parameterValues = EMPTY_OBJECT_ARRAY;
32
33 private Object m_newInstance;
34
35 /***
36 * Creates a new constructor RTTI.
37 *
38 * @param signature
39 * @param thisInstance
40 * @param targetInstance
41 */
42 public ConstructorRttiImpl(final ConstructorSignatureImpl signature,
43 final Object thisInstance,
44 final Object targetInstance) {
45 m_signature = signature;
46 m_thisRef = new WeakReference(thisInstance);
47 m_targetRef = new WeakReference(targetInstance);
48 }
49
50 /***
51 * Clones the RTTI instance.
52 *
53 * @param thisInstance
54 * @param targetInstance
55 * @return
56 */
57 public Rtti cloneFor(final Object thisInstance, final Object targetInstance) {
58 return new ConstructorRttiImpl(m_signature, thisInstance, targetInstance);
59 }
60
61 /***
62 * Returns the target instance.
63 *
64 * @return the target instance
65 */
66 public Object getTarget() {
67 return m_targetRef.get();
68 }
69
70 /***
71 * Returns the instance currently executing.
72 *
73 * @return the instance currently executing
74 */
75 public Object getThis() {
76 return m_thisRef.get();
77 }
78
79 /***
80 * Returns the constructor tuple.
81 *
82 * @return the constructor tuple
83 */
84 public ConstructorTuple getConstructorTuple() {
85 return m_signature.getConstructorTuple();
86 }
87
88 /***
89 * Returns the constructor.
90 *
91 * @return the constructor
92 */
93 public Constructor getConstructor() {
94 return m_signature.getConstructor();
95 }
96
97 /***
98 * Returns the declaring class.
99 *
100 * @return the declaring class
101 */
102 public Class getDeclaringType() {
103 return m_signature.getDeclaringType();
104 }
105
106 /***
107 * Returns the new instance created by the constructor.
108 *
109 * @return the new instance
110 */
111 public Object getNewInstance() {
112 return m_newInstance;
113 }
114
115 /***
116 * Sets the new instance created by the constructor.
117 *
118 * @param newInstance
119 */
120 public void setNewInstance(final Object newInstance) {
121 m_newInstance = newInstance;
122 }
123
124 /***
125 * Returns the modifiers for the signature. <p/>Could be used like this:
126 *
127 * <pre>
128 * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
129 * </pre>
130 *
131 * @return the mofifiers
132 */
133 public int getModifiers() {
134 return m_signature.getModifiers();
135 }
136
137 /***
138 * Returns the name (f.e. name of method of field).
139 *
140 * @return
141 */
142 public String getName() {
143 return m_signature.getName();
144 }
145
146 /***
147 * Returns the exception types declared by the code block.
148 *
149 * @return the exception types
150 */
151 public Class[] getExceptionTypes() {
152 return m_signature.getExceptionTypes();
153 }
154
155 /***
156 * Returns the parameter types.
157 *
158 * @return the parameter types
159 */
160 public Class[] getParameterTypes() {
161 return m_signature.getParameterTypes();
162 }
163
164 /***
165 * Sets the values of the parameters.
166 *
167 * @param parameterValues
168 */
169 public void setParameterValues(final Object[] parameterValues) {
170 m_parameterValues = parameterValues;
171 }
172
173 /***
174 * Returns the values of the parameters.
175 *
176 * @return the values of the parameters
177 */
178 public Object[] getParameterValues() {
179 return m_parameterValues;
180 }
181
182 /***
183 * Returns a string representation of the signature.
184 *
185 * @return a string representation
186 * @TODO: implement toString to something meaningful
187 */
188 public String toString() {
189 return super.toString();
190 }
191
192 }