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