au.gov.tas.dpiwe.mr.bean
Class MrEntityContext

java.lang.Object
  extended by au.gov.tas.dpiwe.mr.bean.MrEntityContext
All Implemented Interfaces:
EJBContext, EntityContext

public class MrEntityContext
extends Object
implements EntityContext

An implementation of EntityContext with a few internal methods utilized by the Architecture added for good measure.

This class is essential to imposing lifecycle on Mr Architecture beans, even though this lifecycle deviates somewhat from standard EJBs. The additional methods exposed here over EntityContext are not for use outside the Architecture, and are subject to change without notice.

Since:
Mr Architecture 1.0
Version:
1.0.0.8
Author:
Kade Hansson
See Also:
EntityContext

Field Summary
protected  EJBLocalObject bean
          The bean wrapper for this entity bean.
protected  Container container
          The container to which the entity bean belongs.
protected  EJBLocalHome home
          The home for entity beans of this type.
 
Constructor Summary
MrEntityContext()
          Creates a new empty entity bean context.
MrEntityContext(Container container, EJBLocalObject bean, EJBLocalHome home)
          Creates a new entity bean context for an entity bean.
MrEntityContext(Container container, EntityBean bean)
          Creates a new entity bean context for an entity bean.
 
Method Summary
 void activate(Container container, EntityBean bean)
          Called internally by the Architecture in order to issue an activate lifecycle event to the entity bean to which this context object is assigned.
 void create(Container container, EntityBean bean)
          Called internally by the Architecture in order to issue a create and post-create lifecycle events and establish the container and home for the entity bean to which this context object is assigned, at least if these were not already established at construct time.
 Identity getCallerIdentity()
          Obtain the java.security.Identity of the caller.
 Principal getCallerPrincipal()
          Obtain the java.security.Principal that identifies the caller.
 EJBHome getEJBHome()
          Obtain the enterprise bean's remote home interface.
 EJBLocalHome getEJBLocalHome()
          Obtain the enterprise bean's local home interface.
 EJBLocalObject getEJBLocalObject()
          Obtain a reference to the EJB local object that is currently associated with the instance.
 EJBObject getEJBObject()
          Obtain a reference to the EJB object that is currently associated with the instance.
 Properties getEnvironment()
          Obtain the enterprise bean's environment properties.
 Object getPrimaryKey()
          Obtain the primary key of the EJB object that is currently associated with this instance.
 boolean getRollbackOnly()
          Test if the transaction has been marked for rollback only.
 UserTransaction getUserTransaction()
          Obtain the transaction demarcation interface.
 boolean isCallerInRole(Identity role)
          Test if the caller has a given role.
 boolean isCallerInRole(String roleName)
          Test if the caller has a given security role.
 void setRollbackOnly()
          Mark the current transaction for rollback.
 EntityContext wrap(Container container, EJBLocalObject bean)
          Amends an entity bean context to reflect a new container and/or object wrapper.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

container

protected Container container
The container to which the entity bean belongs.


bean

protected EJBLocalObject bean
The bean wrapper for this entity bean.


home

protected EJBLocalHome home
The home for entity beans of this type.

Constructor Detail

MrEntityContext

public MrEntityContext()
Creates a new empty entity bean context.

Not to be called by external clients.


MrEntityContext

public MrEntityContext(Container container,
                       EntityBean bean)
Creates a new entity bean context for an entity bean.

Not to be called by external clients.

Parameters:
container - the container to which the entity bean belongs.
bean - the entity bean whose context this will be.

MrEntityContext

public MrEntityContext(Container container,
                       EJBLocalObject bean,
                       EJBLocalHome home)
Creates a new entity bean context for an entity bean.

Not to be called by external clients.

Parameters:
container - the container to which the entity bean belongs.
bean - the entity bean's object interface.
home - the entity bean's home interface.
Method Detail

create

public void create(Container container,
                   EntityBean bean)
            throws CreateException,
                   EJBException
Called internally by the Architecture in order to issue a create and post-create lifecycle events and establish the container and home for the entity bean to which this context object is assigned, at least if these were not already established at construct time.

Not to be called by external clients.

Parameters:
container - the container to which the entity bean belongs.
bean - the entity bean which has been created.
Throws:
CreateException
EJBException

activate

public void activate(Container container,
                     EntityBean bean)
              throws EJBException,
                     RemoteException
Called internally by the Architecture in order to issue an activate lifecycle event to the entity bean to which this context object is assigned.

Not to be called by external clients.

Parameters:
container - the container to which the entity bean belongs.
bean - the entity bean to activate.
Throws:
EJBException
RemoteException

wrap

public EntityContext wrap(Container container,
                          EJBLocalObject bean)
Amends an entity bean context to reflect a new container and/or object wrapper.

Used internally by the Architecture itself and not to be called by external clients.

Parameters:
container - the container to which the entity bean belongs.
bean - the entity bean's object interface.
Returns:
the entity bean context so amended.

getEJBHome

public EJBHome getEJBHome()
Description copied from interface: EJBContext
Obtain the enterprise bean's remote home interface.

Specified by:
getEJBHome in interface EJBContext
Returns:
The enterprise bean's remote home interface.

getEJBObject

public EJBObject getEJBObject()
Description copied from interface: EntityContext
Obtain a reference to the EJB object that is currently associated with the instance.

An instance of an entity enterprise Bean can call this method only when the instance is associated with an EJB object identity, i.e. in the ejbActivate, ejbPassivate, ejbPostCreate, ejbRemove, ejbLoad, ejbStore, and business methods.

An instance can use this method, for example, when it wants to pass a reference to itself in a method argument or result.

Specified by:
getEJBObject in interface EntityContext
Returns:
The EJB object currently associated with the instance.

getEnvironment

public Properties getEnvironment()
Description copied from interface: EJBContext
Obtain the enterprise bean's environment properties.

Note: If the enterprise bean has no environment properties this method returns an empty java.util.Properties object. This method never returns null.

Specified by:
getEnvironment in interface EJBContext
Returns:
The environment properties for the enterprise bean.

getEJBLocalHome

public EJBLocalHome getEJBLocalHome()
Description copied from interface: EJBContext
Obtain the enterprise bean's local home interface.

Specified by:
getEJBLocalHome in interface EJBContext
Returns:
The enterprise bean's local home interface.

getEJBLocalObject

public EJBLocalObject getEJBLocalObject()
Description copied from interface: EntityContext
Obtain a reference to the EJB local object that is currently associated with the instance.

An instance of an entity enterprise Bean can call this method only when the instance is associated with an EJB local object identity, i.e. in the ejbActivate, ejbPassivate, ejbPostCreate, ejbRemove, ejbLoad, ejbStore, and business methods.

An instance can use this method, for example, when it wants to pass a reference to itself in a method argument or result.

Specified by:
getEJBLocalObject in interface EntityContext
Returns:
The EJB local object currently associated with the instance.

getPrimaryKey

public Object getPrimaryKey()
Description copied from interface: EntityContext
Obtain the primary key of the EJB object that is currently associated with this instance.

An instance of an entity enterprise Bean can call this method only when the instance is associated with an EJB object identity, i.e. in the ejbActivate, ejbPassivate, ejbPostCreate, ejbRemove, ejbLoad, ejbStore, and business methods.

Note: The result of this method is that same as the result of getEJBObject().getPrimaryKey().

Specified by:
getPrimaryKey in interface EntityContext
Returns:
The primary key currently associated with the instance.

getRollbackOnly

public boolean getRollbackOnly()
Description copied from interface: EJBContext
Test if the transaction has been marked for rollback only. An enterprise bean instance can use this operation, for example, to test after an exception has been caught, whether it is fruitless to continue computation on behalf of the current transaction. Only enterprise beans with container-managed transactions are allowed to use this method.

Specified by:
getRollbackOnly in interface EJBContext
Returns:
True if the current transaction is marked for rollback, false otherwise.

setRollbackOnly

public void setRollbackOnly()
Description copied from interface: EJBContext
Mark the current transaction for rollback. The transaction will become permanently marked for rollback. A transaction marked for rollback can never commit. Only enterprise beans with container-managed transactions are allowed to use this method.

Specified by:
setRollbackOnly in interface EJBContext

getUserTransaction

public UserTransaction getUserTransaction()
Description copied from interface: EJBContext
Obtain the transaction demarcation interface. Only enterprise beans with bean-managed transactions are allowed to to use the UserTransaction interface. As entity beans must always use container-managed transactions, only session beans with bean-managed transactions are allowed to invoke this method.

Specified by:
getUserTransaction in interface EJBContext
Returns:
The UserTransaction interface that the enterprise bean instance can use for transaction demarcation.

getCallerIdentity

public Identity getCallerIdentity()
Description copied from interface: EJBContext
Obtain the java.security.Identity of the caller. This method is deprecated in EJB 1.1. The Container is allowed to return alway null from this method. The enterprise bean should use the getCallerPrincipal method instead.

Specified by:
getCallerIdentity in interface EJBContext
Returns:
The Identity object that identifies the caller.

getCallerPrincipal

public Principal getCallerPrincipal()
Description copied from interface: EJBContext
Obtain the java.security.Principal that identifies the caller.

Specified by:
getCallerPrincipal in interface EJBContext
Returns:
The Principal object that identifies the caller. This method never returns null.

isCallerInRole

public boolean isCallerInRole(Identity role)
Description copied from interface: EJBContext
Test if the caller has a given role.

This method is deprecated in EJB 1.1. The enterprise bean should use the isCallerInRole(String roleName) method instead.

Specified by:
isCallerInRole in interface EJBContext
Parameters:
role - The java.security.Identity of the role to be tested.
Returns:
True if the caller has the specified role.

isCallerInRole

public boolean isCallerInRole(String roleName)
Description copied from interface: EJBContext
Test if the caller has a given security role.

Specified by:
isCallerInRole in interface EJBContext
Parameters:
roleName - The name of the security role. The role must be one of the security roles that is defined in the deployment descriptor.
Returns:
True if the caller has the specified role.