1 22 package org.jboss.aop.joinpoint; 23 24 import org.jboss.aop.Advisor; 25 import org.jboss.aop.ConByMethodInfo; 26 import org.jboss.aop.advice.Interceptor; 27 28 import java.lang.reflect.Constructor ; 29 import java.lang.reflect.InvocationTargetException ; 30 import java.lang.reflect.Method ; 31 32 33 41 public class ConstructorCalledByMethodInvocation extends CallerInvocation 42 { 43 private static final long serialVersionUID = -3269308917757322223L; 44 45 protected Object [] arguments = null; 46 47 protected Class callingClass; 49 protected Method callingMethod; 50 protected Constructor constructor; 51 protected Method wrappingMethod; 52 53 protected Object callingObject; 54 55 public ConstructorCalledByMethodInvocation(ConByMethodInfo info, Object callingObject, Object [] args, Interceptor[] interceptors) 56 { 57 this(info.getAdvisor(), info.getCallingClass(), info.getCallingMethod(), info.getConstructor(), info.getWrappingMethod(), callingObject, args, interceptors); 58 } 59 60 public ConstructorCalledByMethodInvocation(ConByMethodInfo info, Object callingObject, Interceptor[] interceptors) 61 { 62 this(info.getAdvisor(), info.getCallingClass(), info.getCallingMethod(), info.getConstructor(), info.getWrappingMethod(), callingObject, null, interceptors); 63 } 64 65 public ConstructorCalledByMethodInvocation(Advisor advisor, Class callingClass, 66 Method callingMethod, Constructor constructor, Method wrappingMethod, Object callingObject, Object [] args, Interceptor[] interceptors) 67 { 68 super(advisor, interceptors); 69 this.callingClass = callingClass; 70 this.callingMethod = callingMethod; 71 this.constructor = constructor; 72 this.wrappingMethod = wrappingMethod; 73 this.callingObject = callingObject; 74 this.arguments = args; 75 } 76 77 public ConstructorCalledByMethodInvocation(Interceptor[] interceptors) 78 { 79 super(interceptors); 80 } 81 82 85 public Object [] getArguments() 86 { 87 return arguments; 88 } 89 90 95 public void setArguments(Object [] arguments) 96 { 97 this.arguments = arguments; 98 } 99 100 103 public Class getCallingClass() 104 { 105 return callingClass; 106 } 107 108 111 public Method getCallingMethod() 112 { 113 return callingMethod; 114 } 115 116 119 public Constructor getCalledConstructor() 120 { 121 return constructor; 122 } 123 124 130 public boolean isWrapped() 131 { 132 return wrappingMethod != null; 133 } 134 135 141 public Method getWrappingMethod() 142 { 143 return wrappingMethod; 144 } 145 146 151 public Object invokeNext() throws Throwable 152 { 153 if (interceptors != null && currentInterceptor < interceptors.length) 154 { 155 try 156 { 157 return interceptors[currentInterceptor++].invoke(this); 158 } 159 finally 160 { 161 currentInterceptor--; 163 } 164 } 165 166 return invokeTarget(); 167 } 168 169 173 public Object invokeTarget() throws Throwable 174 { 175 if (wrappingMethod != null) 176 { 177 try 178 { 179 setTargetObject(wrappingMethod.invoke(null, arguments)); 180 return getTargetObject(); 181 } 182 catch (InvocationTargetException e) 183 { 184 throw e.getTargetException(); 185 } 186 } 187 else 188 { 189 try 190 { 191 return constructor.newInstance(arguments); 192 } 193 catch (InstantiationException e) 194 { 195 throw new RuntimeException (e); } 197 catch (IllegalAccessException e) 198 { 199 throw new RuntimeException (e); } 201 catch (InvocationTargetException e) 202 { 203 throw e.getCause(); 204 } 205 } 206 } 207 208 217 public Object getMetaData(Object group, Object attr) 218 { 219 Object val = super.getMetaData(group, attr); 220 if (val != null) return val; 221 222 return null; 224 } 225 226 235 public Invocation getWrapper(Interceptor[] newchain) 236 { 237 ConstructorCalledByMethodInvocationWrapper wrapper = new ConstructorCalledByMethodInvocationWrapper(this, newchain); 238 return wrapper; 239 } 240 241 246 public Invocation copy() 247 { 248 ConstructorCalledByMethodInvocation wrapper = new ConstructorCalledByMethodInvocation(advisor, callingClass, 249 callingMethod, constructor, wrappingMethod, callingObject, arguments, interceptors); 250 wrapper.setTargetObject(this.getTargetObject()); 251 wrapper.metadata = this.metadata; 252 wrapper.instanceResolver = this.instanceResolver; 253 wrapper.currentInterceptor = this.currentInterceptor; 254 return wrapper; 255 } 256 257 public Object getCallingObject() 258 { 259 return callingObject; 260 } 261 } 262 | Popular Tags |