-
- All Known Subinterfaces:
- EntityContext, MessageDrivenContext, SessionContext
public interface EJBContext
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
, andMessageDrivenContext
interfaces to provide additional methods specific to the enterprise interface bean type.- Since:
- EJB 1.0
- See Also:
SessionContext
,MessageDrivenContext
,EntityContext
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method and Description Identity
getCallerIdentity()
Deprecated.Use Principal getCallerPrincipal() instead.Principal
getCallerPrincipal()
Obtain thejava.security.Principal
that identifies the caller.Map<String,Object>
getContextData()
ThegetContextData
method enables a business method, lifecycle callback method, or timeout method to retrieve any interceptor/webservices context associated with its invocation.EJBHome
getEJBHome()
Obtain the enterprise bean's remote home interface.EJBLocalHome
getEJBLocalHome()
Obtain the enterprise bean's local home interface.Properties
getEnvironment()
Deprecated.Use the JNDI naming context java:comp/env to access enterprise bean's environment.boolean
getRollbackOnly()
Test if the transaction has been marked for rollback only.TimerService
getTimerService()
Get access to the EJB Timer Service.UserTransaction
getUserTransaction()
Obtain the transaction demarcation interface.boolean
isCallerInRole(Identity role)
Deprecated.Use boolean isCallerInRole(String roleName) instead.boolean
isCallerInRole(String roleName)
Test if the caller has a given security role.Object
lookup(String name)
Lookup a resource within thejava:
namespace.void
setRollbackOnly()
Mark the current transaction for rollback.
-
-
-
Method Detail
-
getEJBHome
EJBHome getEJBHome() throws IllegalStateException
Obtain the enterprise bean's remote home interface.- Returns:
- The enterprise bean's remote home interface.
- Throws:
IllegalStateException
- if the enterprise bean does not have a remote home interface.
-
getEJBLocalHome
EJBLocalHome getEJBLocalHome() throws IllegalStateException
Obtain the enterprise bean's local home interface.- Returns:
- The enterprise bean's local home interface.
- Throws:
IllegalStateException
- if the enterprise bean does not have a local home interface.- Since:
- EJB 2.0
-
getEnvironment
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 returnsnull
.- Returns:
- The environment properties for the enterprise bean.
-
getCallerIdentity
Identity getCallerIdentity()
Deprecated. Use Principal getCallerPrincipal() instead.Obtain thejava.security.Identity
of the caller. This method is deprecated in EJB 1.1. The Container is allowed to return alwaysnull
from this method. The enterprise bean should use thegetCallerPrincipal
method instead.- Returns:
- The
Identity
object that identifies the caller.
-
getCallerPrincipal
Principal getCallerPrincipal() throws IllegalStateException
Obtain thejava.security.Principal
that identifies the caller.- Returns:
- The
Principal
object that identifies the caller. This method never returnsnull
. - Throws:
IllegalStateException
- The Container throws the exception if the instance is not allowed to call this method.- Since:
- EJB 1.1
-
isCallerInRole
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
- Thejava.security.Identity
of the role to be tested.- Returns:
- True if the caller has the specified role.
-
isCallerInRole
boolean isCallerInRole(String roleName) throws IllegalStateException
Test if the caller has a given security role.- 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.
- Throws:
IllegalStateException
- The Container throws the exception if the instance is not allowed to call this method.- Since:
- EJB 1.1
-
getUserTransaction
UserTransaction getUserTransaction() throws IllegalStateException
Obtain the transaction demarcation interface. Only enterprise beans with bean-managed transactions are allowed to to use theUserTransaction
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:
- The
UserTransaction
interface that the enterprise bean instance can use for transaction demarcation. - Throws:
IllegalStateException
- The Container throws the exception if the instance is not allowed to use theUserTransaction
interface (i.e. the instance is of a bean with container-managed transactions).
-
setRollbackOnly
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.- Throws:
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
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:
- True if the current transaction is marked for rollback, false otherwise.
- Throws:
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
TimerService getTimerService() throws IllegalStateException
Get access to the EJB Timer Service.- Throws:
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
-
lookup
Object lookup(String name) throws IllegalArgumentException
Lookup a resource within thejava:
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 anejb-local-ref
withejb-ref-name
"ejb/BarRef"
the following two calls toEJBContext.lookup
are equivalent :ejbContext.lookup("ejb/BarRef")
;ejbContext.lookup("java:comp/env/ejb/BarRef")
;- Parameters:
name
- Name of the entry- Throws:
IllegalArgumentException
- The Container throws the exception if the given name does not match an entry within the component's environment.- Since:
- EJB 3.0
-
getContextData
Map<String,Object> getContextData()
ThegetContextData
method enables a business method, lifecycle callback method, or timeout method to retrieve any interceptor/webservices context associated with its invocation.- 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. - Since:
- EJB 3.1
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/08/2025 17:23:52 Cette version de la page est en cache (à la date du 21/08/2025 17:23:52) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 14/04/2008, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/ejb/EJBContext.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.