1 22 package org.jboss.ejb3; 23 24 import java.lang.reflect.InvocationTargetException ; 25 import java.lang.reflect.Method ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 import org.jboss.aop.advice.Interceptor; 29 import org.jboss.aop.joinpoint.Invocation; 30 import org.jboss.aop.metadata.SimpleMetaData; 31 import org.jboss.aop.metadata.ThreadMetaData; 32 import org.jboss.logging.Logger; 33 34 40 public abstract class EJBInvocation implements Invocation 41 { 42 private static final Logger log = Logger.getLogger(EJBInvocation.class); 43 44 protected transient Interceptor[] interceptors; 45 protected long methodHash; 46 protected transient int currentInterceptor = 0; 47 protected transient Method method; 48 protected Object [] arguments; 49 protected SimpleMetaData metadata = null; 50 protected transient Map responseContextInfo = null; 51 52 protected EJBInvocation(Method method, long methodHash, Object [] arguments, Interceptor[] interceptors) 53 { 54 this.method = method; 55 this.methodHash = methodHash; 56 this.arguments = arguments; 57 this.interceptors = interceptors; 58 } 59 60 protected EJBInvocation() 61 { 62 } 63 64 public Object invokeNext() throws Throwable 65 { 66 if (currentInterceptor < interceptors.length) 67 { 68 try 69 { 70 return interceptors[currentInterceptor++].invoke(this); 71 } 72 finally 73 { 74 currentInterceptor--; 76 } 77 } 78 try 79 { 80 return method.invoke(getTargetObject(), getArguments()); 81 } 82 catch (InvocationTargetException e) 83 { 84 throw e.getTargetException(); 85 } 86 } 87 88 public Method getMethod() 89 { 90 return method; 91 } 92 93 public long getMethodHash() 94 { 95 return methodHash; 96 } 97 98 public Interceptor[] getInterceptors() 99 { 100 return interceptors; 101 } 102 103 public void setInterceptors(Interceptor[] interceptors) 104 { 105 this.interceptors = interceptors; 106 } 107 108 public Object [] getArguments() 109 { 110 return arguments; 111 } 112 113 public void setArguments(Object [] args) 114 { 115 this.arguments = args; 116 } 117 118 public Object getMetaData(Object key, Object attr) 119 { 120 Object value = null; 122 if (metadata != null) value = metadata.getMetaData(key, attr); 123 if (value != null) return value; 124 value = ThreadMetaData.instance().getMetaData(key, attr); 125 return value; 126 } 127 128 public Map getResponseContextInfo() 129 { 130 return responseContextInfo; 131 } 132 133 public void setResponseContextInfo(Map responseContextInfo) 134 { 135 this.responseContextInfo = responseContextInfo; 136 } 137 138 public void addResponseAttachment(Object key, Object val) 139 { 140 if (responseContextInfo == null) responseContextInfo = new HashMap (); 141 responseContextInfo.put(key, val); 142 } 143 144 public Object getResponseAttachment(Object key) 145 { 146 if (responseContextInfo == null) return null; 147 return responseContextInfo.get(key); 148 } 149 150 public SimpleMetaData getMetaData() 151 { 152 if (metadata == null) metadata = new SimpleMetaData(); 153 return metadata; 154 } 155 156 public void setMetaData(SimpleMetaData data) 157 { 158 this.metadata = data; 159 } 160 161 public Object invokeNext(Interceptor[] newInterceptors) throws Throwable 162 { 163 throw new RuntimeException ("NOT IMPLEMENTED"); 164 } 165 } 166 | Popular Tags |