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.ConstructorRtti;
007: import com.tc.aspectwerkz.joinpoint.Rtti;
008:
009: import java.lang.ref.WeakReference;
010: import java.lang.reflect.Constructor;
011:
012: /**
013: * Implementation for the constructor RTTI.
014: *
015: * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a>
016: */
017: public class ConstructorRttiImpl implements ConstructorRtti {
018: private static final Object[] EMPTY_OBJECT_ARRAY = new Object[] {};
019:
020: private final ConstructorSignatureImpl 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: /**
029: * Creates a new constructor RTTI.
030: *
031: * @param signature
032: * @param thisInstance
033: * @param targetInstance
034: */
035: public ConstructorRttiImpl(
036: final ConstructorSignatureImpl 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 ConstructorRttiImpl(m_signature, this Instance,
053: targetInstance);
054: }
055:
056: /**
057: * Returns the target instance.
058: *
059: * @return the target instance
060: */
061: public Object getTarget() {
062: return m_targetRef.get();
063: }
064:
065: /**
066: * Returns the instance currently executing.
067: *
068: * @return the instance currently executing
069: */
070: public Object getThis() {
071: return m_this Ref.get();
072: }
073:
074: /**
075: * Returns the constructor.
076: *
077: * @return the constructor
078: */
079: public Constructor getConstructor() {
080: return m_signature.getConstructor();
081: }
082:
083: /**
084: * Returns the declaring class.
085: *
086: * @return the declaring class
087: */
088: public Class getDeclaringType() {
089: return m_signature.getDeclaringType();
090: }
091:
092: /**
093: * Returns the modifiers for the signature. <p/>Could be used like this:
094: * <p/>
095: * <pre>
096: * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
097: * </pre>
098: *
099: * @return the mofifiers
100: */
101: public int getModifiers() {
102: return m_signature.getModifiers();
103: }
104:
105: /**
106: * Returns the name (f.e. name of method of field).
107: *
108: * @return
109: */
110: public String getName() {
111: return m_signature.getName();
112: }
113:
114: /**
115: * Returns the exception types declared by the code block.
116: *
117: * @return the exception types
118: */
119: public Class[] getExceptionTypes() {
120: return m_signature.getExceptionTypes();
121: }
122:
123: /**
124: * Returns the parameter types.
125: *
126: * @return the parameter types
127: */
128: public Class[] getParameterTypes() {
129: return m_signature.getParameterTypes();
130: }
131:
132: /**
133: * Sets the values of the parameters.
134: *
135: * @param parameterValues
136: */
137: public void setParameterValues(final Object[] parameterValues) {
138: m_parameterValues = parameterValues;
139: }
140:
141: /**
142: * Returns the values of the parameters.
143: *
144: * @return the values of the parameters
145: */
146: public Object[] getParameterValues() {
147: return m_parameterValues;
148: }
149:
150: /**
151: * Returns a string representation of the signature.
152: *
153: * @return a string representation
154: * @TODO: implement toString to something meaningful
155: */
156: public String toString() {
157: return super.toString();
158: }
159:
160: }
|