Top Description Methods
javax.ejb

public Interface EJBContext

Known Direct Subinterfaces
javax.ejb.EntityContext, javax.ejb.MessageDrivenContext, javax.ejb.SessionContext
Imports
java.util.*, java.security.Identity, .Principal, javax.transaction.UserTransaction

The EJBContext interface provides an instance with access to the container-provided runtime context of an enterprise bean instance.

This interface is extended by the SessionContext, EntityContext, and MessageDrivenContext interfaces to provide additional methods specific to the enterprise interface bean type.

Since
EJB 1.0
See Also
SessionContext, MessageDrivenContext, EntityContext

Method Summary

Modifier and TypeMethod and Description
public Identity

Returns:

The Identity object that identifies the caller.
getCallerIdentity
()

Deprecated Use Principal getCallerPrincipal() instead.
Obtain the java.security.Identity of the caller.
public Principal

Returns:

The Principal object that identifies the caller. This method never returns null.
getCallerPrincipal
()

Obtain the java.security.Principal that identifies the caller.

public Map<String, Object>

Returns:

the context data that interceptor context associated with this invocation. If there is no context data, an empty Map<String,Object> object will be returned.
getContextData
()

The getContextData method enables a business method, lifecycle callback method, or timeout method to retrieve any interceptor/webservices context associated with its invocation.

public EJBHome

Returns:

The enterprise bean's remote home interface.
getEJBHome
()

Obtain the enterprise bean's remote home interface.

public EJBLocalHome

Returns:

The enterprise bean's local home interface.
getEJBLocalHome
()

Obtain the enterprise bean's local home interface.

public Properties

Returns:

The environment properties for the enterprise bean.
getEnvironment
()

Deprecated Use the JNDI naming context java:comp/env to access enterprise bean's environment.
Obtain the enterprise bean's environment properties.
public boolean

Returns:

True if the current transaction is marked for rollback, false otherwise.
getRollbackOnly
()

Test if the transaction has been marked for rollback only.

public TimerService
getTimerService()

Get access to the EJB Timer Service.

public UserTransaction

Returns:

The UserTransaction interface that the enterprise bean instance can use for transaction demarcation.
getUserTransaction
()

Obtain the transaction demarcation interface.

public boolean

Returns:

True if the caller has the specified role.
isCallerInRole
(Identity
The java.security.Identity of the role to be tested.
role
)

Deprecated Use boolean isCallerInRole(String roleName) instead.
Test if the caller has a given role.
public boolean

Returns:

True if the caller has the specified role.
isCallerInRole
(String
The name of the security role. The role must be one of the security roles that is defined in the deployment descriptor.
roleName
)

Test if the caller has a given security role.

public Object
lookup(String
Name of the entry
name
)

Lookup a resource within the java: namespace.

public void
setRollbackOnly()

Mark the current transaction for rollback.

Method Detail

getCallerIdentityback to summary
public 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 always null from this method. The enterprise bean should use the getCallerPrincipal method instead.

Returns:Identity

The Identity object that identifies the caller.

getCallerPrincipalback to summary
public Principal getCallerPrincipal() throws IllegalStateException

Obtain the java.security.Principal that identifies the caller.

Returns:Principal

The Principal object that identifies the caller. This method never returns null.

Exceptions
IllegalStateException:
The Container throws the exception if the instance is not allowed to call this method.
Since
EJB 1.1
getContextDataback to summary
public Map<String, Object> getContextData()

The getContextData method enables a business method, lifecycle callback method, or timeout method to retrieve any interceptor/webservices context associated with its invocation.

Returns:Map<String, Object>

the context data that interceptor context associated with this invocation. If there is no context data, an empty Map<String,Object> object will be returned.

Since
EJB 3.1
getEJBHomeback to summary
public EJBHome getEJBHome() throws IllegalStateException

Obtain the enterprise bean's remote home interface.

Returns:EJBHome

The enterprise bean's remote home interface.

Exceptions
IllegalStateException:
if the enterprise bean does not have a remote home interface.
getEJBLocalHomeback to summary
public EJBLocalHome getEJBLocalHome() throws IllegalStateException

Obtain the enterprise bean's local home interface.

Returns:EJBLocalHome

The enterprise bean's local home interface.

Exceptions
IllegalStateException:
if the enterprise bean does not have a local home interface.
Since
EJB 2.0
getEnvironmentback to summary
public 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.

Returns:Properties

The environment properties for the enterprise bean.

getRollbackOnlyback to summary
public boolean getRollbackOnly() throws 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.

Returns:boolean

True if the current transaction is marked for rollback, false otherwise.

Exceptions
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).
getTimerServiceback to summary
public TimerService getTimerService() throws IllegalStateException

Get access to the EJB Timer Service.

Exceptions
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)
Since
EJB 2.1
getUserTransactionback to summary
public UserTransaction getUserTransaction() throws 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 or message-driven beans with bean-managed transactions are allowed to invoke this method.

Returns:UserTransaction

The UserTransaction interface that the enterprise bean instance can use for transaction demarcation.

Exceptions
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).
isCallerInRoleback to summary
public boolean isCallerInRole(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.

Parameters
role:Identity

The java.security.Identity of the role to be tested.

Returns:boolean

True if the caller has the specified role.

isCallerInRoleback to summary
public boolean isCallerInRole(String roleName) throws IllegalStateException

Test if the caller has a given security role.

Parameters
roleName:String

The name of the security role. The role must be one of the security roles that is defined in the deployment descriptor.

Returns:boolean

True if the caller has the specified role.

Exceptions
IllegalStateException:
The Container throws the exception if the instance is not allowed to call this method.
Since
EJB 1.1
lookupback to summary
public Object lookup(String name) throws IllegalArgumentException

Lookup a resource within the java: namespace. Names referring to entries within the private component namespace can be passed as unqualified strings. In that case the lookup will be relative to "java:comp/env/". For example, assuming an enterprise bean defines an ejb-local-ref with ejb-ref-name "ejb/BarRef" the following two calls to EJBContext.lookup are equivalent : ejbContext.lookup("ejb/BarRef"); ejbContext.lookup("java:comp/env/ejb/BarRef");

Parameters
name:String

Name of the entry

Exceptions
IllegalArgumentException:
The Container throws the exception if the given name does not match an entry within the component's environment.
Since
EJB 3.0
setRollbackOnlyback to summary
public void setRollbackOnly() throws 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.

Exceptions
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).