View Javadoc

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.CatchClauseRtti;
11  import org.codehaus.aspectwerkz.joinpoint.Rtti;
12  
13  import java.lang.ref.WeakReference;
14  
15  /***
16   * Implementation for the catch clause RTTI.
17   * 
18   * @author <a href="mailto:jboner@codehaus.org">Jonas Bonér </a>
19   */
20  public class CatchClauseRttiImpl implements CatchClauseRtti {
21      private final CatchClauseSignatureImpl m_signature;
22  
23      private WeakReference m_thisRef;
24  
25      private WeakReference m_targetRef;
26  
27      private Object m_parameterValue;
28  
29      /***
30       * Creates a new catch clause RTTI.
31       * 
32       * @param signature
33       * @param thisInstance
34       * @param targetInstance
35       */
36      public CatchClauseRttiImpl(final CatchClauseSignatureImpl signature,
37                                 final Object thisInstance,
38                                 final Object targetInstance) {
39          m_signature = signature;
40          m_thisRef = new WeakReference(thisInstance);
41          m_targetRef = new WeakReference(targetInstance);
42      }
43  
44      /***
45       * Clones the RTTI instance.
46       *
47       * @param thisInstance
48       * @param targetInstance
49       * @return
50       */
51      public Rtti cloneFor(final Object thisInstance, final Object targetInstance) {
52          return new CatchClauseRttiImpl(m_signature, thisInstance, targetInstance);
53      }
54  
55      /***
56       * Returns the instance currently executing.
57       * 
58       * @return the instance currently executing
59       */
60      public Object getThis() {
61          return m_thisRef.get();
62      }
63  
64      /***
65       * Returns the target instance.
66       * 
67       * @return the target instance
68       */
69      public Object getTarget() {
70          return m_targetRef.get();
71      }
72  
73      /***
74       * Returns the declaring class.
75       * 
76       * @return the declaring class
77       */
78      public Class getDeclaringType() {
79          return m_signature.getDeclaringType();
80      }
81  
82      /***
83       * Returns the modifiers for the signature. <p/>Could be used like this:
84       * 
85       * <pre>
86       * boolean isPublic = java.lang.reflect.Modifier.isPublic(signature.getModifiers());
87       * </pre>
88       * 
89       * @return the mofifiers
90       */
91      public int getModifiers() {
92          return m_signature.getModifiers();
93      }
94  
95      /***
96       * Returns the name (f.e. name of method of field).
97       * 
98       * @return
99       */
100     public String getName() {
101         return m_signature.getName();
102     }
103 
104     /***
105      * Returns the parameter type.
106      * 
107      * @return the parameter type
108      */
109     public Class getParameterType() {
110         return m_signature.getParameterType();
111     }
112 
113     /***
114      * Returns the value of the parameter.
115      * 
116      * @return the value of the parameter
117      */
118     public Object getParameterValue() {
119         return m_parameterValue;
120     }
121 
122     /***
123      * Sets the value of the parameter.
124      * 
125      * @param parameterValue the value of the parameter
126      */
127     public void setParameterValue(final Object parameterValue) {
128         m_parameterValue = parameterValue;
129     }
130 
131     /***
132      * Returns a string representation of the signature.
133      * 
134      * @return a string representation
135      * @TODO: implement toString to something meaningful
136      */
137     public String toString() {
138         return super.toString();
139     }
140 }