FileDocCategorySizeDatePackage
StatefulHandleImpl.javaAPI DocJBoss 4.2.15417Fri Jul 13 20:53:50 BST 2007org.jboss.ejb3.stateful

StatefulHandleImpl

public class StatefulHandleImpl extends Object implements javax.ejb.Handle
An EJB stateful session bean handle.
author
Marc Fleury
author
Jason Dillon
author
Bill Burke
author
William DeCoste
version
$Revision: 60233 $

Fields Summary
private static final Logger
log
static final long
serialVersionUID
Serial Version Identifier.
protected static final Method
GET_EJB_OBJECT
A reference to {@link Handle#getEJBObject}.
private Object
invokerID
The value of our local Invoker.ID to detect when we are local.
public int
objectName
The identity of the bean.
public String
jndiName
public String
invokerProxyBinding
public org.jboss.invocation.Invoker
invoker
public Object
id
protected Hashtable
jndiEnv
The JNDI env in effect when the home handle was created
Constructors Summary
public StatefulHandleImpl()
Initialize Handle method references.


           
   
   
      try
      {
         GET_EJB_OBJECT = Handle.class.getMethod("getEJBObject", new Class[0]);
      }
      catch(Exception e)
      {
         e.printStackTrace();
         throw new ExceptionInInitializerError(e);
      }
   
      
   
public StatefulHandleImpl(int objectName, String jndiName, org.jboss.invocation.Invoker invoker, String invokerProxyBinding, Object id, Object invokerID)
Create an ejb handle for a stateful session bean.

param
objectName - the session container jmx name
param
jndiName - the session home ejb name
param
invoker - the invoker to request the EJBObject from
param
invokerProxyBinding - the type of invoker binding
param
id - the session id

      this.jndiName = jndiName;
      this.id = id;
      this.jndiEnv = (Hashtable) NamingContextFactory.lastInitialContextEnv.get();
      try
      {
         String property = System.getProperty("org.jboss.ejb.sfsb.handle.V327");
         if (property != null)
         {
            this.invokerProxyBinding = invokerProxyBinding;
            this.invokerID = invokerID;
            this.objectName = objectName;
            this.invoker = invoker;
         }
      }
      catch (AccessControlException ignored)
      {
      }

   
Methods Summary
public javax.ejb.EJBObjectgetEJBObject()
Handle implementation. This differs from Stateless and Entity handles which just invoke standard methods (create and findByPrimaryKey respectively) on the Home interface (proxy). There is no equivalent option for stateful SBs, so a direct invocation on the container has to be made to locate the bean by its id (the stateful SB container provides an implementation of getEJBObject). This means the security context has to be set here just as it would be in the Proxy.

return
EJBObject reference.
throws
ServerException Could not get EJBObject.

      try
      {
         InitialContext ic = null;
         if( jndiEnv != null )
            ic = new InitialContext(jndiEnv);
         else
            ic = new InitialContext();
    
         Proxy proxy = (Proxy) ic.lookup(jndiName);

         return (EJBObject) proxy;
      }
      catch (Throwable t)
      {
         t.printStackTrace();
         throw new RemoteException("Error during getEJBObject", t);
      }
   
public java.lang.ObjectgetID()

return
the internal session identifier

      return id;
   
public java.lang.StringgetJNDIName()

return
the jndi name

      return jndiName;