org.objectweb.easybeans.rpc
Class AbsInvocationHandler

java.lang.Object
  extended by org.objectweb.easybeans.rpc.AbsInvocationHandler
All Implemented Interfaces:
java.io.Serializable, java.lang.reflect.InvocationHandler
Direct Known Subclasses:
ClientRPCInvocationHandler, LocalCallInvocationHandler

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

Abstract class used by remote or local invocation handler.

Author:
Florent Benoit
See Also:
Serialized Form

Field Summary
private  java.lang.Long beanId
          Bean id.
private  java.lang.String containerId
          Container id.
private  java.lang.String factoryName
          Factory name.
private  java.util.Map<java.lang.reflect.Method,java.lang.Long> hashedMethods
          Map between method and its hash.
private  java.lang.String interfaceClassName
          Interface used by this handler.
private  boolean isItfExtendingRmiRemote
          Boolean used to know if this class extends java.rmi.Remote class.
private  boolean useID
          useID true if all instance build with this ref are unique (stateful), false if it references the same object (stateless).
 
Constructor Summary
AbsInvocationHandler(java.lang.String containerId, java.lang.String factoryName, boolean useID)
          Build a new Invocation handler.
 
Method Summary
protected  java.lang.Long getBeanId()
          Gets the bean id.
protected  java.lang.String getContainerId()
           
protected  java.lang.String getFactoryName()
           
protected  java.util.Map<java.lang.reflect.Method,java.lang.Long> getHashedMethods()
           
 java.lang.String getInterfaceClassName()
           
protected  java.lang.Object handleObjectMethods(java.lang.reflect.Method method, java.lang.Object[] args)
          Manages all methods of java.lang.Object class.
protected  void handleThrowable(java.lang.Throwable originalThrowable, boolean isApplicationException, java.lang.reflect.Method method)
          Handle the given throwable and throw the correct exception to the client.
 boolean isExtendingRmiRemote()
           
 boolean isUsingID()
           
protected  void setBeanId(java.lang.Long beanId)
          Sets the id of the bean.
protected  void setContainerId(java.lang.String containerId)
          Sets the container ID.
 void setExtendingRmiRemote(boolean isItfExtendingRmiRemote)
          Sets the flag if interface is extending java.rmi.Remote.
protected  void setFactoryName(java.lang.String factoryName)
          Sets the factory's name.
protected  void setHashedMethods(java.util.Map<java.lang.reflect.Method,java.lang.Long> hashedMethods)
          Sets the hashed methods.
 void setInterfaceClass(java.lang.Class clz)
          Sets the interface that represents this handler.
protected  void setInterfaceClassName(java.lang.String interfaceClassName)
          Sets the name of the interface that represents this handler.
 void setUseID(boolean useID)
          Sets the flag if all instance build with this ref are unique or not.
 java.lang.String toString()
          Gets a string representation for this handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.reflect.InvocationHandler
invoke
 

Field Detail

containerId

private java.lang.String containerId
Container id.


factoryName

private java.lang.String factoryName
Factory name.


beanId

private java.lang.Long beanId
Bean id.


hashedMethods

private transient java.util.Map<java.lang.reflect.Method,java.lang.Long> hashedMethods
Map between method and its hash.


interfaceClassName

private java.lang.String interfaceClassName
Interface used by this handler.


isItfExtendingRmiRemote

private boolean isItfExtendingRmiRemote
Boolean used to know if this class extends java.rmi.Remote class.


useID

private boolean useID
useID true if all instance build with this ref are unique (stateful), false if it references the same object (stateless).

Constructor Detail

AbsInvocationHandler

public AbsInvocationHandler(java.lang.String containerId,
                            java.lang.String factoryName,
                            boolean useID)
Build a new Invocation handler.

Parameters:
containerId - the id of the container that will be called on the remote side.
factoryName - the name of the remote factory.
useID - true if all instance build with this ref are unique (stateful), false if it references the same object (stateless)
Method Detail

handleObjectMethods

protected java.lang.Object handleObjectMethods(java.lang.reflect.Method method,
                                               java.lang.Object[] args)
Manages all methods of java.lang.Object class.

Parameters:
method - the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
args - an array of objects containing the values of the arguments passed in the method invocation on the proxy instance
Returns:
the value of the called method.

handleThrowable

protected void handleThrowable(java.lang.Throwable originalThrowable,
                               boolean isApplicationException,
                               java.lang.reflect.Method method)
                        throws java.lang.Exception
Handle the given throwable and throw the correct exception to the client.

Parameters:
originalThrowable - the exception that has been thrown on the server side.
isApplicationException - true if it is an application exception, else false.
method - the Method instance corresponding to the interface method invoked on the proxy instance.
Throws:
java.lang.Exception - the exception that has been wrapped or not for the client.

setBeanId

protected void setBeanId(java.lang.Long beanId)
Sets the id of the bean.

Parameters:
beanId - the new ID.

setHashedMethods

protected void setHashedMethods(java.util.Map<java.lang.reflect.Method,java.lang.Long> hashedMethods)
Sets the hashed methods.

Parameters:
hashedMethods - the hash for each method.

getBeanId

protected java.lang.Long getBeanId()
Gets the bean id.

Returns:
the bean id.

getContainerId

protected java.lang.String getContainerId()
Returns:
the container id.

getFactoryName

protected java.lang.String getFactoryName()
Returns:
the name of the factory.

getHashedMethods

protected java.util.Map<java.lang.reflect.Method,java.lang.Long> getHashedMethods()
Returns:
the hashes for each method.

setContainerId

protected void setContainerId(java.lang.String containerId)
Sets the container ID.

Parameters:
containerId - the identifier of the container.

setFactoryName

protected void setFactoryName(java.lang.String factoryName)
Sets the factory's name.

Parameters:
factoryName - the name of the factory.

getInterfaceClassName

public java.lang.String getInterfaceClassName()
Returns:
the name of the interface that represents this handler.

setInterfaceClassName

protected void setInterfaceClassName(java.lang.String interfaceClassName)
Sets the name of the interface that represents this handler.

Parameters:
interfaceClassName - the name of the interface.

setInterfaceClass

public void setInterfaceClass(java.lang.Class clz)
Sets the interface that represents this handler.

Parameters:
clz - the instance of the interface.

setExtendingRmiRemote

public void setExtendingRmiRemote(boolean isItfExtendingRmiRemote)
Sets the flag if interface is extending java.rmi.Remote.

Parameters:
isItfExtendingRmiRemote - true if it extending, else false.

isExtendingRmiRemote

public boolean isExtendingRmiRemote()
Returns:
true if the interface used by this handler is extending java.rmi.Remote.

setUseID

public void setUseID(boolean useID)
Sets the flag if all instance build with this ref are unique or not.

Parameters:
useID - true : (stateful), false if it references the same object (stateless).

isUsingID

public boolean isUsingID()
Returns:
true : (stateful), false if it references the same object (stateless).

toString

public java.lang.String toString()
Gets a string representation for this handler.

Overrides:
toString in class java.lang.Object
Returns:
a string representation for this handler.