org.mockejb
Class MockEjbObject

java.lang.Object
  extended byorg.mockejb.MockEjbObject
All Implemented Interfaces:
javax.ejb.EnterpriseBean, java.lang.reflect.InvocationHandler, java.io.Serializable

public class MockEjbObject
extends java.lang.Object
implements java.lang.reflect.InvocationHandler, javax.ejb.EnterpriseBean, java.io.Serializable

Serves as a proxy for all calls to the bean. Provided implementation of javax.ejb.EJBObject and javax.ejb.EJBLocalObject interfaces. Provides API for working with interceptors.

Author:
Alexander Ananiev
See Also:
Serialized Form

Method Summary
 void addInterceptor(Interceptor interceptor)
          Deprecated. Use AspectSystem and poincuts to add interceptors
 boolean equals(java.lang.Object obj)
          Tests if this object is equals to the given object.
 java.lang.Object getBean()
           
 MockEjbContext getEjbContext()
          Returns MockEjbContext object for the bean backed by this MockEjbObject.
 javax.ejb.EJBHome getEJBHome()
          Obtains the enterprise Bean's home interface.
 javax.ejb.EJBLocalHome getEJBLocalHome()
          Obtains the enterprise Bean's local home interface.
 javax.ejb.Handle getHandle()
          This method is not supported.
 java.lang.Object getPrimaryKey()
           
 int hashCode()
           
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method ifaceMethod, java.lang.Object[] paramVals)
          Invokes the target bean's method by delegating to the InvocationContext which calls interceptors and then the bean itself.
 boolean isIdentical(java.lang.Object object)
          Test if a given object is identical to the invoked object.
 void remove()
          Currently this method does not do anything TODO: should call ejbRemove for stateful session bean
 void setTransactionPolicy(TransactionPolicy policy)
          Deprecated. use TransactionManager with the AspectSystem to set transaction policies
 java.lang.String toString()
          Provides string representation of this MockEjbObject and the its bean implementation object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

addInterceptor

public void addInterceptor(Interceptor interceptor)
Deprecated. Use AspectSystem and poincuts to add interceptors

Adds the interceptor to the interceptor list for this bean.

Parameters:
interceptor - interceptor to add

setTransactionPolicy

public void setTransactionPolicy(TransactionPolicy policy)
Deprecated. use TransactionManager with the AspectSystem to set transaction policies

Sets the transaction policy for the TransactionManager which is always part of the interceptor list.
The default policy is "Supports".

Parameters:
policy - transaction policy as defined by TransactionPolicy enumeration.

invoke

public java.lang.Object invoke(java.lang.Object proxy,
                               java.lang.reflect.Method ifaceMethod,
                               java.lang.Object[] paramVals)
                        throws java.lang.Throwable
Invokes the target bean's method by delegating to the InvocationContext which calls interceptors and then the bean itself. If we're dealing with the standard EJB method, this object provides the implementation of these methods instead of the target bean. All interceptors are still invoked as before.

Specified by:
invoke in interface java.lang.reflect.InvocationHandler
Throws:
java.lang.Throwable

getEjbContext

public MockEjbContext getEjbContext()
Returns MockEjbContext object for the bean backed by this MockEjbObject. MockEjbContext implements SessionContext and MesageDrivenContext. Additionally it provides some convenience methods.

Returns:
MockEjbContext instance

getEJBHome

public javax.ejb.EJBHome getEJBHome()
Obtains the enterprise Bean's home interface.

Returns:
a reference to the enterprise Bean's home interface.

getEJBLocalHome

public javax.ejb.EJBLocalHome getEJBLocalHome()
Obtains the enterprise Bean's local home interface.

Returns:
a reference to the enterprise Bean's local home interface.

getHandle

public javax.ejb.Handle getHandle()
                           throws java.rmi.RemoteException
This method is not supported.

Throws:
java.rmi.RemoteException

getPrimaryKey

public java.lang.Object getPrimaryKey()

remove

public void remove()
            throws javax.ejb.RemoveException
Currently this method does not do anything TODO: should call ejbRemove for stateful session bean

Throws:
javax.ejb.RemoveException
See Also:
EJBObject.remove()

isIdentical

public boolean isIdentical(java.lang.Object object)
Test if a given object is identical to the invoked object. Works for both EJBObject and EJBLocalObject interfaces. It uses address equality so the provided parameter does not have to be EJB-specific.

Parameters:
object - an object to test for identity with the invoked object.
Returns:
true if the given object is identical to this object

equals

public boolean equals(java.lang.Object obj)
Tests if this object is equals to the given object. If the given object is a proxy to another bean, the pointer equality between proxies is used. Otherwise, super.equals() is called. In other words, this method can be used to compare MockEjbObject instances as well as bean dynamic proxies returned by Home create().

Parameters:
obj - object to compare with
Returns:
true if this object or the dynamic proxy it holds equals to the given object.

hashCode

public int hashCode()

getBean

public java.lang.Object getBean()

toString

public java.lang.String toString()
Provides string representation of this MockEjbObject and the its bean implementation object.

See Also:
Object.toString()