Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*     */ package org.jboss.ejb3.stateful;
  /*     */ 
  /*     */ import  gnu.trove.TLongObjectHashMap;
  /*     */ import java.lang.reflect.AccessibleObject;
  /*     */ import java.lang.reflect.Field;
  /*     */ import java.lang.reflect.Method;
  /*     */ import java.util.Hashtable;
  /*     */ import java.util.Map;
  /*     */ import javax.annotation.PostConstruct;
 /*     */ import javax.annotation.PreDestroy;
 /*     */ import javax.ejb.EJB;
 /*     */ import javax.ejb.EJBHome;
 /*     */ import javax.ejb.EJBObject;
 /*     */ import javax.ejb.Handle;
 /*     */ import javax.ejb.Init;
 /*     */ import javax.ejb.PostActivate;
 /*     */ import javax.ejb.PrePassivate;
 /*     */ import javax.ejb.Remote;
 /*     */ import javax.ejb.RemoteHome;
 /*     */ import javax.ejb.TimerService;
 /*     */ import org.jboss.aop.AspectManager;
 /*     */ import org.jboss.aop.MethodInfo;
 /*     */ import org.jboss.aop.joinpoint.Invocation;
 /*     */ import org.jboss.aop.util.MethodHashing;
 /*     */ import org.jboss.aspects.asynch.FutureHolder;
 /*     */ import org.jboss.ejb3.BeanContext;
 /*     */ import org.jboss.ejb3.EJBContainerInvocation;
 /*     */ import org.jboss.ejb3.Ejb3Deployment;
 /*     */ import org.jboss.ejb3.ProxyFactory;
 /*     */ import org.jboss.ejb3.ProxyFactoryHelper;
 /*     */ import org.jboss.ejb3.ProxyUtils;
 /*     */ import org.jboss.ejb3.ThreadLocalStack;
 /*     */ import org.jboss.ejb3.annotation.Cache;
 /*     */ import org.jboss.ejb3.annotation.Clustered;
 /*     */ import org.jboss.ejb3.annotation.LocalBinding;
 /*     */ import org.jboss.ejb3.cache.Ejb3CacheFactory;
 /*     */ import org.jboss.ejb3.cache.StatefulCache;
 /*     */ import org.jboss.ejb3.proxy.EJBMetaDataImpl;
 /*     */ import org.jboss.ejb3.session.ProxyDeployer;
 /*     */ import org.jboss.injection.Injector;
 /*     */ import org.jboss.logging.Logger;
 /*     */ 
 /*     */ public class StatefulContainer extends SessionContainer
 /*     */   implements StatefulObjectFactory<StatefulBeanContext>
 /*     */ {
 /*     */   private static final Logger log;
 /*     */   protected StatefulCache cache;
 /*  84 */   private StatefulDelegateWrapper mbean = new StatefulDelegateWrapper(this);
 /*     */ 
 /*     */   public StatefulContainer(ClassLoader clString beanClassNameString ejbNameAspectManager managerHashtable ctxPropertiesInterceptorInfoRepository interceptorRepositoryEjb3Deployment deployment)
 /*     */   {
 /*  90 */     super(clbeanClassNameejbNamemanagerctxPropertiesinterceptorRepositorydeployment);
 /*     */   }
 /*     */ 
 /*     */   public StatefulBeanContext create(Class<?>[] initTypesObject[] initValues)
 /*     */   {
 /*  97 */     return (StatefulBeanContext)createBeanContext();
 /*     */   }
 /*     */ 
 /*     */   public BeanContext<?> createBeanContext()
 /*     */   {
 /* 103 */     return new StatefulBeanContext(thisconstruct());
 /*     */   }
 /*     */ 
 /*     */   protected ProxyFactory createProxyFactory(LocalBinding binding)
 /*     */   {
 /* 109 */     return new StatefulLocalProxyFactory(thisbinding);
 /*     */   }
 /*     */ 
 /*     */   protected RemoteProxyFactory createRemoteProxyFactory(RemoteBinding binding)
 /*     */   {
 /* 115 */     Clustered clustered = (Clustered)getAnnotation(Clustered.class);
 /* 116 */     if (clustered != null)
 /*     */     {
 /* 118 */       return new StatefulClusterProxyFactory(thisbindingclustered);
 /*     */     }
 /*     */ 
 /* 122 */     return new StatefulRemoteProxyFactory(thisbinding);
 /*     */   }
 /*     */ 
 /*     */   public void destroy(StatefulBeanContext obj)
 /*     */   {
 /* 128 */     invokePreDestroy(obj);
 /*     */   }
 /*     */ 
 /*     */   public Object getMBean()
/*     */   {
/* 133 */     return this.;
/*     */   }
/*     */ 
/*     */   public void start() throws Exception
/*     */   {
/*     */     try
/*     */     {
/* 140 */       super.start();
/* 141 */       Cache cacheConfig = (Cache)getAnnotation(Cache.class);
/* 142 */       CacheFactoryRegistry registry = getCacheFactoryRegistry();
/* 143 */       Ejb3CacheFactory factory = registry.getCacheFactory(cacheConfig.value());
/* 144 */       this. = factory.createCache();
/* 145 */       this..initialize(this);
/* 146 */       this..start();
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/*     */       try
/*     */       {
/* 152 */         stop();
/*     */       }
/*     */       catch (Exception ignore)
/*     */       {
/* 156 */         .debug("Failed to cleanup after start() failure"ignore);
/*     */       }
/* 158 */       throw e;
/*     */     }
/*     */   }
/*     */ 
/*     */   public void stop()
/*     */     throws Exception
/*     */   {
/* 165 */     if (this. != nullthis..stop();
/* 166 */     super.stop();
/*     */   }
/*     */ 
/*     */   public StatefulCache getCache()
/*     */   {
/* 171 */     return this.;
/*     */   }
/*     */ 
/*     */   public CacheFactoryRegistry getCacheFactoryRegistry()
/*     */   {
/* 176 */     return getDeployment().getCacheFactoryRegistry();
/*     */   }
/*     */ 
/*     */   public Object localInvoke(Object idMethod methodObject[] args)
/*     */     throws Throwable
/*     */   {
/* 185 */     return localInvoke(idmethodargsnull);
/*     */   }
/*     */ 
/*     */   public Object localHomeInvoke(Method methodObject[] args)
/*     */     throws Throwable
/*     */   {
/* 194 */     ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
/* 195 */     pushEnc();
/*     */     try
/*     */     {
/* 198 */       long hash = MethodHashing.calculateHash(method);
/* 199 */       MethodInfo info = (MethodInfo)this..get(hash);
/* 200 */       if (info == null)
/*     */       {
/* 202 */         throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
/*     */       }
/*     */ 
/* 206 */       Object localObject1 = invokeLocalHomeMethod(infoargs);
/*     */       return localObject1;
/*     */     }
/*     */     finally
/*     */     {
/* 210 */       Thread.currentThread().setContextClassLoader(oldLoader);
/* 211 */       popEnc(); } throw localObject2;
/*     */   }
/*     */ 
/*     */   public Object localInvoke(Object idMethod methodObject[] argsFutureHolder provider)
/*     */     throws Throwable
/*     */   {
/* 223 */     long start = System.currentTimeMillis();
/*     */ 
/* 225 */     ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
/* 226 */     pushEnc();
/*     */     try
/*     */     {
/* 229 */       long hash = MethodHashing.calculateHash(method);
/* 230 */       MethodInfo info = (MethodInfo)this..get(hash);
/* 231 */       if (info == null)
/*     */       {
/* 233 */         throw new RuntimeException("Could not resolve beanClass method from proxy call: " + method.toString());
/*     */       }
/*     */ 
/* 238 */       Method unadvisedMethod = info.getUnadvisedMethod();
/*     */       try
/*     */       {
/* 242 */         this..callIn();
/*     */         Object localObject1;
/* 244 */         if ((unadvisedMethod != null) && (isHomeMethod(unadvisedMethod)))
/*     */         {
/* 246 */           localObject1 = invokeLocalHomeMethod(infoargs);
/*     */ 
/* 265 */           if (unadvisedMethod != null)
/*     */           {
/* 267 */             long end = System.currentTimeMillis();
/* 268 */             long elapsed = end - start;
/* 269 */             this..updateStats(unadvisedMethodelapsed);
/*     */           }
/*     */ 
/* 272 */           this..callOut();
/*     */ 
/* 274 */           this..pop();
/*     */ 
/* 279 */           Thread.currentThread().setContextClassLoader(oldLoader);
/* 280 */           popEnc(); return localObject1;
/*     */         }
/* 248 */         if ((unadvisedMethod != null) && (isEJBObjectMethod(unadvisedMethod)))
/*     */         {
/* 251 */           localObject1 = invokeEJBLocalObjectMethod(idinfoargs);
/*     */ 
/* 265 */           if (unadvisedMethod != null)
/*     */           {
/* 267 */             end = System.currentTimeMillis();
/* 268 */             long elapsed = end - start;
/* 269 */             this..updateStats(unadvisedMethodelapsed);
/*     */           }
/*     */ 
/* 272 */           this..callOut();
/*     */ 
/* 274 */           this..pop();
/*     */ 
/* 279 */           Thread.currentThread().setContextClassLoader(oldLoader);
/* 280 */           popEnc(); return localObject1;
/*     */         }
/* 254 */         StatefulContainerInvocation nextInvocation = new StatefulContainerInvocation(infoid);
/* 255 */         nextInvocation.setAdvisor(this);
/* 256 */         nextInvocation.setArguments(args);
/*     */ 
/* 258 */         ProxyUtils.addLocalAsynchronousInfo(nextInvocationprovider);
/*     */ 
/* 260 */         this..push(new SessionContainer.InvokedMethod(thistruemethod));
/* 261 */         long end = nextInvocation.invokeNext();
/*     */ 
/* 265 */         if (unadvisedMethod != null)
/*     */         {
/* 267 */           long end = System.currentTimeMillis();
/* 268 */           long elapsed = end - start;
/* 269 */           this..updateStats(unadvisedMethodelapsed);
/*     */         }
/*     */ 
/* 272 */         this..callOut();
/*     */ 
/* 274 */         this..pop();
/*     */ 
/* 279 */         Thread.currentThread().setContextClassLoader(oldLoader);
/* 280 */         popEnc(); return end;
/*     */       }
/*     */       finally
/*     */       {
/* 265 */         if (unadvisedMethod != null)
/*     */         {
/* 267 */           long end = System.currentTimeMillis();
/* 268 */           long elapsed = end - start;
/* 269 */           this..updateStats(unadvisedMethodelapsed);
/*     */         }
/*     */ 
/* 272 */         this..callOut();
/*     */ 
/* 274 */         this..pop();
/*     */       }
/*     */     }
/*     */     finally
/*     */     {
/* 279 */       Thread.currentThread().setContextClassLoader(oldLoader);
/* 280 */       popEnc(); } throw localObject3;
/*     */   }
/*     */ 
/*     */   public Object createSession(Class[] initTypesObject[] initValues)
/*     */   {
/* 291 */     ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
/* 292 */     pushEnc();
/*     */     try
/*     */     {
/* 295 */       Thread.currentThread().setContextClassLoader(this.);
/* 296 */       StatefulBeanContext ctx = getCache().create(initTypesinitValues);
/*     */ 
/* 298 */       ctx.setInUse(false);
/* 299 */       Object localObject1 = ctx.getId();
/*     */       return localObject1;
/*     */     }
/*     */     finally
/*     */     {
/* 303 */       Thread.currentThread().setContextClassLoader(oldLoader);
/* 304 */       popEnc(); } throw localObject2;
/*     */   }
/*     */ 
/*     */   protected void destroySession(Object id)
/*     */   {
/* 310 */     getCache().remove(id);
/*     */   }
/*     */ 
/*     */   public InvocationResponse dynamicInvoke(Object targetInvocation invocation)
/*     */     throws Throwable
/*     */   {
/* 322 */     long start = System.currentTimeMillis();
/*     */ 
/* 324 */     ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
/* 325 */     EJBContainerInvocation newSi = null;
/* 326 */     pushEnc();
/*     */     try
/*     */     {
/* 329 */       Thread.currentThread().setContextClassLoader(this.);
/* 330 */       StatefulRemoteInvocation si = (StatefulRemoteInvocation)invocation;
/* 331 */       MethodInfo info = (MethodInfo)this..get(si.getMethodHash());
/* 332 */       if (info == null)
/*     */       {
/* 334 */         throw new RuntimeException("Could not resolve beanClass method from proxy call");
/*     */       }
/*     */ 
/* 337 */       InvocationResponse response = null;
/* 338 */       Method unadvisedMethod = info.getUnadvisedMethod();
/* 339 */       Object newId = null;
/*     */       try
/*     */       {
/* 343 */         this..callIn();
/*     */ 
/* 345 */         if ((info != null) && (unadvisedMethod != null) && (isHomeMethod(unadvisedMethod)))
/*     */         {
/* 347 */           response = invokeHomeMethod(infosi);
/*     */         }
/* 349 */         else if ((info != null) && (unadvisedMethod != null) && (isEJBObjectMethod(unadvisedMethod)))
/*     */         {
/* 351 */           response = invokeEJBObjectMethod(infosi);
/*     */         }
/*     */         else
/*     */         {
/* 355 */           if (si.getId() == null)
/*     */           {
/* 357 */             StatefulBeanContext ctx = getCache().create(nullnull);
/* 358 */             newId = ctx.getId();
/*     */           }
/*     */           else
/*     */           {
/* 362 */             newId = si.getId();
/*     */           }
/* 364 */           newSi = new StatefulContainerInvocation(infonewId);
/* 365 */           newSi.setArguments(si.getArguments());
/* 366 */           newSi.setMetaData(si.getMetaData());
/* 367 */           newSi.setAdvisor(this);
/*     */ 
/* 369 */           Object rtn = null;
/*     */ 
/* 371 */           this..push(new SessionContainer.InvokedMethod(thisfalseunadvisedMethod));
/* 372 */           rtn = newSi.invokeNext();
/*     */ 
/* 374 */           response = marshallResponse(invocationrtnnewSi.getResponseContextInfo());
/* 375 */           if (newId != nullresponse.addAttachment("NEW_ID"newId);
/*     */         }
/*     */       }
/*     */       catch (Throwable throwable)
/*     */       {
/*     */         long end;
/*     */         long elapsed;
/* 380 */         Throwable exception = throwable;
/* 381 */         if (newId != null)
/*     */         {
/* 383 */           exception = new ForwardId(throwablenewId);
/*     */         }
/* 385 */         Map responseContext = null;
/* 386 */         if (newSi != nullnewSi.getResponseContextInfo();
/* 387 */         response = marshallException(invocationexceptionresponseContext);
/* 388 */         InvocationResponse localInvocationResponse1 = response;
/*     */ 
/* 392 */         if (unadvisedMethod != null)
/*     */         {
/* 394 */           long end = System.currentTimeMillis();
/* 395 */           long elapsed = end - start;
/* 396 */           this..updateStats(unadvisedMethodelapsed);
/*     */         }
/*     */ 
/* 399 */         this..callOut();
/*     */ 
/* 401 */         this..pop();
/*     */ 
/* 408 */         Thread.currentThread().setContextClassLoader(oldLoader);
/* 409 */         popEnc(); return localInvocationResponse1;
/*     */       }
/*     */       finally
/*     */       {
/* 392 */         if (unadvisedMethod != null)
/*     */         {
/* 394 */           long end = System.currentTimeMillis();
/* 395 */           long elapsed = end - start;
/* 396 */           this..updateStats(unadvisedMethodelapsed);
/*     */         }
/*     */ 
/* 399 */         this..callOut();
/*     */ 
/* 401 */         this..pop();
/*     */       }
/*     */ 
/* 404 */       throwable = response;
/*     */       return throwable;
/*     */     }
/*     */     finally
/*     */     {
/* 408 */       Thread.currentThread().setContextClassLoader(oldLoader);
/* 409 */       popEnc(); } throw localObject2;
/*     */   }
/*     */ 
/*     */   public TimerService getTimerService()
/*     */   {
/* 416 */     throw new UnsupportedOperationException("stateful bean doesn't support TimerService (EJB3 18.2#2)");
/*     */   }
/*     */ 
/*     */   public TimerService getTimerService(Object pKey)
/*     */   {
/* 421 */     return getTimerService();
/*     */   }
/*     */ 
/*     */   public void invokePostActivate(BeanContext beanContext)
/*     */   {
/* 427 */     for (Injector injector : this.)
/*     */     {
/* 429 */       if ((injector instanceof JndiPropertyInjector))
/*     */       {
/* 431 */         AccessibleObject field = ((JndiPropertyInjector)injector).getAccessibleObject();
/*     */ 
/* 433 */         if (field.isAnnotationPresent(EJB.class))
/*     */         {
/*     */           continue;
/*     */         }
/*     */ 
/* 438 */         if ((field instanceof Field))
/*     */         {
/* 441 */           if ((((Field)field).getModifiers() & 0x80) > 0)
/* 442 */             injector.inject(beanContext);
/*     */         }
/*     */       }
/*     */     }
/* 446 */     this..postActivate(beanContext);
/*     */   }
/*     */ 
/*     */   public void invokePrePassivate(BeanContext beanContext)
/*     */   {
/* 452 */     this..prePassivate(beanContext);
/*     */   }
/*     */ 
/*     */   protected Class[] getHandledCallbacks()
/*     */   {
/* 458 */     return new Class[] { PostConstruct.classPreDestroy.classPostActivate.classPrePassivate.class };
/*     */   }
/*     */ 
/*     */   public void invokeInit(Object beanClass[] initParameterTypesObject[] initParameterValues)
/*     */   {
/* 466 */     int numParameters = 0;
/* 467 */     if (initParameterTypes != null)
/* 468 */       numParameters = initParameterTypes.length;
/*     */     try
/*     */     {
/* 471 */       for (Method method : bean.getClass().getDeclaredMethods())
/*     */       {
/* 473 */         if (numParameters != method.getParameterTypes().length) {
/*     */           continue;
/*     */         }
/* 476 */         if ((method.getAnnotation(Init.class) == null) && (resolveAnnotation(methodInit.class) == null)) {
/*     */           continue;
/*     */         }
/* 479 */         if (initParameterTypes != null)
/*     */         {
/* 481 */           Object[] parameters = getInitParameters(methodinitParameterTypesinitParameterValues);
/*     */ 
/* 484 */           if (parameters != null)
/* 485 */             method.invoke(beanparameters);
/*     */         }
/*     */         else
/*     */         {
/* 489 */           method.invoke(beannew Object[0]);
/*     */         }
/*     */       }
/*     */ 
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 496 */       throw new RuntimeException(e);
/*     */     }
/*     */   }
/*     */ 
/*     */   protected Object[] getInitParameters(Method methodClass[] initParameterTypesObject[] initParameterValues)
/*     */   {
/* 503 */     if (method.getParameterTypes().length == initParameterTypes.length)
/*     */     {
/* 505 */       for (int i = 0; i < initParameterTypes.lengthi++)
/*     */       {
/* 507 */         Class formal = method.getParameterTypes()[i];
/* 508 */         Class actual = initParameterTypes[i];
/* 509 */         if (!isMethodInvocationConvertible(formalactual == null ? null : actual))
/*     */         {
/* 511 */           return null;
/*     */         }
/*     */       }
/* 513 */       return initParameterValues;
/*     */     }
/* 515 */     return null;
/*     */   }
/*     */ 
/*     */   private static boolean isMethodInvocationConvertible(Class formalClass actual)
/*     */   {
/* 541 */     if ((actual == null) && (!formal.isPrimitive()))
/*     */     {
/* 543 */       return true;
/*     */     }
/*     */ 
/* 548 */     if ((actual != null) && (formal.isAssignableFrom(actual)))
/*     */     {
/* 550 */       return true;
/*     */     }
/*     */ 
/* 556 */     if (formal.isPrimitive())
/*     */     {
/* 558 */       if ((formal == .) && (actual == Boolean.class))
/* 559 */         return true;
/* 560 */       if ((formal == .) && (actual == Character.class))
/* 561 */         return true;
/* 562 */       if ((formal == .) && (actual == Byte.class))
/* 563 */         return true;
/* 564 */       if ((formal == .) && ((actual == Short.class) || (actual == Byte.class)))
/*     */       {
/* 566 */         return true;
/* 567 */       }if ((formal == .) && ((actual == Integer.class) || (actual == Short.class) || (actual == Byte.class)))
/*     */       {
/* 569 */         return true;
/* 570 */       }if ((formal == .) && ((actual == Long.class) || (actual == Integer.class) || (actual == Short.class) || (actual == Byte.class)))
/*     */       {
/* 573 */         return true;
/* 574 */       }if ((formal == .) && ((actual == Float.class) || (actual == Long.class) || (actual == Integer.class) || (actual == Short.class) || (actual == Byte.class)))
/*     */       {
/* 577 */         return true;
/* 578 */       }if ((formal == .) && ((actual == Double.class) || (actual == Float.class) || (actual == Long.class) || (actual == Integer.class) || (actual == Short.class) || (actual == Byte.class)))
/*     */       {
/* 582 */         return true;
/*     */       }
/*     */     }
/* 584 */     return false;
/*     */   }
/*     */ 
/*     */   private Object invokeEJBLocalObjectMethod(Object idMethodInfo infoObject[] args)
/*     */     throws Exception
/*     */   {
/* 590 */     Method unadvisedMethod = info.getUnadvisedMethod();
/* 591 */     if (unadvisedMethod.getName().equals("remove"))
/*     */     {
/* 593 */       destroySession(id);
/*     */ 
/* 595 */       return null;
/*     */     }
/* 597 */     if (unadvisedMethod.getName().equals("getEJBLocalHome"))
/*     */     {
/* 599 */       Object bean = getCache().get(id).getInstance();
/*     */ 
/* 601 */       return bean;
/*     */     }
/* 603 */     if (unadvisedMethod.getName().equals("getPrimaryKey"))
/*     */     {
/* 605 */       return id;
/*     */     }
/* 607 */     if (unadvisedMethod.getName().equals("isIdentical"))
/*     */     {
/* 609 */       EJBObject bean = (EJBObject)args[0];
/*     */ 
/* 611 */       Object primaryKey = bean.getPrimaryKey();
/*     */ 
/* 613 */       boolean isIdentical = id.equals(primaryKey);
/*     */ 
/* 615 */       return Boolean.valueOf(isIdentical);
/*     */     }
/*     */ 
/* 619 */     return null;
/*     */   }
/*     */ 
/*     */   private Object invokeLocalHomeMethod(MethodInfo infoObject[] args)
/*     */     throws Exception
/*     */   {
/* 626 */     Method unadvisedMethod = info.getUnadvisedMethod();
/* 627 */     if (unadvisedMethod.getName().startsWith("create"))
/*     */     {
/* 629 */       Class[] initParameterTypes = new Class[0];
/*     */ 
/* 631 */       Object[] initParameterValues = new Object[0];
/*     */ 
/* 633 */       if (unadvisedMethod.getParameterTypes().length > 0)
/*     */       {
/* 635 */         initParameterTypes = unadvisedMethod.getParameterTypes();
/* 636 */         initParameterValues = args;
/*     */       }
/*     */ 
/* 639 */       LocalBinding binding = (LocalBinding)resolveAnnotation(LocalBinding.class);
/*     */ 
/* 641 */       StatefulLocalProxyFactory factory = new StatefulLocalProxyFactory(thisbinding);
/* 642 */       factory.init();
/*     */ 
/* 644 */       Object proxy = factory.createProxy(initParameterTypesinitParameterValues);
/*     */ 
/* 647 */       return proxy;
/*     */     }
/* 649 */     if (unadvisedMethod.getName().equals("remove"))
/*     */     {
/* 651 */       StatefulHandleImpl handle = (StatefulHandleImpl)args[0];
/*     */ 
/* 653 */       destroySession(handle.id);
/*     */ 
/* 655 */       return null;
/*     */     }
/*     */ 
/* 659 */     return null;
/*     */   }
/*     */ 
/*     */   public Object createLocalProxy(Object idLocalBinding binding)
/*     */     throws Exception
/*     */   {
/* 665 */     StatefulLocalProxyFactory factory = new StatefulLocalProxyFactory(thisbinding);
/* 666 */     factory.init();
/*     */ 
/* 668 */     return factory.createProxy(id);
/*     */   }
/*     */ 
/*     */   public Object createRemoteProxy(Object idRemoteBinding binding)
/*     */     throws Exception
/*     */   {
/* 680 */     StatefulRemoteProxyFactory factory = new StatefulRemoteProxyFactory(thisbinding);
/* 681 */     factory.init();
/*     */ 
/* 683 */     if (id != null) {
/* 684 */       return factory.createProxy(id);
/*     */     }
/* 686 */     return factory.createProxy();
/*     */   }
/*     */ 
/*     */   public boolean isClustered()
/*     */   {
/* 691 */     return hasAnnotation(getBeanClass(), Clustered.class.getName());
/*     */   }
/*     */ 
/*     */   protected InvocationResponse invokeHomeMethod(MethodInfo infoStatefulRemoteInvocation statefulInvocation)
/*     */     throws Throwable
/*     */   {
/* 697 */     Method unadvisedMethod = info.getUnadvisedMethod();
/* 698 */     if (unadvisedMethod.getName().startsWith("create"))
/*     */     {
/* 700 */       Class[] initParameterTypes = new Class[0];
/*     */ 
/* 702 */       Object[] initParameterValues = new Object[0];
/*     */ 
/* 704 */       if (unadvisedMethod.getParameterTypes().length > 0)
/*     */       {
/* 706 */         initParameterTypes = unadvisedMethod.getParameterTypes();
/* 707 */         initParameterValues = statefulInvocation.getArguments();
/*     */       }
/*     */ 
/* 710 */       RemoteBinding binding = null;
/* 711 */       RemoteBindings bindings = (RemoteBindings)resolveAnnotation(RemoteBindings.class);
/* 712 */       if (bindings != null)
/* 713 */         binding = bindings.value()[0];
/*     */       else {
/* 715 */         binding = (RemoteBinding)resolveAnnotation(RemoteBinding.class);
/*     */       }
/* 717 */       StatefulContainerInvocation newStatefulInvocation = buildNewInvocation(infostatefulInvocationinitParameterTypesinitParameterValues);
/*     */ 
/* 721 */       StatefulRemoteProxyFactory factory = new StatefulRemoteProxyFactory(thisbinding);
/* 722 */       factory.init();
/*     */ 
/* 724 */       Object proxy = null;
/* 725 */       if (newStatefulInvocation.getId() != null)
/* 726 */         proxy = factory.createProxy(newStatefulInvocation.getId());
/*     */       else {
/* 728 */         proxy = factory.createProxy();
/*     */       }
/* 730 */       InvocationResponse response = marshallResponse(statefulInvocationproxynewStatefulInvocation.getResponseContextInfo());
/* 731 */       if (newStatefulInvocation.getId() != null) {
/* 732 */         response.addAttachment("NEW_ID"newStatefulInvocation.getId());
/*     */       }
/* 734 */       return response;
/*     */     }
/* 736 */     if (unadvisedMethod.getName().equals("remove"))
/*     */     {
/* 738 */       StatefulHandleImpl handle = (StatefulHandleImpl)statefulInvocation.getArguments()[0];
/*     */ 
/* 741 */       destroySession(handle.id);
/*     */ 
/* 743 */       InvocationResponse response = new InvocationResponse(null);
/* 744 */       response.setContextInfo(statefulInvocation.getResponseContextInfo());
/* 745 */       return response;
/*     */     }
/* 747 */     if (unadvisedMethod.getName().equals("getEJBMetaData"))
/*     */     {
/* 749 */       Class remote = null;
/* 750 */       Class home = null;
/* 751 */       Class pkClass = Object.class;
/* 752 */       HomeHandleImpl homeHandle = null;
/*     */ 
/* 754 */       Remote remoteAnnotation = (Remote)resolveAnnotation(Remote.class);
/* 755 */       if (remoteAnnotation != null)
/* 756 */         remote = remoteAnnotation.value()[0];
/* 757 */       RemoteHome homeAnnotation = (RemoteHome)resolveAnnotation(RemoteHome.class);
/* 758 */       if (homeAnnotation != null)
/* 759 */         home = homeAnnotation.value();
/* 760 */       RemoteBinding remoteBindingAnnotation = (RemoteBinding)resolveAnnotation(RemoteBinding.class);
/* 761 */       if (remoteBindingAnnotation != null) {
/* 762 */         homeHandle = new HomeHandleImpl(remoteBindingAnnotation.jndiBinding());
/*     */       }
/*     */ 
/* 765 */       EJBMetaDataImpl metadata = new EJBMetaDataImpl(remotehomepkClasstruefalsehomeHandle);
/*     */ 
/* 768 */       InvocationResponse response = marshallResponse(statefulInvocationmetadatanull);
/* 769 */       return response;
/*     */     }
/* 771 */     if (unadvisedMethod.getName().equals("getHomeHandle"))
/*     */     {
/* 773 */       HomeHandleImpl homeHandle = null;
/*     */ 
/* 775 */       RemoteBinding remoteBindingAnnotation = (RemoteBinding)resolveAnnotation(RemoteBinding.class);
/* 776 */       if (remoteBindingAnnotation != null) {
/* 777 */         homeHandle = new HomeHandleImpl(remoteBindingAnnotation.jndiBinding());
/*     */       }
/*     */ 
/* 781 */       InvocationResponse response = marshallResponse(statefulInvocationhomeHandlenull);
/* 782 */       return response;
/*     */     }
/*     */ 
/* 786 */     return null;
/*     */   }
/*     */ 
/*     */   protected InvocationResponse invokeEJBObjectMethod(MethodInfo infoStatefulRemoteInvocation statefulInvocation)
/*     */     throws Throwable
/*     */   {
/* 793 */     Method unadvisedMethod = info.getUnadvisedMethod();
/* 794 */     if (unadvisedMethod.getName().equals("getHandle"))
/*     */     {
/* 796 */       StatefulContainerInvocation newStatefulInvocation = buildInvocation(infostatefulInvocation);
/*     */ 
/* 799 */       StatefulHandleImpl handle = new StatefulHandleImpl();
/* 800 */       handle.id = newStatefulInvocation.getId();
/* 801 */       RemoteBinding remoteBinding = (RemoteBinding)resolveAnnotation(RemoteBinding.class);
/* 802 */       if (remoteBinding != null)
/* 803 */         handle.jndiName = remoteBinding.jndiBinding();
/* 804 */       InvocationResponse response = marshallResponse(statefulInvocationhandlenull);
/* 805 */       return response;
/*     */     }
/* 807 */     if (unadvisedMethod.getName().equals("remove"))
/*     */     {
/* 809 */       destroySession(statefulInvocation.getId());
/*     */ 
/* 811 */       InvocationResponse response = new InvocationResponse(null);
/* 812 */       return response;
/*     */     }
/* 814 */     if (unadvisedMethod.getName().equals("getEJBHome"))
/*     */     {
/* 816 */       HomeHandleImpl homeHandle = null;
/*     */ 
/* 818 */       RemoteBinding remoteBindingAnnotation = (RemoteBinding)resolveAnnotation(RemoteBinding.class);
/* 819 */       if (remoteBindingAnnotation != null) {
/* 820 */         homeHandle = new HomeHandleImpl(ProxyFactoryHelper.getHomeJndiName(this));
/*     */       }
/* 822 */       EJBHome ejbHome = homeHandle.getEJBHome();
/*     */ 
/* 824 */       InvocationResponse response = marshallResponse(statefulInvocationejbHomenull);
/* 825 */       return response;
/*     */     }
/* 827 */     if (unadvisedMethod.getName().equals("getPrimaryKey"))
/*     */     {
/* 829 */       Object id = statefulInvocation.getId();
/*     */ 
/* 831 */       InvocationResponse response = marshallResponse(statefulInvocationidnull);
/* 832 */       return response;
/*     */     }
/* 834 */     if (unadvisedMethod.getName().equals("isIdentical"))
/*     */     {
/* 836 */       Object id = statefulInvocation.getId();
/* 837 */       EJBObject bean = (EJBObject)statefulInvocation.getArguments()[0];
/*     */ 
/* 839 */       Object primaryKey = bean.getPrimaryKey();
/*     */ 
/* 841 */       boolean isIdentical = id.equals(primaryKey);
/*     */ 
/* 843 */       InvocationResponse response = marshallResponse(statefulInvocation, Boolean.valueOf(isIdentical), null);
/* 844 */       return response;
/*     */     }
/*     */ 
/* 848 */     return null;
/*     */   }
/*     */ 
/*     */   private StatefulContainerInvocation buildNewInvocation(MethodInfo infoStatefulRemoteInvocation statefulInvocationClass[] initParameterTypesObject[] initParameterValues)
/*     */   {
/* 856 */     StatefulContainerInvocation newStatefulInvocation = null;
/*     */ 
/* 858 */     StatefulBeanContext ctx = null;
/* 859 */     if (initParameterTypes.length > 0)
/* 860 */       ctx = getCache().create(initParameterTypesinitParameterValues);
/*     */     else {
/* 862 */       ctx = getCache().create(nullnull);
/*     */     }
/* 864 */     Object newId = ctx.getId();
/* 865 */     newStatefulInvocation = new StatefulContainerInvocation(infonewId);
/*     */ 
/* 867 */     newStatefulInvocation.setArguments(statefulInvocation.getArguments());
/* 868 */     newStatefulInvocation.setMetaData(statefulInvocation.getMetaData());
/* 869 */     newStatefulInvocation.setAdvisor(this);
/*     */ 
/* 871 */     return newStatefulInvocation;
/*     */   }
/*     */ 
/*     */   private StatefulContainerInvocation buildInvocation(MethodInfo infoStatefulRemoteInvocation statefulInvocation)
/*     */   {
/* 877 */     StatefulContainerInvocation newStatefulInvocation = null;
/* 878 */     Object newId = null;
/* 879 */     if (statefulInvocation.getId() == null)
/*     */     {
/* 881 */       StatefulBeanContext ctx = getCache().create(nullnull);
/* 882 */       newId = ctx.getId();
/* 883 */       newStatefulInvocation = new StatefulContainerInvocation(infonewId);
/*     */     }
/*     */     else
/*     */     {
/* 887 */       newStatefulInvocation = new StatefulContainerInvocation(infostatefulInvocation.getId());
/*     */     }
/*     */ 
/* 890 */     newStatefulInvocation.setArguments(statefulInvocation.getArguments());
/* 891 */     newStatefulInvocation.setMetaData(statefulInvocation.getMetaData());
/* 892 */     newStatefulInvocation.setAdvisor(this);
/*     */ 
/* 894 */     return newStatefulInvocation;
/*     */   }
/*     */ 
/*     */   public Object getBusinessObject(BeanContext beanContextClass businessInterface)
/*     */     throws IllegalStateException
/*     */   {
/* 900 */     assert (beanContext != null) : "beanContext is null";
/* 901 */     assert (businessInterface != null) : "businessInterface is null";
/*     */ 
/* 903 */     StatefulBeanContext ctx = (StatefulBeanContext)beanContext;
/*     */ 
/* 905 */     SessionContainer container = ctx.getContainer();
/* 906 */     assert (container == this) : ("beanContext not of this container (" + container + " != " + this + ")");
/*     */ 
/* 908 */     boolean isRemote = false;
/* 909 */     boolean found = false;
/* 910 */     Class[] remoteInterfaces = ProxyFactoryHelper.getRemoteAndBusinessRemoteInterfaces(this);
/* 911 */     for (Class intf : remoteInterfaces)
/*     */     {
/* 913 */       if (!intf.getName().equals(businessInterface.getName()))
/*     */         continue;
/* 915 */       isRemote = true;
/* 916 */       found = true;
/* 917 */       break;
/*     */     }
/*     */ 
/* 920 */     if (!found)
/*     */     {
/* 922 */       Class[] localInterfaces = ProxyFactoryHelper.getLocalAndBusinessLocalInterfaces(this);
/* 923 */       for (Class intf : localInterfaces)
/*     */       {
/* 925 */         if (!intf.getName().equals(businessInterface.getName()))
/*     */           continue;
/* 927 */         found = true;
/* 928 */         break;
/*     */       }
/*     */     }
/*     */ 
/* 932 */     if (!foundthrow new IllegalStateException(businessInterface.getName() + " is not a business interface for container " + this);
/*     */ 
/* 934 */     for (ProxyFactory factory : this..getProxyFactories())
/*     */     {
/* 936 */       if ((isRemote) && ((factory instanceof StatefulRemoteProxyFactory)))
/*     */       {
/* 938 */         return ((StatefulRemoteProxyFactory)factory).createProxy(ctx.getId());
/*     */       }
/* 940 */       if ((!isRemote) && ((factory instanceof StatefulLocalProxyFactory)))
/*     */       {
/* 942 */         return ((StatefulLocalProxyFactory)factory).createProxy(ctx.getId());
/*     */       }
/*     */     }
/* 945 */     throw new IllegalStateException("Unable to create proxy for getBusinessObject as a proxy factory was not found");
/*     */   }
/*     */ 
/*     */   protected void removeHandle(Handle arg)
/*     */     throws Exception
/*     */   {
/* 955 */     arg.getEJBObject().remove();
/*     */   }
/*     */ 
/*     */   static
/*     */   {
/*  81 */      = Logger.getLogger(StatefulContainer.class);
/*     */   }
/*     */ }
/* Location:           /home/mnovotny/projects/EMBEDDED_JBOSS_BETA3_COMMUNITY/embedded/output/lib/embedded-jboss/lib/jboss-embedded-all.jar
 * Qualified Name:     org.jboss.ejb3.stateful.StatefulContainer
 * JD-Core Version:    0.6.0
 */