ELContext (Java EE 5)

Java EE API


javax.el Class ELContext

java.lang.Object
  extended by javax.el.ELContext

public abstract class ELContext
extends Object


表达式求值的上下文信息。

若要求一个 Expression 的值,必须提供一个 ELContextELContext 包含:

  • 对 base ELResolver 的引用,将参考该 base 来解析模型对象及其属性
  • FunctionMapper 的引用,它将用来解析 EL 函数。
  • VariableMapper 的引用,它将用来解析 EL 变量。
  • ELResolver 使用的所有相关上下文对象所组成的 Collection
  • 表达式求值期间的状态信息,如属性是否已被解析

上下文对象 Collection 是必需的,因为每个 ELResolver 可能需要访问不同的上下文对象。例如,JSP 和 Faces 解析器分别需要访问 javax.servlet.jsp.JspContextjavax.faces.context.FacesContext

通过底层技术可以控制 ELContext 对象的创建。例如,在 JSP 中,使用 JspContext.getELContext() 工厂方法。某些技术提供添加 ELContextListener 的功能,以便应用程序和框架可以确保其自己的上下文对象连接到任何新建的 ELContext

由于它存储表达式求值期间的状态,因此 ELContext 对象不是线程安全的对象。请注意,不要在两个或多个线程之间共享 ELContext 实例。

英文文档:

Context information for expression evaluation.

To evaluate an Expression, an ELContext must be provided. The ELContext holds:

  • a reference to the base ELResolver that will be consulted to resolve model objects and their properties
  • a reference to FunctionMapper that will be used to resolve EL Functions.
  • a reference to VariableMapper that will be used to resolve EL Variables.
  • a collection of all the relevant context objects for use by ELResolvers
  • state information during the evaluation of an expression, such as whether a property has been resolved yet

The collection of context objects is necessary because each ELResolver may need access to a different context object. For example, JSP and Faces resolvers need access to a JspContext and a FacesContext, respectively.

Creation of ELContext objects is controlled through the underlying technology. For example, in JSP the JspContext.getELContext() factory method is used. Some technologies provide the ability to add an ELContextListener so that applications and frameworks can ensure their own context objects are attached to any newly created ELContext.

Because it stores state during expression evaluation, an ELContext object is not thread-safe. Care should be taken to never share an ELContext instance between two or more threads.

Since:
JSP 2.1
See Also:
ELContextListener, ELContextEvent, ELResolver, FunctionMapper, VariableMapper, JspContext

Constructor Summary
 
Method Summary
 Object
abstract  ELResolver
abstract  FunctionMapper
 Locale
abstract  VariableMapper
 boolean
 void
 void
 void
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public ELContext()
英文文档:

ELContext

public ELContext()
Method Detail

public void setPropertyResolved(boolean resolved)
调用此方法指示 ELResolver 已成功解析了给定的 (base, property) 对。

CompositeELResolver 检查此属性,以确定是考虑还是跳过其他解析器组件。

resolved 如果该属性已被解析,则返回 true;否则返回 false。
See also javax.el.CompositeELResolver
英文文档:

setPropertyResolved

public void setPropertyResolved(boolean resolved)
Called to indicate that a ELResolver has successfully resolved a given (base, property) pair.

The CompositeELResolver checks this property to determine whether it should consider or skip other component resolvers.

Parameters:
resolved - true if the property has been resolved, or false if not.
See Also:
CompositeELResolver

public boolean isPropertyResolved()
返回 ELResolver 是否已成功解析了给定的 (base, property) 对。

CompositeELResolver 检查此属性,以确定是考虑还是跳过其他解析器组件。

return 如果该属性已被解析,则返回 true;否则返回 false。
See also javax.el.CompositeELResolver
英文文档:

isPropertyResolved

public boolean isPropertyResolved()
Returns whether an ELResolver has successfully resolved a given (base, property) pair.

The CompositeELResolver checks this property to determine whether it should consider or skip other component resolvers.

Returns:
true if the property has been resolved, or false if not.
See Also:
CompositeELResolver

public void putContext(Class<T> key, Object contextObject)
将上下文对象与此 ELContext 关联。

ELContext 维护与表达式计算相关的上下文对象的 Collection。这些上下文对象由 ELResolver 使用。使用此方法向该 Collection 中添加上下文对象。

按照惯例,contextObject 将为 key 指定的类型。但是,并不要求这样做,键将被严格地用作唯一标识符。

key ELResolver 用来标识此上下文对象的键。
contextObject 要添加到 Collection 的上下文对象。
ThrowsNullPointerException: 如果 key 为 null 或者 contextObject 为 null。
英文文档:

putContext

public void putContext(Class key,
                       Object contextObject)
Associates a context object with this ELContext.

The ELContext maintains a collection of context objects relevant to the evaluation of an expression. These context objects are used by ELResolvers. This method is used to add a context object to that collection.

By convention, the contextObject will be of the type specified by the key. However, this is not required and the key is used strictly as a unique identifier.

Parameters:
key - The key used by an @{link ELResolver} to identify this context object.
contextObject - The context object to add to the collection.
Throws:
NullPointerException - if key is null or contextObject is null.

public Object getContext(Class<T> key)
返回与给定键关联的上下文对象。

ELContext 维护与表达式计算相关的上下文对象的 Collection。这些上下文对象由 ELResolver 使用。使用此方法从 Collection 中获取具有给定键的上下文。

按照惯例,返回的对象将为 key 指定的类型。但是,并不要求这样做,键将被严格地用作唯一标识符。

key 用于将上下文对象与此 ELContext 关联的唯一标识符。
return 返回与给定键关联的上下文对象;如果没有找到这样的上下文,则返回 null。
ThrowsNullPointerException: 如果 key 为 null。
英文文档:

getContext

public Object getContext(Class key)
Returns the context object associated with the given key.

The ELContext maintains a collection of context objects relevant to the evaluation of an expression. These context objects are used by ELResolvers. This method is used to retrieve the context with the given key from the collection.

By convention, the object returned will be of the type specified by the key. However, this is not required and the key is used strictly as a unique identifier.

Parameters:
key - The unique identifier that was used to associate the context object with this ELContext.
Returns:
The context object associated with the given key, or null if no such context was found.
Throws:
NullPointerException - if key is null.

abstract public ELResolver getELResolver()
获取与此上下文关联的 ELResolver

ELContext 维护对 ELResolver 的引用,在表达式求值期间将参考 ELResolver 来解析变量和属性。此方法获取对解析器的引用。

构建了 ELContext 之后,将无法更改对与上下文关联的 ELResolver 的引用。

return 表达式求值期间解析变量和属性时要参考的解析器。
英文文档:

getELResolver

public abstract ELResolver getELResolver()
Retrieves the ELResolver associated with this context.

The ELContext maintains a reference to the ELResolver that will be consulted to resolve variables and properties during an expression evaluation. This method retrieves the reference to the resolver.

Once an ELContext is constructed, the reference to the ELResolver associated with the context cannot be changed.

Returns:
The resolver to be consulted for variable and property resolution during expression evaluation.

abstract public FunctionMapper getFunctionMapper()
获取与此 ELContext 关联的 FunctionMapper
return 解析 EL 函数时要参考的函数映射器。
英文文档:

getFunctionMapper

public abstract FunctionMapper getFunctionMapper()
Retrieves the FunctionMapper associated with this ELContext.

Returns:
The function mapper to be consulted for the resolution of EL functions.

public java.util.Locale getLocale()
获取以前调用 #setLocale 存储的 Locale。如果此方法返回非 null 值,则实现中所需的所有本地化都必须使用此 Locale。因为考虑到会动态更改 Locale 的应用程序,Locale 不得缓存。
return 运行此实例的 Locale。主要用于消息本地化。
英文文档:

getLocale

public Locale getLocale()
Get the Locale stored by a previous invocation to setLocale(java.util.Locale). If this method returns non null, this Locale must be used for all localization needs in the implementation. The Locale must not be cached to allow for applications that change Locale dynamically.

Returns:
The Locale in which this instance is operating. Used primarily for message localization.

public void setLocale(java.util.Locale locale)
设置此实例的 Locale。创建实例(如 JavaServer Faces 或 JSP)的一方可以调用该方法,使 EL 实现能够为用户提供已本地化的消息。如果未设置 Locale,则实现必须使用 Locale.getDefault( ) 所返回的语言环境。
英文文档:

setLocale

public void setLocale(Locale locale)
Set the Locale for this instance. This method may be called by the party creating the instance, such as JavaServer Faces or JSP, to enable the EL implementation to provide localized messages to the user. If no Locale is set, the implementation must use the locale returned by Locale.getDefault( ).


abstract public VariableMapper getVariableMapper()
获取与此 ELContext 关联的 VariableMapper
return 解析 EL 变量时要参考的变量映射器。
英文文档:

getVariableMapper

public abstract VariableMapper getVariableMapper()
Retrieves the VariableMapper associated with this ELContext.

Returns:
The variable mapper to be consulted for the resolution of EL variables.


Submit a bug or feature

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

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

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