org.openejb.core.ivm
Class BaseEjbProxyHandler

java.lang.Object
  extended by org.openejb.core.ivm.BaseEjbProxyHandler
All Implemented Interfaces:
java.io.Serializable, InvocationHandler
Direct Known Subclasses:
EjbHomeProxyHandler, EjbObjectProxyHandler

public abstract class BaseEjbProxyHandler
extends java.lang.Object
implements InvocationHandler, java.io.Serializable

This InvocationHandler and its proxy are serializable and can be used by HomeHandle, Handle, and MetaData to persist and revive handles. It maintains its original client identity which allows the container to be more discerning about allowing the revieed proxy to be used. See StatefulContaer manager for more details.

Author:
David Blevins, Richard Monson-Haefel
See Also:
Serialized Form

Field Summary
 RpcContainer container
          The RpcContainer that the bean deployment this stub hanlder represents is deployed in.
 java.lang.Object deploymentID
          The unique id of the bean deployment that this stub handler represents.
 DeploymentInfo deploymentInfo
          The DeployemtnInfo object if the bean deployment that this stub handler represents.
protected  boolean doIntraVmCopy
           
 boolean inProxyMap
           
protected  boolean isInvalidReference
           
protected static java.util.Hashtable liveHandleRegistry
          keeps track of live BaseEjbProxyHanlders in this VM.
 java.lang.Object primaryKey
          The primary key of the bean deployment or null if the deployment is a bean type that doesn't require a primary key
 
Constructor Summary
BaseEjbProxyHandler(RpcContainer container, java.lang.Object pk, java.lang.Object depID)
          Constructs a BaseEjbProxyHandler representing the specifed bean deployment.
 
Method Summary
protected abstract  java.lang.Object _invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
          Overridden by subclasses and called by invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]).
protected abstract  java.lang.Object _writeReplace(java.lang.Object proxy)
           
protected  void checkAuthorization(java.lang.reflect.Method method)
          Checks if the caller of the specified method is authorized to access and execute it.
protected  java.lang.Object[] copyArgs(java.lang.Object[] objects)
           
protected  java.lang.Object copyObj(java.lang.Object object)
           
 boolean equals(java.lang.Object obj)
           
abstract  ProxyInfo getProxyInfo()
           
protected  java.lang.Object getThreadSpecificSecurityIdentity()
           
 int hashCode()
           
protected static void invalidateAllHandlers(java.lang.Object key)
           
 void invalidateReference()
          Invalidates this reference so that it can not be used as a proxy for the bean identity.
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
          Preserves the context of the current thread and passes the invoke on to the BaseEjbProxyHandler subclass where the Container will be asked to invoke the method on the bean.
 boolean isLocal()
           
protected static void registerHandler(java.lang.Object key, BaseEjbProxyHandler handler)
           
 void setIntraVmCopyMode(boolean on)
          This method enables/disables the copy process of the arguments and return value to and from a regular EJB invocation.
 void setLocal(boolean isLocal)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

liveHandleRegistry

protected static final java.util.Hashtable liveHandleRegistry
keeps track of live BaseEjbProxyHanlders in this VM. So that related handlers can be removed if necessary. Currently this registry is only used to track live EjbObjectProxyHandlers. The EjbObjectProxyHandlers are tracked to allow remove() operations and invalidate exceptions to be propagated to the proper handler instances. There are several scenarios where this is useful:

deploymentID

public final java.lang.Object deploymentID
The unique id of the bean deployment that this stub handler represents.


primaryKey

public final java.lang.Object primaryKey
The primary key of the bean deployment or null if the deployment is a bean type that doesn't require a primary key


inProxyMap

public boolean inProxyMap

deploymentInfo

public transient DeploymentInfo deploymentInfo
The DeployemtnInfo object if the bean deployment that this stub handler represents.


container

public transient RpcContainer container
The RpcContainer that the bean deployment this stub hanlder represents is deployed in.


isInvalidReference

protected boolean isInvalidReference

doIntraVmCopy

protected boolean doIntraVmCopy
Constructor Detail

BaseEjbProxyHandler

public BaseEjbProxyHandler(RpcContainer container,
                           java.lang.Object pk,
                           java.lang.Object depID)
Constructs a BaseEjbProxyHandler representing the specifed bean deployment.

Parameters:
container - The Container that the bean deployment this stub hanlder represents is deployed in.
pk - The primary key of the bean deployment or null if the deployment is a bean type that doesn't require a primary key.
depID - The unique id of the bean deployment that this stub handler will represent.
Method Detail

checkAuthorization

protected void checkAuthorization(java.lang.reflect.Method method)
                           throws OpenEJBException
Checks if the caller of the specified method is authorized to access and execute it. Relies on the SecurityService assigned to the Container that this bean deployment is in to determine if the caller is authorized.

Parameters:
method - The method the caller is attempting to execute.
Throws:
OpenEJBException - If the caller does bot have adequate authorization to execute the specified method.

getThreadSpecificSecurityIdentity

protected java.lang.Object getThreadSpecificSecurityIdentity()

setIntraVmCopyMode

public void setIntraVmCopyMode(boolean on)
This method enables/disables the copy process of the arguments and return value to and from a regular EJB invocation. In some cases it is desireable to skip the copy, e.g. when the invocation comes from an RMI or CORBA remote layer, where the arguemnts are already copies.


invoke

public java.lang.Object invoke(java.lang.Object proxy,
                               java.lang.reflect.Method method,
                               java.lang.Object[] args)
                        throws java.lang.Throwable
Preserves the context of the current thread and passes the invoke on to the BaseEjbProxyHandler subclass where the Container will be asked to invoke the method on the bean. When entering a container the ThreadContext will change to match the context of the bean being serviced. That changes the current context of the calling bean, so the context must be preserved and then resourced after request is serviced. The context is restored after the subclass' _invoke method returns.

Specified by:
invoke in interface InvocationHandler
Parameters:
proxy - The Proxy object that represents this bean deployment's EJBObject or EJBHome.
method - The EJBHome or EJBObject method the caller is invoking.
args - The parameters to the mehtod being invoked
Returns:
The result of invoking the appropriate method on the bean instance.
Throws:
java.lang.Throwable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

_invoke

protected abstract java.lang.Object _invoke(java.lang.Object proxy,
                                            java.lang.reflect.Method method,
                                            java.lang.Object[] args)
                                     throws java.lang.Throwable
Overridden by subclasses and called by invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[]). Subclasses implement the main behavior of calling invoke on the Container that the bean deployment lives in.

Parameters:
proxy - The Proxy subclass that is the bean's EJBObject or EJBHome.
method - The bean method that the caller is attempting to invoke.
args - The arguments to the method being invoked.
Returns:
The result of invoking the appropriate method on the bean instance.
Throws:
java.lang.Throwable

copyArgs

protected java.lang.Object[] copyArgs(java.lang.Object[] objects)
                               throws java.io.IOException,
                                      java.lang.ClassNotFoundException
Parameters:
objects - The object array you wish to dereference.
Returns:
An object array with new, equlivilent instances of the original objects contained in the array.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

copyObj

protected java.lang.Object copyObj(java.lang.Object object)
                            throws java.io.IOException,
                                   java.lang.ClassNotFoundException
Parameters:
object -
Returns:
An equlivilent instance of the original object.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

invalidateReference

public void invalidateReference()
Invalidates this reference so that it can not be used as a proxy for the bean identity. This method may be called when an InvalidateReferenceException is thrown by the container or when the bean identity associated with this proxy is explicitly removed, by calling one of the remove( ) methods.


invalidateAllHandlers

protected static void invalidateAllHandlers(java.lang.Object key)

_writeReplace

protected abstract java.lang.Object _writeReplace(java.lang.Object proxy)
                                           throws java.io.ObjectStreamException
Throws:
java.io.ObjectStreamException

registerHandler

protected static void registerHandler(java.lang.Object key,
                                      BaseEjbProxyHandler handler)

getProxyInfo

public abstract ProxyInfo getProxyInfo()

isLocal

public boolean isLocal()

setLocal

public void setLocal(boolean isLocal)


Copyright © 1999-2011 OpenEJB. All Rights Reserved.