KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > aspectwerkz > joinpoint > impl > FieldRttiImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.aspectwerkz.joinpoint.impl;
5
6 import com.tc.aspectwerkz.joinpoint.FieldRtti;
7 import com.tc.aspectwerkz.joinpoint.Rtti;
8
9 import java.lang.ref.WeakReference JavaDoc;
10 import java.lang.reflect.Field JavaDoc;
11
12 /**
13  * Implementation for the field signature.
14  *
15  * @author <a HREF="mailto:jboner@codehaus.org">Jonas Bon�r </a>
16  */

17 public class FieldRttiImpl implements FieldRtti {
18   private final FieldSignatureImpl m_signature;
19
20   private WeakReference JavaDoc m_thisRef;
21
22   private WeakReference JavaDoc m_targetRef;
23
24   private Object JavaDoc m_fieldValue;
25
26   /**
27    * Creates a new field RTTI.
28    *
29    * @param signature
30    * @param thisInstance
31    * @param targetInstance
32    */

33   public FieldRttiImpl(final FieldSignatureImpl signature, final Object JavaDoc thisInstance, final Object JavaDoc targetInstance) {
34     m_signature = signature;
35     m_thisRef = new WeakReference JavaDoc(thisInstance);
36     m_targetRef = new WeakReference JavaDoc(targetInstance);
37   }
38
39   /**
40    * Clones the RTTI instance.
41    *
42    * @param thisInstance
43    * @param targetInstance
44    * @return
45    */

46   public Rtti cloneFor(final Object JavaDoc thisInstance, final Object JavaDoc targetInstance) {
47     return new FieldRttiImpl(m_signature, thisInstance, targetInstance);
48   }
49
50   /**
51    * Returns the target instance.
52    *
53    * @return the target instance
54    */

55   public Object JavaDoc getTarget() {
56     return m_targetRef.get();
57   }
58
59   /**
60    * Returns the instance currently executing.
61    *
62    * @return the instance currently executing
63    */

64   public Object JavaDoc getThis() {
65     return m_thisRef.get();
66   }
67
68   /**
69    * Returns the declaring class.
70    *
71    * @return the declaring class
72    */

73   public Class JavaDoc getDeclaringType() {
74     return m_signature.getDeclaringType();
75   }
76
77   /**
78    * Returns the modifiers for the signature. <p/>Could be used like this:
79    * <p/>
80    * <pre>
81    * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
82    * </pre>
83    *
84    * @return the mofifiers
85    */

86   public int getModifiers() {
87     return m_signature.getModifiers();
88   }
89
90   /**
91    * Returns the name (f.e. name of method of field).
92    *
93    * @return the name
94    */

95   public String JavaDoc getName() {
96     return m_signature.getName();
97   }
98
99   /**
100    * Returns the field.
101    *
102    * @return the field
103    */

104   public Field JavaDoc getField() {
105     return m_signature.getField();
106   }
107
108   /**
109    * Returns the field type.
110    *
111    * @return the field type
112    */

113   public Class JavaDoc getFieldType() {
114     return m_signature.getFieldType();
115   }
116
117   /**
118    * Returns the value of the field.
119    *
120    * @return the value of the field
121    */

122   public Object JavaDoc getFieldValue() {
123     return m_fieldValue;
124   }
125
126   /**
127    * Sets the value of the field.
128    *
129    * @param fieldValue the value of the field
130    */

131   public void setFieldValue(final Object JavaDoc fieldValue) {
132     m_fieldValue = fieldValue;
133   }
134
135   /**
136    * Returns a string representation of the signature.
137    *
138    * @return a string representation
139    * @TODO: implement toString to something meaningful
140    */

141   public String JavaDoc toString() {
142     return super.toString();
143   }
144
145   /**
146    * TODO: Needed for JIT compiler. Remove for 2.0.
147    *
148    * @return
149    */

150   public Object JavaDoc[] getParameterValues() {
151     return new Object JavaDoc[]{m_fieldValue};
152   }
153 }
Popular Tags