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