001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.aspectwerkz.joinpoint.impl;
005:
006: import com.tc.aspectwerkz.joinpoint.MethodRtti;
007: import com.tc.aspectwerkz.joinpoint.Rtti;
008:
009: import java.lang.ref.WeakReference;
010: import java.lang.reflect.Method;
011:
012: /**
013: * Implementation for the method signature.
014: *
015: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
016: */
017: public class MethodRttiImpl implements MethodRtti {
018: private static final Object[] EMPTY_OBJECT_ARRAY = new Object[] {};
019:
020: private final MethodSignatureImpl m_signature;
021:
022: private WeakReference m_this Ref;
023:
024: private WeakReference m_targetRef;
025:
026: private Object[] m_parameterValues = EMPTY_OBJECT_ARRAY;
027:
028: private Object m_returnValue;
029:
030: /**
031: * Creates a new method RTTI.
032: *
033: * @param signature
034: * @param thisInstance
035: * @param targetInstance
036: */
037: public MethodRttiImpl(final MethodSignatureImpl signature,
038: final Object this Instance, final Object targetInstance) {
039: m_signature = signature;
040: m_this Ref = new WeakReference(this Instance);
041: m_targetRef = new WeakReference(targetInstance);
042: }
043:
044: /**
045: * Clones the RTTI instance.
046: *
047: * @param thisInstance
048: * @param targetInstance
049: * @return
050: */
051: public Rtti cloneFor(final Object this Instance,
052: final Object targetInstance) {
053: return new MethodRttiImpl(m_signature, this Instance,
054: targetInstance);
055: }
056:
057: /**
058: * Returns the target instance.
059: *
060: * @return the target instance
061: */
062: public Object getTarget() {
063: return m_targetRef.get();
064: }
065:
066: /**
067: * Returns the instance currently executing.
068: *
069: * @return the instance currently executing
070: */
071: public Object getThis() {
072: return m_this Ref.get();
073: }
074:
075: /**
076: * Returns the method.
077: *
078: * @return the method
079: */
080: public Method getMethod() {
081: return m_signature.getMethod();
082: }
083:
084: /**
085: * Returns the declaring class.
086: *
087: * @return the declaring class
088: */
089: public Class getDeclaringType() {
090: return m_signature.getDeclaringType();
091: }
092:
093: /**
094: * Returns the modifiers for the signature. <p/>Could be used like this:
095: * <p/>
096: * <pre>
097: * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
098: * </pre>
099: *
100: * @return the mofifiers
101: */
102: public int getModifiers() {
103: return m_signature.getModifiers();
104: }
105:
106: /**
107: * Returns the name (f.e. name of method of field).
108: *
109: * @return
110: */
111: public String getName() {
112: return m_signature.getName();
113: }
114:
115: /**
116: * Returns the exception types declared by the code block.
117: *
118: * @return the exception types
119: */
120: public Class[] getExceptionTypes() {
121: return m_signature.getExceptionTypes();
122: }
123:
124: /**
125: * Returns the parameter types.
126: *
127: * @return the parameter types
128: */
129: public Class[] getParameterTypes() {
130: return m_signature.getParameterTypes();
131: }
132:
133: /**
134: * Sets the values of the parameters.
135: *
136: * @param parameterValues
137: */
138: public void setParameterValues(final Object[] parameterValues) {
139: m_parameterValues = parameterValues;
140: }
141:
142: /**
143: * Returns the values of the parameters.
144: *
145: * @return the values of the parameters
146: */
147: public Object[] getParameterValues() {
148: return m_parameterValues;
149: }
150:
151: /**
152: * Returns the return type.
153: *
154: * @return the return type
155: */
156: public Class getReturnType() {
157: return m_signature.getReturnType();
158: }
159:
160: /**
161: * Sets the return value.
162: *
163: * @param returnValue the return value
164: */
165: public void setReturnValue(final Object returnValue) {
166: m_returnValue = returnValue;
167: }
168:
169: /**
170: * Returns the value of the return type.
171: *
172: * @return the value of the return type
173: */
174: public Object getReturnValue() {
175: return m_returnValue;
176: }
177:
178: /**
179: * Returns a string representation of the signature.
180: *
181: * @return a string representation
182: * @TODO: implement toString to something meaningful
183: */
184: public String toString() {
185: return super.toString();
186: }
187: }
|