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.FieldRtti;
007: import com.tc.aspectwerkz.joinpoint.Rtti;
008:
009: import java.lang.ref.WeakReference;
010: import java.lang.reflect.Field;
011:
012: /**
013: * Implementation for the field signature.
014: *
015: * @author <a href="mailto:jboner@codehaus.org">Jonas Bon�r </a>
016: */
017: public class FieldRttiImpl implements FieldRtti {
018: private final FieldSignatureImpl m_signature;
019:
020: private WeakReference m_this Ref;
021:
022: private WeakReference m_targetRef;
023:
024: private Object m_fieldValue;
025:
026: /**
027: * Creates a new field RTTI.
028: *
029: * @param signature
030: * @param thisInstance
031: * @param targetInstance
032: */
033: public FieldRttiImpl(final FieldSignatureImpl 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 FieldRttiImpl(m_signature, this Instance,
050: targetInstance);
051: }
052:
053: /**
054: * Returns the target instance.
055: *
056: * @return the target instance
057: */
058: public Object getTarget() {
059: return m_targetRef.get();
060: }
061:
062: /**
063: * Returns the instance currently executing.
064: *
065: * @return the instance currently executing
066: */
067: public Object getThis() {
068: return m_this Ref.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 the name
097: */
098: public String getName() {
099: return m_signature.getName();
100: }
101:
102: /**
103: * Returns the field.
104: *
105: * @return the field
106: */
107: public Field getField() {
108: return m_signature.getField();
109: }
110:
111: /**
112: * Returns the field type.
113: *
114: * @return the field type
115: */
116: public Class getFieldType() {
117: return m_signature.getFieldType();
118: }
119:
120: /**
121: * Returns the value of the field.
122: *
123: * @return the value of the field
124: */
125: public Object getFieldValue() {
126: return m_fieldValue;
127: }
128:
129: /**
130: * Sets the value of the field.
131: *
132: * @param fieldValue the value of the field
133: */
134: public void setFieldValue(final Object fieldValue) {
135: m_fieldValue = fieldValue;
136: }
137:
138: /**
139: * Returns a string representation of the signature.
140: *
141: * @return a string representation
142: * @TODO: implement toString to something meaningful
143: */
144: public String toString() {
145: return super .toString();
146: }
147:
148: /**
149: * TODO: Needed for JIT compiler. Remove for 2.0.
150: *
151: * @return
152: */
153: public Object[] getParameterValues() {
154: return new Object[] { m_fieldValue };
155: }
156: }
|