1 /*************************************************************************************** 2 * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. * 3 * http://aspectwerkz.codehaus.org * 4 * ---------------------------------------------------------------------------------- * 5 * The software in this package is published under the terms of the LGPL license * 6 * a copy of which has been included with this distribution in the license.txt file. * 7 **************************************************************************************/ 8 package org.codehaus.aspectwerkz.joinpoint.impl; 9 10 import org.codehaus.aspectwerkz.joinpoint.ConstructorRtti; 11 import org.codehaus.aspectwerkz.joinpoint.Rtti; 12 13 import java.lang.ref.WeakReference; 14 import java.lang.reflect.Constructor; 15 16 /*** 17 * Implementation for the constructor RTTI. 18 * 19 * @author <a href="mailto:jboner@codehaus.org">Jonas BonŽr </a> 20 */ 21 public class ConstructorRttiImpl implements ConstructorRtti { 22 private static final Object[] EMPTY_OBJECT_ARRAY = new Object[]{}; 23 24 private final ConstructorSignatureImpl m_signature; 25 26 private WeakReference m_thisRef; 27 28 private WeakReference m_targetRef; 29 30 private Object[] m_parameterValues = EMPTY_OBJECT_ARRAY; 31 32 /*** 33 * Creates a new constructor RTTI. 34 * 35 * @param signature 36 * @param thisInstance 37 * @param targetInstance 38 */ 39 public ConstructorRttiImpl(final ConstructorSignatureImpl signature, 40 final Object thisInstance, 41 final Object targetInstance) { 42 m_signature = signature; 43 m_thisRef = new WeakReference(thisInstance); 44 m_targetRef = new WeakReference(targetInstance); 45 } 46 47 /*** 48 * Clones the RTTI instance. 49 * 50 * @param thisInstance 51 * @param targetInstance 52 * @return 53 */ 54 public Rtti cloneFor(final Object thisInstance, final Object targetInstance) { 55 return new ConstructorRttiImpl(m_signature, thisInstance, targetInstance); 56 } 57 58 /*** 59 * Returns the target instance. 60 * 61 * @return the target instance 62 */ 63 public Object getTarget() { 64 return m_targetRef.get(); 65 } 66 67 /*** 68 * Returns the instance currently executing. 69 * 70 * @return the instance currently executing 71 */ 72 public Object getThis() { 73 return m_thisRef.get(); 74 } 75 76 /*** 77 * Returns the constructor. 78 * 79 * @return the constructor 80 */ 81 public Constructor getConstructor() { 82 return m_signature.getConstructor(); 83 } 84 85 /*** 86 * Returns the declaring class. 87 * 88 * @return the declaring class 89 */ 90 public Class getDeclaringType() { 91 return m_signature.getDeclaringType(); 92 } 93 94 /*** 95 * Returns the modifiers for the signature. <p/>Could be used like this: 96 * <p/> 97 * <pre> 98 * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers()); 99 * </pre> 100 * 101 * @return the mofifiers 102 */ 103 public int getModifiers() { 104 return m_signature.getModifiers(); 105 } 106 107 /*** 108 * Returns the name (f.e. name of method of field). 109 * 110 * @return 111 */ 112 public String getName() { 113 return m_signature.getName(); 114 } 115 116 /*** 117 * Returns the exception types declared by the code block. 118 * 119 * @return the exception types 120 */ 121 public Class[] getExceptionTypes() { 122 return m_signature.getExceptionTypes(); 123 } 124 125 /*** 126 * Returns the parameter types. 127 * 128 * @return the parameter types 129 */ 130 public Class[] getParameterTypes() { 131 return m_signature.getParameterTypes(); 132 } 133 134 /*** 135 * Sets the values of the parameters. 136 * 137 * @param parameterValues 138 */ 139 public void setParameterValues(final Object[] parameterValues) { 140 m_parameterValues = parameterValues; 141 } 142 143 /*** 144 * Returns the values of the parameters. 145 * 146 * @return the values of the parameters 147 */ 148 public Object[] getParameterValues() { 149 return m_parameterValues; 150 } 151 152 /*** 153 * Returns a string representation of the signature. 154 * 155 * @return a string representation 156 * @TODO: implement toString to something meaningful 157 */ 158 public String toString() { 159 return super.toString(); 160 } 161 162 }