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; 9 10 import java.lang.reflect.Method; 11 import java.io.Serializable; 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 { 19 private final Method m_wrapperMethod; 20 21 private final Method m_originalMethod; 22 23 private final Class m_declaringClass; 24 25 /*** 26 * @param wrapperMethod 27 * @param originalMethod 28 */ 29 public MethodTuple(Method wrapperMethod, Method originalMethod) { 30 if (originalMethod == null) { 31 originalMethod = wrapperMethod; 32 } 33 if (wrapperMethod.getDeclaringClass() != originalMethod.getDeclaringClass()) { 34 throw new RuntimeException(wrapperMethod.getName() 35 + " and " 36 + originalMethod.getName() 37 + " does not have the same declaring class"); 38 } 39 m_declaringClass = wrapperMethod.getDeclaringClass(); 40 m_wrapperMethod = wrapperMethod; 41 m_wrapperMethod.setAccessible(true); 42 m_originalMethod = originalMethod; 43 m_originalMethod.setAccessible(true); 44 } 45 46 public boolean isWrapped() { 47 return m_originalMethod != null; 48 } 49 50 public Class getDeclaringClass() { 51 return m_declaringClass; 52 } 53 54 public Method getWrapperMethod() { 55 return m_wrapperMethod; 56 } 57 58 public Method getOriginalMethod() { 59 return m_originalMethod; 60 } 61 62 public String getName() { 63 return m_wrapperMethod.getName(); 64 } 65 }