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