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; 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( 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 getDeclaringClass() { 53 return m_declaringClass; 54 } 55 56 public Method getWrapperMethod() { 57 return m_wrapperMethod; 58 } 59 60 public Method getOriginalMethod() { 61 return m_originalMethod; 62 } 63 64 public String getName() { 65 return m_wrapperMethod.getName(); 66 } 67 }