1 22 package org.jboss.aop.joinpoint; 23 24 import org.jboss.aop.Advisor; 25 import org.jboss.aop.InstanceAdvised; 26 import org.jboss.aop.InstanceAdvisor; 27 import org.jboss.aop.advice.Interceptor; 28 import org.jboss.aop.metadata.MetaDataResolver; 29 import org.jboss.aop.metadata.SimpleMetaData; 30 31 import java.util.HashMap ; 32 import java.util.Map ; 33 34 41 abstract public class InvocationBase implements java.io.Serializable , Invocation 42 { 43 static final long serialVersionUID = -4880246394729260729L; 44 45 protected org.jboss.aop.metadata.SimpleMetaData metadata = null; 46 47 48 protected transient int currentInterceptor = 0; 49 protected transient org.jboss.aop.advice.Interceptor[] interceptors = null; 50 protected transient Advisor advisor = null; 51 protected transient Map responseContextInfo = null; 52 53 protected transient Object targetObject = null; 54 55 protected transient MetaDataResolver instanceResolver; 57 58 public Map getResponseContextInfo() 59 { 60 return responseContextInfo; 61 } 62 63 public void setResponseContextInfo(Map responseContextInfo) 64 { 65 this.responseContextInfo = responseContextInfo; 66 } 67 68 public void addResponseAttachment(Object key, Object val) 69 { 70 if (responseContextInfo == null) responseContextInfo = new HashMap (1); 71 responseContextInfo.put(key, val); 72 } 73 74 public Object getResponseAttachment(Object key) 75 { 76 if (responseContextInfo == null) return null; 77 return responseContextInfo.get(key); 78 } 79 80 83 public SimpleMetaData getMetaData() 84 { 85 if (metadata == null) metadata = new SimpleMetaData(); 86 return metadata; 87 } 88 89 92 public void setMetaData(SimpleMetaData data) 93 { 94 this.metadata = data; 95 } 96 97 public Object resolveClassMetaData(Object key, Object attr) 98 { 99 return getAdvisor().getClassMetaData().getMetaData(key, attr); 100 } 101 102 public int getCurrentInterceptor() 103 { 104 return currentInterceptor; 105 } 106 107 112 public Object invokeNext() throws Throwable 113 { 114 try 115 { 116 return interceptors[currentInterceptor++].invoke(this); 117 } 118 finally 119 { 120 currentInterceptor--; 122 } 123 } 124 125 129 public Object invokeTarget() throws Throwable 130 { 131 return null; 132 } 133 134 141 public Object invokeNext(Interceptor[] newInterceptors) throws Throwable 142 { 143 org.jboss.aop.advice.Interceptor[] oldInterceptors = interceptors; 145 int oldCurrentInterceptor = currentInterceptor; 146 147 interceptors = newInterceptors; 149 currentInterceptor = 0; 150 151 try 153 { 154 return invokeNext(); 155 } 156 finally 157 { 158 interceptors = oldInterceptors; 160 currentInterceptor = oldCurrentInterceptor; 161 } 162 } 163 164 public InvocationBase(org.jboss.aop.advice.Interceptor[] interceptors) 165 { 166 this(interceptors, null); 167 } 168 169 public InvocationBase(org.jboss.aop.advice.Interceptor[] interceptors, org.jboss.aop.metadata.SimpleMetaData meta) 170 { 171 this.interceptors = interceptors; 176 this.metadata = meta; 177 } 178 179 182 public InvocationBase(Invocation invocation) 183 { 184 this.interceptors = invocation.getInterceptors(); 185 setTargetObject(invocation.getTargetObject()); 186 } 187 188 public InvocationBase() 189 { 190 } 192 193 197 public org.jboss.aop.advice.Interceptor[] getInterceptors() 198 { 199 return interceptors; 200 } 201 202 203 public Object resolveClassAnnotation(Class annotation) 204 { 205 if (advisor != null) return advisor.resolveAnnotation(annotation); 206 return null; 207 } 208 209 public Object resolveAnnotation(Class annotation) 210 { 211 return null; 213 } 214 215 public Object resolveAnnotation(Class [] annotations) 216 { 217 return null; 219 } 220 221 230 public Object getMetaData(Object group, Object attr) 231 { 232 Object val = null; 233 if (this.metadata != null) 234 { 235 val = this.metadata.resolve(this, group, attr); 236 if (val != null) return val; 237 } 238 239 val = org.jboss.aop.metadata.ThreadMetaData.instance().resolve(this, group, attr); 240 if (val != null) return val; 241 242 MetaDataResolver resolver = getInstanceResolver(); 243 if (resolver != null) 244 { 245 val = getInstanceResolver().resolve(this, group, attr); 246 if (val != null) return val; 247 } 248 249 return null; 250 } 251 252 public MetaDataResolver getInstanceResolver() 253 { 254 if (instanceResolver != null) return instanceResolver; 255 if (getTargetObject() != null) 256 { 257 if (getTargetObject() instanceof InstanceAdvised) 258 { 259 InstanceAdvisor ia = ((InstanceAdvised) getTargetObject())._getInstanceAdvisor(); 260 if (ia != null) 261 { 262 263 instanceResolver = ia.getMetaData(); 264 return instanceResolver; 265 } 266 } 267 } 268 return null; 269 } 270 271 public Advisor getAdvisor() 272 { 273 return advisor; 274 } 275 276 public Object getTargetObject() 277 { 278 return targetObject; 279 } 280 281 public void setTargetObject(Object targetObject) 282 { 283 this.targetObject = targetObject; 284 } 285 286 public void setAdvisor(Advisor advisor) 287 { 288 this.advisor = advisor; 289 } 290 291 public void setInstanceResolver(MetaDataResolver instanceResolver) 292 { 293 this.instanceResolver = instanceResolver; 294 } 295 296 } 297 | Popular Tags |