1 22 package org.jboss.aop.joinpoint; 23 24 import org.jboss.aop.Advisor; 25 import org.jboss.aop.ConByConInfo; 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 ConstructorCalledByConstructorInvocation extends CallerInvocation 42 { 43 private static final long serialVersionUID = -1569257745454443521L; 44 45 protected Object [] arguments; 46 47 protected Constructor calling; 49 protected Constructor constructor; 50 protected Method wrappingMethod; 51 52 public ConstructorCalledByConstructorInvocation(ConByConInfo info, Object [] args, Interceptor[] interceptors) 53 { 54 this(info.getAdvisor(), info.getCalling(), info.getConstructor(), info.getWrappingMethod(), args, interceptors); 55 } 56 57 public ConstructorCalledByConstructorInvocation(ConByConInfo info, Interceptor[] interceptors) 58 { 59 this(info.getAdvisor(), info.getCalling(), info.getConstructor(), info.getWrappingMethod(), null, interceptors); 60 } 61 62 public ConstructorCalledByConstructorInvocation(Advisor advisor, Constructor calling, Constructor constructor, Method wrappingMethod, Object [] args, Interceptor[] interceptors) 63 { 64 super(advisor, interceptors); 65 this.calling = calling; 66 this.constructor = constructor; 67 this.wrappingMethod = wrappingMethod; 68 this.arguments = args; 69 } 70 71 public ConstructorCalledByConstructorInvocation(Interceptor[] interceptors) 72 { 73 super(interceptors); 74 } 75 76 public Object [] getArguments() 77 { 78 return arguments; 79 } 80 81 public void setArguments(Object [] arguments) 82 { 83 this.arguments = arguments; 84 } 85 86 90 public Constructor getCallingConstructor() 91 { 92 return calling; 93 } 94 98 public Constructor getCalledConstructor() { return constructor; } 99 100 105 public boolean isWrapped() { return wrappingMethod != null; } 106 107 112 public Method getWrappingMethod() { return wrappingMethod; } 113 114 119 public Object invokeNext() throws Throwable 120 { 121 if (interceptors != null && currentInterceptor < interceptors.length) 122 { 123 try 124 { 125 return interceptors[currentInterceptor++].invoke(this); 126 } 127 finally 128 { 129 currentInterceptor--; 131 } 132 } 133 134 return invokeTarget(); 135 } 136 137 141 public Object invokeTarget() throws Throwable 142 { 143 if (wrappingMethod != null) 144 { 145 try 146 { 147 setTargetObject(wrappingMethod.invoke(null, arguments)); 148 return getTargetObject(); 149 } 150 catch (InvocationTargetException e) 151 { 152 throw e.getTargetException(); 153 } 154 } 155 else 156 { 157 try 158 { 159 return constructor.newInstance(arguments); 160 } 161 catch (InstantiationException e) 162 { 163 throw new RuntimeException (e); } 165 catch (IllegalAccessException e) 166 { 167 throw new RuntimeException (e); } 169 catch (InvocationTargetException e) 170 { 171 throw e.getCause(); 172 } 173 } 174 } 175 176 185 public Object getMetaData(Object group, Object attr) 186 { 187 Object val = super.getMetaData(group, attr); 188 if (val != null) return val; 189 190 return null; 192 } 193 194 202 public Invocation getWrapper(Interceptor[] newchain) 203 { 204 ConstructorCalledByConstructorInvocationWrapper wrapper = new ConstructorCalledByConstructorInvocationWrapper(this, newchain); 205 return wrapper; 206 } 207 208 212 public Invocation copy() 213 { 214 ConstructorCalledByConstructorInvocation wrapper = new ConstructorCalledByConstructorInvocation(advisor, calling, constructor, wrappingMethod, arguments, interceptors); 215 wrapper.setAdvisor(this.getAdvisor()); 216 wrapper.setTargetObject(this.getTargetObject()); 217 wrapper.currentInterceptor = this.currentInterceptor; 218 wrapper.instanceResolver = this.instanceResolver; 219 wrapper.metadata = this.metadata; 220 return wrapper; 221 } 222 223 224 } 225 | Popular Tags |