1 22 package org.jboss.aop.joinpoint; 23 24 import org.jboss.aop.Advisor; 25 import org.jboss.aop.MethodByMethodInfo; 26 import org.jboss.aop.advice.Interceptor; 27 28 import java.lang.reflect.InvocationTargetException ; 29 import java.lang.reflect.Method ; 30 31 32 40 public class MethodCalledByMethodInvocation extends CallerInvocation 41 { 42 private static final long serialVersionUID = -156920151151728318L; 43 44 Class callingClass; 46 Method callingMethod; 47 Method method; 48 49 protected Object [] arguments = null; 50 protected Object callingObject; 51 52 public MethodCalledByMethodInvocation(MethodByMethodInfo info, Object callingObject, Object targetObject, Object [] arguments, Interceptor[] interceptors) 53 { 54 this(info.getAdvisor(), info.getCallingClass(), info.getCallingMethod(), info.getMethod(), callingObject, targetObject, arguments, interceptors); 55 } 56 57 public MethodCalledByMethodInvocation(MethodByMethodInfo info, Object callingObject, Object targetObject, Interceptor[] interceptors) 58 { 59 this(info.getAdvisor(), info.getCallingClass(), info.getCallingMethod(), info.getMethod(), callingObject, targetObject, null, interceptors); 60 } 61 62 public MethodCalledByMethodInvocation(Advisor advisor, Class callingClass, 63 Method callingMethod, Method method, Object callingObject, Object targetObject, Object [] args, Interceptor[] interceptors) 64 { 65 super(advisor, interceptors); 66 this.callingClass = callingClass; 67 this.callingMethod = callingMethod; 68 this.method = method; 69 this.callingObject = callingObject; 70 setTargetObject(targetObject); 71 this.arguments = args; 72 } 73 74 public MethodCalledByMethodInvocation(Interceptor[] interceptors) 75 { 76 super(interceptors); 77 } 78 79 84 public Object invokeNext() throws Throwable 85 { 86 if (interceptors != null && currentInterceptor < interceptors.length) 87 { 88 try 89 { 90 return interceptors[currentInterceptor++].invoke(this); 91 } 92 finally 93 { 94 currentInterceptor--; 96 } 97 } 98 99 return invokeTarget(); 100 } 101 102 106 public Object invokeTarget() throws Throwable 107 { 108 try 109 { 110 return method.invoke(getTargetObject(), arguments); 111 } 112 catch (InvocationTargetException e) 113 { 114 throw e.getTargetException(); 115 } 116 } 117 118 119 128 public Object getMetaData(Object group, Object attr) 129 { 130 Object val = super.getMetaData(group, attr); 131 if (val != null) return val; 132 133 return null; 135 } 136 137 146 public Invocation getWrapper(Interceptor[] newchain) 147 { 148 MethodCalledByMethodInvocationWrapper wrapper = new MethodCalledByMethodInvocationWrapper(this, newchain); 149 return wrapper; 150 } 151 152 157 public Invocation copy() 158 { 159 MethodCalledByMethodInvocation wrapper = new MethodCalledByMethodInvocation(advisor, callingClass, 160 callingMethod, method, callingObject, targetObject, arguments, interceptors); 161 wrapper.currentInterceptor = this.currentInterceptor; 162 wrapper.instanceResolver = this.instanceResolver; 163 wrapper.metadata = this.metadata; 164 return wrapper; 165 } 166 167 170 public Object [] getArguments() 171 { 172 return arguments; 173 } 174 175 180 public void setArguments(Object [] arguments) 181 { 182 this.arguments = arguments; 183 } 184 185 188 public Class getCallingClass() 189 { 190 return callingClass; 191 } 192 193 196 public Method getCallingMethod() 197 { 198 return callingMethod; 199 } 200 201 public Method getCalledMethod() 202 { 203 return method; 204 } 205 206 public Object getCallingObject() 207 { 208 return callingObject; 209 } 210 211 } 212 | Popular Tags |