SessionContext (Java EE 5)

Java EE API


javax.ejb Interface SessionContext

All Superinterfaces:
EJBContext

public interface SessionContext
extends EJBContext

Implements: EJBContext

SessionContext 接口提供对容器为会话企业 Bean 实例提供的运行时会话上下文的访问。容器在实例创建后将 SessionContext 接口传递给实例。会话上下文在实例的生命周期内保持与实例关联。
英文文档:

The SessionContext interface provides access to the runtime session context that the container provides for a session enterprise Bean instance. The container passes the SessionContext interface to an instance after the instance has been created. The session context remains associated with the instance for the lifetime of the instance.


Method Summary
<T> T
getBusinessObject(Class<T> businessInterface)
          Obtain an object that can be used to invoke the current bean through the given business interface.  EJBLocalObject getEJBLocalObject()
          Obtain a reference to the EJB local object that is associated with the instance.  EJBObject getEJBObject()
          Obtain a reference to the EJB object that is currently associated with the instance.  Class getInvokedBusinessInterface()
          Obtain the business interface through which the current business method invocation was made.  MessageContext getMessageContext()
          Obtain a reference to the JAX-RPC MessageContext.  
Methods inherited from interface javax.ejb.EJBContext
 

Method Detail

public EJBLocalObject getEJBLocalObject() throws IllegalStateException
获得对与实例关联的 EJB 本地对象的引用。

会话企业 Bean 的实例可以在 ejbCreate() 和 ejbRemove() 方法之间(包括从 ejbCreate() 和 ejbRemove() 方法内)随时调用此方法。

例如,如果实例希望在方法参数或结果中传递对本身的引用时,它可以使用此方法。

return 当前与实例关联的 EJB 本地对象。
ThrowsIllegalStateException: 如果在实例不允许调用此方法的情况下,或者实例没有本地接口的情况下调用此方法,则抛出该异常。

英文文档:

getEJBLocalObject

EJBLocalObject getEJBLocalObject()
                                 throws 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.

Returns:
The EJB local object currently associated with the instance.
Throws:
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.

public EJBObject getEJBObject() throws IllegalStateException
获得对当前与实例关联的 EJB 对象的引用。

会话企业 Bean 的实例可以在 ejbCreate() 和 ejbRemove() 方法之间(包括从 ejbCreate() 和 ejbRemove() 方法内)随时调用此方法。

例如,如果实例希望在方法参数或结果中传递对本身的引用时,它可以使用此方法。

return 当前与实例关联的 EJB 对象。
ThrowsIllegalStateException: 如果在实例不允许调用此方法的情况下,或者实例没有远程接口的情况下调用此方法,则抛出该异常。

英文文档:

getEJBObject

EJBObject getEJBObject()
                       throws 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.

Returns:
The EJB object currently associated with the instance.
Throws:
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.

public MessageContext getMessageContext() throws IllegalStateException
获得对 JAX-RPC MessageContext 的引用。

无状态会话 Bean 的实例可以从任何通过其 Web 服务端点接口调用的业务方法中调用此方法。

return 此 Web 服务调用的 MessageContext。
ThrowsIllegalStateException: 如果在实例不允许访问此方法的情况下调用了此方法,则抛出此异常。

英文文档:

getMessageContext

MessageContext getMessageContext()
                                 throws 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.

Returns:
The MessageContext for this web service invocation.
Throws:
IllegalStateException - Thrown if this method is invoked while the instance is in a state that does not allow access to this method.

英文文档:

getBusinessObject

<T> T getBusinessObject(Class<T> businessInterface)
                    throws IllegalStateException
Obtain an object that can be used to invoke the current bean through the given business interface.

Parameters:
businessInterface - One of the local business interfaces or remote business interfaces for this session bean.
Returns:
The business object corresponding to the given business interface.
Throws:
IllegalStateException - Thrown if this method is invoked with an invalid business interface for the current bean.

public Class<T> getInvokedBusinessInterface() throws IllegalStateException
获得用于当前业务方法调用的业务接口。
ThrowsIllegalStateException: 如果调用此方法时还未通过业务接口调用 Bean,则抛出此异常。
英文文档:

getInvokedBusinessInterface

Class getInvokedBusinessInterface()
                                  throws IllegalStateException
Obtain the business interface through which the current business method invocation was made.

Throws:
IllegalStateException - Thrown if this method is called and the bean has not been invoked through a business interface.


Submit a bug or feature

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

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

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