1 2 24 package com.sun.ejb; 25 26 28 import javax.xml.rpc.handler.MessageContext ; 29 30 import javax.interceptor.InvocationContext; 31 import javax.ejb.EJBContext ; 32 import javax.transaction.Transaction ; 33 import java.security.Identity ; 34 import java.util.Map ; 35 import java.util.HashMap ; 36 import java.lang.reflect.Method ; 37 import java.rmi.Remote ; 38 39 import com.sun.xml.ws.spi.runtime.WebServiceContext; 40 import com.sun.enterprise.deployment.MethodDescriptor; 41 import com.sun.enterprise.security.CachedPermission; 42 43 50 51 public class Invocation 52 extends com.sun.enterprise.ComponentInvocation 53 implements InvocationContext 54 { 55 private static Map <Class , Class > primitive2Wrapper 56 = new HashMap <Class , Class >(); 57 58 static { 59 primitive2Wrapper.put(byte.class, Byte .class); 60 primitive2Wrapper.put(boolean.class, Boolean .class); 61 primitive2Wrapper.put(char.class, Character .class); 62 primitive2Wrapper.put(double.class, Double .class); 63 primitive2Wrapper.put(float.class, Float .class); 64 primitive2Wrapper.put(int.class, Integer .class); 65 primitive2Wrapper.put(short.class, Short .class); 66 } 67 68 public Invocation() 69 {} 70 71 public Invocation(Object ejb, Object container) { 72 super(ejb, container); 73 this.ejb = ejb; 74 } 75 76 public Invocation(Object ejb, Object container, ComponentContext context) { 77 super(ejb, container, context); 78 this.ejb = ejb; 79 } 80 81 85 public com.sun.ejb.containers.EJBLocalRemoteObject ejbObject; 86 87 91 public boolean isLocal=false; 92 93 96 public InvocationInfo invocationInfo; 97 98 102 public boolean isBusinessInterface; 103 104 107 public boolean isWebService=false; 108 109 112 public boolean isMessageDriven=false; 113 114 118 public boolean isHome=false; 119 120 124 public Class clientInterface; 125 126 134 public java.lang.reflect.Method method; 135 136 140 public Object ejb; 141 142 146 public Throwable exception; 147 148 155 public Throwable exceptionFromBeanMethod; 156 157 158 163 public Transaction clientTx; 164 165 170 173 177 public int transactionAttribute; 178 179 183 public int securityPermissions; 184 185 186 190 public boolean containerStartsTx; 191 192 196 public ClassLoader originalContextClassLoader; 197 198 202 203 public MessageContext messageContext; 204 205 210 public Object [] methodParams; 211 212 218 public Object getJaccEjb() { 219 Object bean = null; 220 if( container != null ) { 221 bean = ((Container) container).getJaccEjb(this); 222 } 223 return bean; 224 } 225 226 229 public String getMethodInterface() { 230 if (isWebService) { 231 return MethodDescriptor.EJB_WEB_SERVICE; 232 } else if (isMessageDriven) { 233 return MethodDescriptor.EJB_BEAN; 234 } else if (isLocal) { 235 return (isHome) ? MethodDescriptor.EJB_LOCALHOME : 236 MethodDescriptor.EJB_LOCAL; 237 } else { 238 return (isHome) ? MethodDescriptor.EJB_HOME : 239 MethodDescriptor.EJB_REMOTE; 240 } 241 } 242 243 247 public CachedPermission getCachedPermission() { 248 return (invocationInfo != null) ? invocationInfo.cachedPermission : 249 null; 250 } 251 252 255 public EJBContext getEJBContext() { 256 return (EJBContext ) this.context; 257 } 258 259 260 262 private int interceptorIndex; 263 264 public Method beanMethod; 265 266 private WebServiceContext webServiceContext; 268 269 private Map contextData; 270 271 public InterceptorChain getInterceptorChain() { 272 return (invocationInfo == null) 273 ? null : invocationInfo.interceptorChain; 274 } 275 276 279 public Object getTarget() { 280 return this.ejb; 281 } 282 283 284 289 public Method getMethod() { 290 return getBeanMethod(); 291 } 292 public Method getBeanMethod() { 293 return this.beanMethod; 294 } 295 296 302 public Object [] getParameters() { 303 return this.methodParams; 304 } 305 306 310 public void setParameters(Object [] params) { 311 Method method = getMethod(); 312 if (method != null) { 313 Class [] paramTypes = method.getParameterTypes(); 314 if ((params == null) && (paramTypes.length != 0)) { 315 throw new IllegalArgumentException ("Wrong number of parameters for " 316 + " method: " + method); 317 } 318 if (paramTypes.length != params.length) { 319 throw new IllegalArgumentException ("Wrong number of parameters for " 320 + " method: " + method); 321 } 322 int index = 0 ; 323 for (Class type : paramTypes) { 324 if (type.isPrimitive()) { 325 Class allowedWrapper = primitive2Wrapper.get(type); 326 if (allowedWrapper != params[index].getClass()) { 327 throw new IllegalArgumentException ("Parameter type mismatch for method " 328 + method.getName() + ". Arg[" 329 + index + "] type: " + params[index].getClass().getName() 330 + " does not match the expected type: " + type.getName()); 331 } 332 } else if (! type.isAssignableFrom(params[index].getClass())) { 333 throw new IllegalArgumentException ("Parameter type mismatch for method " 334 + method.getName() + ". Arg[" 335 + index + "] type: " + params[index].getClass().getName() 336 + " does not match the expected type: " + type.getName()); 337 } 338 index++; 339 } 340 } else { 341 throw new IllegalStateException ("Internal Error: Got null method"); 342 } 343 this.methodParams = params; 344 } 345 346 public void setContextData(WebServiceContext context) { 349 this.webServiceContext = context; 350 } 351 352 355 public Map <String , Object > getContextData() { 356 if (this.contextData == null) { 357 this.contextData = (webServiceContext != null) ? 358 webServiceContext.getMessageContext() : 359 new HashMap <String , Object >(); 360 } 361 return contextData; 362 } 363 364 367 public Object proceed() 368 throws Exception 369 { 370 try { 371 interceptorIndex++; 373 return getInterceptorChain().invokeNext(interceptorIndex, this); 374 } catch (Exception ex) { 375 throw ex; 376 } catch (Throwable th) { 377 throw new Exception (th); 378 } finally { 379 interceptorIndex--; 380 } 381 } 382 383 384 385 public static interface InterceptorChain { 386 public Object invokeNext(int index, Invocation invCtx) 387 throws Throwable ; 388 } 389 390 } 391 392 | Popular Tags |