KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > joinpoint > impl > MethodRttiImpl


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.joinpoint.MethodRtti;
11 import org.codehaus.aspectwerkz.joinpoint.Rtti;
12
13 import java.lang.ref.WeakReference JavaDoc;
14 import java.lang.reflect.Method JavaDoc;
15
16 /**
17  * Implementation for the method signature.
18  *
19  * @author <a HREF="mailto:jboner@codehaus.org">Jonas Bonér </a>
20  */

21 public class MethodRttiImpl implements MethodRtti {
22     private static final Object JavaDoc[] EMPTY_OBJECT_ARRAY = new Object JavaDoc[]{};
23
24     private final MethodSignatureImpl m_signature;
25
26     private WeakReference JavaDoc m_thisRef;
27
28     private WeakReference JavaDoc m_targetRef;
29
30     private Object JavaDoc[] m_parameterValues = EMPTY_OBJECT_ARRAY;
31
32     private Object JavaDoc m_returnValue;
33
34     /**
35      * Creates a new method RTTI.
36      *
37      * @param signature
38      * @param thisInstance
39      * @param targetInstance
40      */

41     public MethodRttiImpl(final MethodSignatureImpl signature, final Object JavaDoc thisInstance, final Object JavaDoc targetInstance) {
42         m_signature = signature;
43         m_thisRef = new WeakReference JavaDoc(thisInstance);
44         m_targetRef = new WeakReference JavaDoc(targetInstance);
45     }
46
47     /**
48      * Clones the RTTI instance.
49      *
50      * @param thisInstance
51      * @param targetInstance
52      * @return
53      */

54     public Rtti cloneFor(final Object JavaDoc thisInstance, final Object JavaDoc targetInstance) {
55         return new MethodRttiImpl(m_signature, thisInstance, targetInstance);
56     }
57
58     /**
59      * Returns the target instance.
60      *
61      * @return the target instance
62      */

63     public Object JavaDoc getTarget() {
64         return m_targetRef.get();
65     }
66
67     /**
68      * Returns the instance currently executing.
69      *
70      * @return the instance currently executing
71      */

72     public Object JavaDoc getThis() {
73         return m_thisRef.get();
74     }
75
76     /**
77      * Returns the method.
78      *
79      * @return the method
80      */

81     public Method JavaDoc getMethod() {
82         return m_signature.getMethod();
83     }
84
85     /**
86      * Returns the declaring class.
87      *
88      * @return the declaring class
89      */

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

103     public int getModifiers() {
104         return m_signature.getModifiers();
105     }
106
107     /**
108      * Returns the name (f.e. name of method of field).
109      *
110      * @return
111      */

112     public String JavaDoc getName() {
113         return m_signature.getName();
114     }
115
116     /**
117      * Returns the exception types declared by the code block.
118      *
119      * @return the exception types
120      */

121     public Class JavaDoc[] getExceptionTypes() {
122         return m_signature.getExceptionTypes();
123     }
124
125     /**
126      * Returns the parameter types.
127      *
128      * @return the parameter types
129      */

130     public Class JavaDoc[] getParameterTypes() {
131         return m_signature.getParameterTypes();
132     }
133
134     /**
135      * Sets the values of the parameters.
136      *
137      * @param parameterValues
138      */

139     public void setParameterValues(final Object JavaDoc[] parameterValues) {
140         m_parameterValues = parameterValues;
141     }
142
143     /**
144      * Returns the values of the parameters.
145      *
146      * @return the values of the parameters
147      */

148     public Object JavaDoc[] getParameterValues() {
149         return m_parameterValues;
150     }
151
152     /**
153      * Returns the return type.
154      *
155      * @return the return type
156      */

157     public Class JavaDoc getReturnType() {
158         return m_signature.getReturnType();
159     }
160
161     /**
162      * Sets the return value.
163      *
164      * @param returnValue the return value
165      */

166     public void setReturnValue(final Object JavaDoc returnValue) {
167         m_returnValue = returnValue;
168     }
169
170     /**
171      * Returns the value of the return type.
172      *
173      * @return the value of the return type
174      */

175     public Object JavaDoc getReturnValue() {
176         return m_returnValue;
177     }
178
179     /**
180      * Returns a string representation of the signature.
181      *
182      * @return a string representation
183      * @TODO: implement toString to something meaningful
184      */

185     public String JavaDoc toString() {
186         return super.toString();
187     }
188 }
Popular Tags