1 22 package org.jboss.aop.joinpoint; 23 24 import org.jboss.aop.ConstructorInfo; 25 import org.jboss.aop.advice.Interceptor; 26 27 import java.lang.reflect.Constructor ; 28 import java.lang.reflect.InvocationTargetException ; 29 30 38 public class ConstructorInvocation extends InvocationBase 39 { 40 private static final long serialVersionUID = -7880020293056198584L; 41 42 protected Object [] arguments = null; protected transient Constructor constructor = null; 44 45 public ConstructorInvocation(Interceptor[] interceptors) 46 { 47 super(interceptors); 48 } 49 50 public ConstructorInvocation(ConstructorInfo info, Interceptor[] interceptors) 51 { 52 super(interceptors); 53 super.advisor = info.getAdvisor(); 54 constructor = info.getConstructor(); 55 } 56 57 58 63 public Object invokeNext() throws Throwable 64 { 65 if (interceptors != null && currentInterceptor < interceptors.length) 66 { 67 try 68 { 69 return interceptors[currentInterceptor++].invoke(this); 70 } 71 finally 72 { 73 currentInterceptor--; 75 } 76 } 77 78 return invokeTarget(); 79 } 80 81 85 public Object invokeTarget() throws Throwable 86 { 87 try 88 { 89 Constructor con = getConstructor(); 90 Object [] args = getArguments(); 91 setTargetObject(con.newInstance(args)); 92 return getTargetObject(); 93 } 94 catch (InstantiationException in) 95 { 96 throw new RuntimeException ("failed to call constructor", in); 97 } 98 catch (IllegalAccessException ill) 99 { 100 throw new RuntimeException ("illegal access", ill); 101 } 102 catch (InvocationTargetException ite) 103 { 104 throw ite.getCause(); 105 } 106 catch (IllegalArgumentException iae) 107 { 108 throw iae; 110 } 111 } 112 113 114 118 public Object resolveAnnotation(Class annotation) 119 { 120 Object val = super.resolveAnnotation(annotation); 121 if (val != null) return val; 122 123 if (getAdvisor() != null) 124 { 125 val = getAdvisor().resolveAnnotation(constructor, annotation); 126 if (val != null) return val; 127 } 128 129 return null; 130 } 131 132 141 public Object getMetaData(Object group, Object attr) 142 { 143 Object val = super.getMetaData(group, attr); 144 if (val != null) return val; 145 146 if (getAdvisor() != null) 147 { 148 val = getAdvisor().getConstructorMetaData().resolve(this, group, attr); 149 if (val != null) return val; 150 } 151 152 if (getAdvisor() != null) 153 { 154 val = getAdvisor().getDefaultMetaData().resolve(this, group, attr); 155 if (val != null) return val; 156 } 157 158 return null; 159 } 160 161 169 public Invocation getWrapper(Interceptor[] newchain) 170 { 171 ConstructorInvocationWrapper wrapper = new ConstructorInvocationWrapper(this, newchain); 172 return wrapper; 173 } 174 175 179 public Invocation copy() 180 { 181 ConstructorInvocation wrapper = new ConstructorInvocation(interceptors); 182 wrapper.arguments = this.arguments; 183 wrapper.constructor = this.constructor; 184 wrapper.setAdvisor(this.getAdvisor()); 185 wrapper.currentInterceptor = this.currentInterceptor; 186 wrapper.metadata = this.metadata; 187 return wrapper; 188 } 189 190 public Object [] getArguments() 191 { 192 return arguments; 193 } 194 195 public void setArguments(Object [] arguments) 196 { 197 this.arguments = arguments; 198 } 199 200 public Constructor getConstructor() 201 { 202 return constructor; 203 } 204 205 public void setConstructor(Constructor constructor) 206 { 207 this.constructor = constructor; 208 } 209 } 210 | Popular Tags |