org.objectweb.easybeans.container.session
Class EasyBeansSessionContext<BeanType extends EasyBeansSB>

java.lang.Object
  extended by org.objectweb.easybeans.container.session.EasyBeansSessionContext<BeanType>
Type Parameters:
BeanType - Could be a stateless or stateful.
All Implemented Interfaces:
EJBContext, javax.ejb.SessionContext

public class EasyBeansSessionContext<BeanType extends EasyBeansSB>
extends java.lang.Object
implements javax.ejb.SessionContext

Defines the Session Context used by Stateless and Stateful beans.

Author:
Florent Benoit

Nested Class Summary
(package private)  class EasyBeansSessionContext.DummyPrincipal
          Dummy class for handling Principal.
(package private)  class EasyBeansSessionContext.DummyTimerService
          Dummy class for handling Timer Service.
 
Field Summary
private  BeanType bean
          Reference to the bean.
private  javax.transaction.Transaction beanTransaction
          Transaction used by this bean.
private static java.lang.String JAVA_COMP_ENV
          java:comp/env prefix.
private  TransactionManagementType transactionManagementType
          Type of transaction.
private  javax.transaction.TransactionManager transactionManager
          Reference to the transaction manager.
 
Constructor Summary
EasyBeansSessionContext(BeanType bean)
          Build a new Session context.
 
Method Summary
 BeanType getBean()
          Gets the bean of this context.
 javax.transaction.Transaction getBeanTransaction()
          Gets the transaction used by this bean.
 java.security.Identity getCallerIdentity()
          Deprecated. 
 java.security.Principal getCallerPrincipal()
          Obtain the java.security.Principal that identifies the caller.
 javax.ejb.EJBHome getEJBHome()
          Obtain the enterprise bean's remote home interface.
 javax.ejb.EJBLocalHome getEJBLocalHome()
          Obtain the enterprise bean's local home interface.
 javax.ejb.EJBLocalObject getEJBLocalObject()
          Obtain a reference to the EJB local object that is associated with the instance.
 javax.ejb.EJBObject getEJBObject()
          Obtain a reference to the EJB object that is currently associated with the instance.
 java.util.Properties getEnvironment()
          Deprecated. 
 javax.xml.rpc.handler.MessageContext getMessageContext()
          Obtain a reference to the JAX-RPC MessageContext.
 boolean getRollbackOnly()
          Test if the transaction has been marked for rollback only.
 javax.ejb.TimerService getTimerService()
          Get access to the EJB Timer Service.
 javax.transaction.UserTransaction getUserTransaction()
          Obtain the transaction demarcation interface.
 boolean isCallerInRole(java.security.Identity role)
          Deprecated. 
 boolean isCallerInRole(java.lang.String roleName)
          Test if the caller has a given security role.
 java.lang.Object lookup(java.lang.String name)
          Lookup object with given name.
 void setBeanTransaction(javax.transaction.Transaction beanTransaction)
          Sets the transaction used by this bean.
 void setRollbackOnly()
          Mark the current transaction for rollback.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JAVA_COMP_ENV

private static final java.lang.String JAVA_COMP_ENV
java:comp/env prefix.

See Also:
Constant Field Values

bean

private BeanType extends EasyBeansSB bean
Reference to the bean.


transactionManager

private javax.transaction.TransactionManager transactionManager
Reference to the transaction manager.


transactionManagementType

private TransactionManagementType transactionManagementType
Type of transaction.


beanTransaction

private javax.transaction.Transaction beanTransaction
Transaction used by this bean. (Used by stateful bean).

Constructor Detail

EasyBeansSessionContext

public EasyBeansSessionContext(BeanType bean)
Build a new Session context.

Parameters:
bean - the bean on which we are linked.
Method Detail

getBeanTransaction

public javax.transaction.Transaction getBeanTransaction()
Gets the transaction used by this bean.

Returns:
the bean transaction.

setBeanTransaction

public void setBeanTransaction(javax.transaction.Transaction beanTransaction)
Sets the transaction used by this bean.

Parameters:
beanTransaction - the bean transaction.

getBean

public BeanType getBean()
Gets the bean of this context.

Returns:
bean used by this context.

getEJBLocalObject

public javax.ejb.EJBLocalObject getEJBLocalObject()
                                           throws java.lang.IllegalStateException
Obtain a reference to the EJB local object that is associated with the instance. An instance of a session enterprise Bean can call this method at anytime between the ejbCreate() and ejbRemove() methods, including from within the ejbCreate() and ejbRemove() 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 javax.ejb.SessionContext
Returns:
The EJB local object currently associated with the instance.
Throws:
java.lang.IllegalStateException - - Thrown if the instance invokes this method while the instance is in a state that does not allow the instance to invoke this method, or if the instance does not have a local interface.

getEJBObject

public javax.ejb.EJBObject getEJBObject()
                                 throws java.lang.IllegalStateException
Obtain a reference to the EJB object that is currently associated with the instance. An instance of a session enterprise Bean can call this method at anytime between the ejbCreate() and ejbRemove() methods, including from within the ejbCreate() and ejbRemove() 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 javax.ejb.SessionContext
Returns:
The EJB object currently associated with the instance.
Throws:
java.lang.IllegalStateException - - Thrown if the instance invokes this method while the instance is in a state that does not allow the instance to invoke this method, or if the instance does not have a remote interface.

getMessageContext

public javax.xml.rpc.handler.MessageContext getMessageContext()
                                                       throws java.lang.IllegalStateException
Obtain a reference to the JAX-RPC MessageContext. An instance of a stateless session bean can call this method from any business method invoked through its web service endpoint interface.

Specified by:
getMessageContext in interface javax.ejb.SessionContext
Returns:
The MessageContext for this web service invocation.
Throws:
java.lang.IllegalStateException - - Thrown if this method is invoked while the instance is in a state that does not allow access to this method.

getEJBHome

public javax.ejb.EJBHome getEJBHome()
                             throws java.lang.IllegalStateException
Obtain the enterprise bean's remote home interface.

Specified by:
getEJBHome in interface EJBContext
Returns:
The enterprise bean's remote home interface.
Throws:
java.lang.IllegalStateException - if the enterprise bean does not have a remote home interface.

getEJBLocalHome

public javax.ejb.EJBLocalHome getEJBLocalHome()
                                       throws java.lang.IllegalStateException
Obtain the enterprise bean's local home interface.

Specified by:
getEJBLocalHome in interface EJBContext
Returns:
The enterprise bean's local home interface.
Throws:
java.lang.IllegalStateException - - if the enterprise bean does not have a local home interface.

getEnvironment

@Deprecated
public java.util.Properties getEnvironment()
Deprecated. 

Use the JNDI naming context java:comp/env to access enterprise bean's environment. 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.

getCallerIdentity

@Deprecated
public java.security.Identity getCallerIdentity()
Deprecated. 

Use Principal getCallerPrincipal() instead. 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 java.security.Principal getCallerPrincipal()
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

@Deprecated
public boolean isCallerInRole(java.security.Identity role)
Deprecated. 

Use boolean isCallerInRole(String roleName) instead. 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(java.lang.String roleName)
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.

getUserTransaction

public javax.transaction.UserTransaction getUserTransaction()
                                                     throws java.lang.IllegalStateException
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.
Throws:
java.lang.IllegalStateException - - The Container throws the exception if the instance is not allowed to use the UserTransaction interface (i.e. the instance is of a bean with container-managed transactions).

setRollbackOnly

public void setRollbackOnly()
                     throws java.lang.IllegalStateException
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
Throws:
java.lang.IllegalStateException - - The Container throws the exception if the instance is not allowed to use this method (i.e. the instance is of a bean with bean-managed transactions).

getRollbackOnly

public boolean getRollbackOnly()
                        throws java.lang.IllegalStateException
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.
Throws:
java.lang.IllegalStateException - - The Container throws the exception if the instance is not allowed to use this method (i.e. the instance is of a bean with bean-managed transactions).

getTimerService

public javax.ejb.TimerService getTimerService()
                                       throws java.lang.IllegalStateException
Get access to the EJB Timer Service.

Specified by:
getTimerService in interface EJBContext
Returns:
Timer service.
Throws:
java.lang.IllegalStateException - The Container throws the exception if the instance is not allowed to use this method (e.g. if the bean is a stateful session bean)

toString

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

lookup

public java.lang.Object lookup(java.lang.String name)
Lookup object with given name.

Specified by:
lookup in interface EJBContext
Parameters:
name - given name
Returns:
result of the lookup