EJBContext (Java EE 5)

Java EE API


javax.ejb Interface EJBContext

All Known Subinterfaces:
EntityContext, MessageDrivenContext, SessionContext

public interface EJBContext


EJBContext 接口为实例提供对企业 Bean 实例的容器提供的运行时上下文的访问。

该接口通过 SessionContext、EntityContext 和 MessageDrivenContext 接口扩展,以提供其他特定于企业接口 Bean 类型的方法。

英文文档:

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.


Method Summary
 Identity
 Principal
 EJBHome
 EJBLocalHome
 Properties
 boolean
 TimerService
 UserTransaction
 boolean
 boolean
 Object
 void
 

Method Detail

public EJBHome getEJBHome()
获得企业 Bean 的远程 home 接口。
return 企业 Bean 的远程 home 接口。
ThrowsIllegalStateException: 如果企业 Bean 不具有远程 home 接口。
英文文档:

getEJBHome

EJBHome getEJBHome()
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.

public EJBLocalHome getEJBLocalHome()
获得企业 Bean 的本地 home 接口。
return 企业 Bean 的本地 home 接口。
ThrowsIllegalStateException: 如果企业 Bean 不具有本地 home 接口。
英文文档:

getEJBLocalHome

EJBLocalHome getEJBLocalHome()
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.

public java.util.Properties getEnvironment()
获得企业 Bean 的环境属性。

注:如果企业 Bean 没有环境属性,那么此方法返回空 java.util.Properties 对象。此方法从不返回 null。

return 企业 Bean 的环境属性。
deprecated 使用 JNDI 命名上下文 java:comp/env 访问企业 Bean 环境。

英文文档:

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 returns null.

Returns:
The environment properties for the enterprise bean.

public java.security.Identity getCallerIdentity()
获得调用者的 java.security.Identity。 此方法从 EJB 1.1 时起过时。Container 允许始终从此方法返回 null。企业 Bean 应改用 getCallerPrincipal 方法。
return 标识调用者的 Identity 对象。
deprecated 请改用 Principal getCallerPrincipal()。
英文文档:

getCallerIdentity

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.

Returns:
The Identity object that identifies the caller.

public java.security.Principal getCallerPrincipal()
获得标识调用者的 java.security.Principal。
return 标识调用者的 Principal 对象。此方法从不返回 null。
ThrowsIllegalStateException: 如果不允许实例调用此方法,则 Container 抛出该异常。
英文文档:

getCallerPrincipal

Principal getCallerPrincipal()
Obtain the java.security.Principal that identifies the caller.

Returns:
The Principal object that identifies the caller. This method never returns null.
Throws:
IllegalStateException - The Container throws the exception if the instance is not allowed to call this method.

public boolean isCallerInRole(java.security.Identity role)
测试调用者是否有给定角色。

此方法从 EJB 1.1 时起过时。企业 Bean 应改用 isCallerInRole(String roleName) 方法。

role 要测试的角色的 java.security.Identity。
return 如果调用者具有指定的角色,则返回 true。
deprecated 请改用 boolean isCallerInRole(String roleName)。

英文文档:

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 - The java.security.Identity of the role to be tested.
Returns:
True if the caller has the specified role.

public boolean isCallerInRole(String roleName)
测试调用者是否有给定安全角色。
roleName 安全角色的名称。角色必须是在部署描述符中定义的安全角色之一。
return 如果调用者具有指定的角色,则返回 true。
ThrowsIllegalStateException: 如果不允许实例调用此方法,则 Container 抛出该异常。
英文文档:

isCallerInRole

boolean isCallerInRole(String roleName)
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.

public UserTransaction getUserTransaction() throws IllegalStateException
获得事务划分接口。 仅允许带有 Bean 管理事务的企业 Bean 使用 UserTransaction 接口。因为实体 Bean 必须始终使用容器管理事务,所以仅允许带有 Bean 管理事务的会话 Bean 或消息驱动 Bean 调用此方法。
return 企业 Bean 实例用于事务划分的 UserTransaction 接口。
ThrowsIllegalStateException: 如果不允许实例使用 UserTransaction 接口(即实例为带有容器管理事务的 Bean),则 Container 抛出该异常。
英文文档:

getUserTransaction

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:
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 the UserTransaction interface (i.e. the instance is of a bean with container-managed transactions).

public void setRollbackOnly() throws IllegalStateException
将当前事务标记为回滚。事务将永久标记为回滚。标记为回滚的事务永远不能提交。 仅允许带有容器管理事务的企业 Bean 使用此方法。
ThrowsIllegalStateException: 如果不允许实例使用此方法(即实例为带有 Bean 管理事务的 Bean),则 Container 抛出该异常。
英文文档:

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

public boolean getRollbackOnly() throws IllegalStateException
测试事务是否仅被标记为回滚。企业 Bean 实例可以使用此操作,例如,测试在捕获异常后代表当前事务继续计算是否无效。 仅允许带有容器管理事务的企业 Bean 使用此方法。
return 如果当前事务被标记为回滚,则返回 true;否则返回 false。
ThrowsIllegalStateException: 如果不允许实例使用此方法(即实例为带有 Bean 管理事务的 Bean),则 Container 抛出该异常。
英文文档:

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

public TimerService getTimerService() throws IllegalStateException
获得对 EJB Timer Service 的访问。
ThrowsIllegalStateException: 如果不允许实例使用此方法(即如果该 Bean 是有状态会话 Bean),则 Container 抛出该异常。
英文文档:

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)

public Object lookup(String name)
在组件的专有命名上下文内查找资源。
name 条目名称(相对于 java:comp/env)。
ThrowsIllegalArgumentException: 如果给定名称与组件环境内的条目不匹配,则 Container 抛出该异常。
英文文档:

lookup

Object lookup(String name)
Lookup a resource within the component's private naming context.

Parameters:
name - Name of the entry (relative to java:comp/env).
Throws:
IllegalArgumentException - The Container throws the exception if the given name does not match an entry within the component's environment.


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!