KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > aspectwerkz > joinpoint > impl > MethodTuple


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 BSD-style 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 java.lang.reflect.Method JavaDoc;
11 import java.io.Serializable JavaDoc;
12
13 /**
14  * Contains a pair of the original method and the wrapper method if such a method exists.
15  *
16  * @author <a HREF="mailto:jboner@codehaus.org">Jonas Bonér </a>
17  */

18 public class MethodTuple implements Serializable JavaDoc {
19     private final Method JavaDoc m_wrapperMethod;
20
21     private final Method JavaDoc m_originalMethod;
22
23     private final Class JavaDoc m_declaringClass;
24
25     /**
26      * @param wrapperMethod
27      * @param originalMethod
28      */

29     public MethodTuple(Method JavaDoc wrapperMethod, Method JavaDoc originalMethod) {
30         if (originalMethod == null) {
31             originalMethod = wrapperMethod;
32         }
33         if (wrapperMethod.getDeclaringClass() != originalMethod.getDeclaringClass()) {
34             throw new RuntimeException JavaDoc(
35                     wrapperMethod.getName()
36                     + " and "
37                     + originalMethod.getName()
38                     + " does not have the same declaring class"
39             );
40         }
41         m_declaringClass = wrapperMethod.getDeclaringClass();
42         m_wrapperMethod = wrapperMethod;
43         m_wrapperMethod.setAccessible(true);
44         m_originalMethod = originalMethod;
45         m_originalMethod.setAccessible(true);
46     }
47
48     public boolean isWrapped() {
49         return m_originalMethod != null;
50     }
51
52     public Class JavaDoc getDeclaringClass() {
53         return m_declaringClass;
54     }
55
56     public Method JavaDoc getWrapperMethod() {
57         return m_wrapperMethod;
58     }
59
60     public Method JavaDoc getOriginalMethod() {
61         return m_originalMethod;
62     }
63
64     public String JavaDoc getName() {
65         return m_wrapperMethod.getName();
66     }
67 }
Popular Tags