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