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.CatchClauseRtti;
007: import com.tc.aspectwerkz.joinpoint.Rtti;
008:
009: import java.lang.ref.WeakReference;
010:
011: /**
012: * Implementation for the catch clause RTTI.
013: *
014: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
015: */
016: public class CatchClauseRttiImpl implements CatchClauseRtti {
017: private final CatchClauseSignatureImpl m_signature;
018:
019: private WeakReference m_this Ref;
020:
021: private WeakReference m_targetRef;
022:
023: private Object m_parameterValue;
024:
025: /**
026: * Creates a new catch clause RTTI.
027: *
028: * @param signature
029: * @param thisInstance
030: * @param targetInstance
031: */
032: public CatchClauseRttiImpl(
033: final CatchClauseSignatureImpl signature,
034: final Object this Instance, final Object targetInstance) {
035: m_signature = signature;
036: m_this Ref = new WeakReference(this Instance);
037: m_targetRef = new WeakReference(targetInstance);
038: }
039:
040: /**
041: * Clones the RTTI instance.
042: *
043: * @param thisInstance
044: * @param targetInstance
045: * @return
046: */
047: public Rtti cloneFor(final Object this Instance,
048: final Object targetInstance) {
049: return new CatchClauseRttiImpl(m_signature, this Instance,
050: targetInstance);
051: }
052:
053: /**
054: * Returns the instance currently executing.
055: *
056: * @return the instance currently executing
057: */
058: public Object getThis() {
059: return m_this Ref.get();
060: }
061:
062: /**
063: * Returns the target instance.
064: *
065: * @return the target instance
066: */
067: public Object getTarget() {
068: return m_targetRef.get();
069: }
070:
071: /**
072: * Returns the declaring class.
073: *
074: * @return the declaring class
075: */
076: public Class getDeclaringType() {
077: return m_signature.getDeclaringType();
078: }
079:
080: /**
081: * Returns the modifiers for the signature. <p/>Could be used like this:
082: * <p/>
083: * <pre>
084: * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
085: * </pre>
086: *
087: * @return the mofifiers
088: */
089: public int getModifiers() {
090: return m_signature.getModifiers();
091: }
092:
093: /**
094: * Returns the name (f.e. name of method of field).
095: *
096: * @return
097: */
098: public String getName() {
099: return m_signature.getName();
100: }
101:
102: /**
103: * Returns the parameter type.
104: *
105: * @return the parameter type
106: */
107: public Class getParameterType() {
108: return m_signature.getParameterType();
109: }
110:
111: /**
112: * Returns the value of the parameter.
113: *
114: * @return the value of the parameter
115: */
116: public Object getParameterValue() {
117: return getTarget();//m_parameterValue;
118: }
119:
120: /**
121: * Returns a string representation of the signature.
122: *
123: * @return a string representation
124: * @TODO: implement toString to something meaningful
125: */
126: public String toString() {
127: return super.toString();
128: }
129: }
|