CompositeELResolver (Java EE 5)

Java EE API


javax.el Class CompositeELResolver

java.lang.Object
  extended by javax.el.ELResolver
      extended by javax.el.CompositeELResolver

public class CompositeELResolver
extends ELResolver

Extends: ELResolver

维护一个按顺序排列的子 ELResolver 的复合列表。

尽管只有一个 ELResolverELContext 关联,但对于任何给定的变量或属性解析,通常可以使用多个解析器。ELResolver 使用 CompositeELResolver 连接到一起,以定义丰富语义来计算表达式。

对于 #getValue#getType#setValue#isReadOnly 方法,ELResolver 不负责解析所有可能的 (base, property) 对。实际上,大部分解析器将仅能处理一种类型的 base。要指示解析器能够成功的解析特定 (base, property) 对,它必须将 ELContextpropertyResolved 属性设置为 true。如果它无法处理给定对,则必须保持此属性不变。如果 propertyResolvedfalse,则调用者必须忽略该方法的返回值。

CompositeELResolverELContext.propertyResolved 标志初始化为 false,并将其用作迭代其解析器组件的一个停止条件。

设计时方法 #getFeatureDescriptors#getCommonPropertyType 不使用 ELContext.propertyResolved 标志。而是从所有子 ELResolver 中进行收集和组合形成这些方法的结果。

英文文档:

Maintains an ordered composite list of child ELResolvers.

Though only a single ELResolver is associated with an ELContext, there are usually multiple resolvers considered for any given variable or property resolution. ELResolvers are combined together using a CompositeELResolver, to define rich semantics for evaluating an expression.

For the getValue(javax.el.ELContext, java.lang.Object, java.lang.Object), getType(javax.el.ELContext, java.lang.Object, java.lang.Object), setValue(javax.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object) and isReadOnly(javax.el.ELContext, java.lang.Object, java.lang.Object) methods, an ELResolver is not responsible for resolving all possible (base, property) pairs. In fact, most resolvers will only handle a base of a single type. To indicate that a resolver has successfully resolved a particular (base, property) pair, it must set the propertyResolved property of the ELContext to true. If it could not handle the given pair, it must leave this property alone. The caller must ignore the return value of the method if propertyResolved is false.

The CompositeELResolver initializes the ELContext.propertyResolved flag to false, and uses it as a stop condition for iterating through its component resolvers.

The ELContext.propertyResolved flag is not used for the design-time methods getFeatureDescriptors(javax.el.ELContext, java.lang.Object) and getCommonPropertyType(javax.el.ELContext, java.lang.Object). Instead, results are collected and combined from all child ELResolvers for these methods.

Since:
JSP 2.1
See Also:
ELContext, ELResolver

Field Summary
 
Fields inherited from class javax.el.ELResolver
 
Constructor Summary
 
Method Summary
 void
 Class<?>
 Iterator<FeatureDescriptor>
 Class<?>
 Object
 boolean
 void
 
Methods inherited from class java.lang.Object
 

Constructor Detail

public CompositeELResolver()
英文文档:

CompositeELResolver

public CompositeELResolver()
Method Detail

public void add(ELResolver elResolver)
将给定的解析器添加到解析器组件列表中。

将按添加的顺序参考解析器。

elResolver 要添加的解析器组件。
ThrowsNullPointerException: 如果提供的解析器为 null
英文文档:

add

public void add(ELResolver elResolver)
Adds the given resolver to the list of component resolvers.

Resolvers are consulted in the order in which they are added.

Parameters:
elResolver - The component resolver to add.
Throws:
NullPointerException - If the provided resolver is null.

public Object getValue(ELContext context, Object base, Object property)
尝试通过查询所有解析器组件解析给定 base 对象上的给定 property 对象。

如果此解析器处理给定的 (base, property) 对,则在返回前,ELContext 对象的 propertyResolved 属性必须设置为 true。如果调用此方法后此属性不为 true,则调用者应该忽略返回值。

首先,在提供的 ELContext 上将 propertyResolved 设置为 false

接下来,对于此组合中的每个解析器组件:

  1. 调用 getValue() 方法,传入提供的 contextbaseproperty
  2. 如果 ELContextpropertyResolved 标志为 false,则继续迭代。
  3. 否则,迭代将停止,并不再考虑其他解析器组件。此方法返回 getValue() 返回的值。

如果没有一个解析器组件能够执行此操作,则返回值 null,并且 propertyResolved 标志仍然设置为 false

迭代期间解析器组件抛出的任何异常都将传播到此方法的调用者。

context 此计算的上下文。
base 将返回属性值的 base 对象;或者为 null,表示解析顶级变量。
property 要解析的属性或变量。
return 如果 ELContextpropertyResolved 属性设置为 true,则返回变量或属性解析的结果;其他情况未定义。
ThrowsNullPointerException: 如果 context 为 null
ThrowsPropertyNotFoundException: 如果此 ELResolver 处理了给定的 (base, property) 对,但指定变量或属性不存在或不可读。
ThrowsELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。
英文文档:

getValue

public Object getValue(ELContext context,
                       Object base,
                       Object property)
Attempts to resolve the given property object on the given base object by querying all component resolvers.

If this resolver handles the given (base, property) pair, the propertyResolved property of the ELContext object must be set to true by the resolver, before returning. If this property is not true after this method is called, the caller should ignore the return value.

First, propertyResolved is set to false on the provided ELContext.

Next, for each component resolver in this composite:

  1. The getValue() method is called, passing in the provided context, base and property.
  2. If the ELContext's propertyResolved flag is false then iteration continues.
  3. Otherwise, iteration stops and no more component resolvers are considered. The value returned by getValue() is returned by this method.

If none of the component resolvers were able to perform this operation, the value null is returned and the propertyResolved flag remains set to false

.

Any exception thrown by component resolvers during the iteration is propagated to the caller of this method.

Specified by:
getValue in class ELResolver
Parameters:
context - The context of this evaluation.
base - The base object whose property value is to be returned, or null to resolve a top-level variable.
property - The property or variable to be resolved.
Returns:
If the propertyResolved property of ELContext was set to true, then the result of the variable or property resolution; otherwise undefined.
Throws:
NullPointerException - if context is null
PropertyNotFoundException - if the given (base, property) pair is handled by this ELResolver but the specified variable or property does not exist or is not readable.
ELException - if an exception was thrown while performing the property or variable resolution. The thrown exception must be included as the cause property of this exception, if available.

public Class<T> getType(ELContext context, Object base, Object property)
对于给定的 baseproperty,尝试标识最一般的对象类型,该类型对于将来调用 #setValue 方法时作为 value 参数传递的对象而言是可接受的。将通过查询所有解析器组件获取结果。

如果此解析器处理给定的 (base, property) 对,则在返回前,ELContext 对象的 propertyResolved 属性必须设置为 true。如果调用此方法后此属性不为 true,则调用者应该忽略返回值。

首先,在提供的 ELContext 上将 propertyResolved 设置为 false

接下来,对于此组合中的每个组件解析器:

  1. 调用 getType() 方法,传入提供的 contextbaseproperty
  2. 如果 ELContextpropertyResolved 标志为 false,则继续迭代。
  3. 否则,迭代将停止,并不再考虑其他解析器组件。此方法返回 getType() 返回的值。

如果没有一个解析器组件能够执行此操作,则返回值 null,并且 propertyResolved 标志仍然设置为 false

迭代期间解析器组件抛出的任何异常都将传播到此方法的调用者。

context 此计算的上下文。
base 将分析属性值的 base 对象;或者为 null,表示分析顶级变量。
property 要返回可接受类型的属性或变量。
return 如果 ELContextpropertyResolved 属性设置为 true,则返回最一般的可接受类型;其他情况未定义。
ThrowsNullPointerException: 如果 context 为 null
ThrowsPropertyNotFoundException: 如果此 ELResolver 处理了给定的 (base, property) 对,但指定变量或属性不存在或不可读。
ThrowsELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。
英文文档:

getType

public Class<?> getType(ELContext context,
                        Object base,
                        Object property)
For a given base and property, attempts to identify the most general type that is acceptable for an object to be passed as the value parameter in a future call to the setValue(javax.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object) method. The result is obtained by querying all component resolvers.

If this resolver handles the given (base, property) pair, the propertyResolved property of the ELContext object must be set to true by the resolver, before returning. If this property is not true after this method is called, the caller should ignore the return value.

First, propertyResolved is set to false on the provided ELContext.

Next, for each component resolver in this composite:

  1. The getType() method is called, passing in the provided context, base and property.
  2. If the ELContext's propertyResolved flag is false then iteration continues.
  3. Otherwise, iteration stops and no more component resolvers are considered. The value returned by getType() is returned by this method.

If none of the component resolvers were able to perform this operation, the value null is returned and the propertyResolved flag remains set to false

.

Any exception thrown by component resolvers during the iteration is propagated to the caller of this method.

Specified by:
getType in class ELResolver
Parameters:
context - The context of this evaluation.
base - The base object whose property value is to be analyzed, or null to analyze a top-level variable.
property - The property or variable to return the acceptable type for.
Returns:
If the propertyResolved property of ELContext was set to true, then the most general acceptable type; otherwise undefined.
Throws:
NullPointerException - if context is null
PropertyNotFoundException - if the given (base, property) pair is handled by this ELResolver but the specified variable or property does not exist or is not readable.
ELException - if an exception was thrown while performing the property or variable resolution. The thrown exception must be included as the cause property of this exception, if available.

public void setValue(ELContext context, Object base, Object property, Object val)
尝试在给定的 base 对象上设置给定的 property 对象的值。要求所有解析器组件尝试设置此值。

如果此解析器处理给定的 (base, property) 对,则在返回前,ELContext 对象的 propertyResolved 属性必须设置为 true。如果调用此方法后此属性不为 true,则调用者可以放心地假定没有设置任何值。

首先,在提供的 ELContext 上将 propertyResolved 设置为 false

接下来,对于此组合中的每个解析器组件:

  1. 调用 setValue() 方法,传入提供的 contextbasepropertyvalue
  2. 如果 ELContextpropertyResolved 标志为 false,则继续迭代。
  3. 否则,迭代将停止,并不再考虑其他解析器组件。

如果没有一个解析器组件能够执行此操作,则 propertyResolved 标志仍然设置为 false

迭代期间解析器组件抛出的任何异常都将传播到此方法的调用者。

context 此计算的上下文。
base 将设置属性值的 base 对象;或者为 null,表示设置顶级变量。
property 要设置的属性或变量。
val 用于设置属性或变量的值。
ThrowsNullPointerException: 如果 context 为 null
ThrowsPropertyNotFoundException: 如果此 ELResolver 处理了给定的 (base, property) 对,但指定变量或属性不存在。
ThrowsPropertyNotWritableException: 如果此 ELResolver 处理了给定的 (base, property) 对,但指定的变量或属性不可写。
ThrowsELException: 如果尝试设置属性或变量时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。
英文文档:

setValue

public void setValue(ELContext context,
                     Object base,
                     Object property,
                     Object val)
Attempts to set the value of the given property object on the given base object. All component resolvers are asked to attempt to set the value.

If this resolver handles the given (base, property) pair, the propertyResolved property of the ELContext object must be set to true by the resolver, before returning. If this property is not true after this method is called, the caller can safely assume no value has been set.

First, propertyResolved is set to false on the provided ELContext.

Next, for each component resolver in this composite:

  1. The setValue() method is called, passing in the provided context, base, property and value.
  2. If the ELContext's propertyResolved flag is false then iteration continues.
  3. Otherwise, iteration stops and no more component resolvers are considered.

If none of the component resolvers were able to perform this operation, the propertyResolved flag remains set to false

.

Any exception thrown by component resolvers during the iteration is propagated to the caller of this method.

Specified by:
setValue in class ELResolver
Parameters:
context - The context of this evaluation.
base - The base object whose property value is to be set, or null to set a top-level variable.
property - The property or variable to be set.
val - The value to set the property or variable to.
Throws:
NullPointerException - if context is null
PropertyNotFoundException - if the given (base, property) pair is handled by this ELResolver but the specified variable or property does not exist.
PropertyNotWritableException - if the given (base, property) pair is handled by this ELResolver but the specified variable or property is not writable.
ELException - if an exception was thrown while attempting to set the property or variable. The thrown exception must be included as the cause property of this exception, if available.

public boolean isReadOnly(ELContext context, Object base, Object property)
对于给定的 baseproperty,尝试确定调用 #setValue 是否将总是失败。将通过查询所有解析器组件获取结果。

如果此解析器处理给定的 (base, property) 对,则在返回前,ELContext 对象的 propertyResolved 属性必须设置为 true。如果调用此方法后此属性不为 true,则调用者应该忽略返回值。

首先,在提供的 ELContext 上将 propertyResolved 设置为 false

接下来,对于此组合中的每个解析器组件:

  1. 调用 isReadOnly() 方法,传入提供的 contextbaseproperty
  2. 如果 ELContextpropertyResolved 标志为 false,则继续迭代。
  3. 否则,迭代将停止,并不再考虑其他解析器组件。此方法返回 isReadOnly() 返回的值。

如果没有一个解析器组件能够执行此操作,则返回值 false,并且 propertyResolved 标志仍然设置为 false

迭代期间解析器组件抛出的任何异常都将传播到此方法的调用者。

context 此计算的上下文。
base 将分析属性值的 base 对象;或者为 null,表示分析顶级变量。
property 要返回只读状态的属性或变量。
return 如果 ELContextpropertyResolved 属性被设置为 true,则在属性为只读的情况下返回 true,在非只读的情况下返回 false;其他情况未定义。
ThrowsNullPointerException: 如果 context 为 null
ThrowsPropertyNotFoundException: 如果此 ELResolver 处理了给定的 (base, property) 对,但指定变量或属性不存在。
ThrowsELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。
英文文档:

isReadOnly

public boolean isReadOnly(ELContext context,
                          Object base,
                          Object property)
For a given base and property, attempts to determine whether a call to setValue(javax.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object) will always fail. The result is obtained by querying all component resolvers.

If this resolver handles the given (base, property) pair, the propertyResolved property of the ELContext object must be set to true by the resolver, before returning. If this property is not true after this method is called, the caller should ignore the return value.

First, propertyResolved is set to false on the provided ELContext.

Next, for each component resolver in this composite:

  1. The isReadOnly() method is called, passing in the provided context, base and property.
  2. If the ELContext's propertyResolved flag is false then iteration continues.
  3. Otherwise, iteration stops and no more component resolvers are considered. The value returned by isReadOnly() is returned by this method.

If none of the component resolvers were able to perform this operation, the value false is returned and the propertyResolved flag remains set to false

.

Any exception thrown by component resolvers during the iteration is propagated to the caller of this method.

Specified by:
isReadOnly in class ELResolver
Parameters:
context - The context of this evaluation.
base - The base object whose property value is to be analyzed, or null to analyze a top-level variable.
property - The property or variable to return the read-only status for.
Returns:
If the propertyResolved property of ELContext was set to true, then true if the property is read-only or false if not; otherwise undefined.
Throws:
NullPointerException - if context is null
PropertyNotFoundException - if the given (base, property) pair is handled by this ELResolver but the specified variable or property does not exist.
ELException - if an exception was thrown while performing the property or variable resolution. The thrown exception must be included as the cause property of this exception, if available.

public java.util.Iterator<E> getFeatureDescriptors(ELContext context, Object base)
返回可以为给定 base 对象解析的变量或属性集的有关信息。此方法可以用于自动完成的辅助工具。结果将从所有解析器组件搜集得来。

ELContextpropertyResolved 属性与此方法无关。所有 ELResolver 的结果都连在一起。

返回的 Iterator 是一个迭代器,它对每个解析器组件的 getFeatureDescriptors 方法所返回迭代器返回的 FeatureDescriptor 对象 Collection 进行迭代。如果解析器返回 null,则跳过。

context 此计算的上下文。
base 要枚举有效属性集合的 base 对象;或者为 null,表示枚举此解析器可以计算的顶级变量集合。
return 包含 0 个或多个(可能无限多个)FeatureDescriptor 对象的 Iterator;如果此解析器不处理给定的 base 对象,或者结果太复杂而无法用此方法表示,则返回 null
英文文档:

getFeatureDescriptors

public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
                                                         Object base)
Returns information about the set of variables or properties that can be resolved for the given base object. One use for this method is to assist tools in auto-completion. The results are collected from all component resolvers.

The propertyResolved property of the ELContext is not relevant to this method. The results of all ELResolvers are concatenated.

The Iterator returned is an iterator over the collection of FeatureDescriptor objects returned by the iterators returned by each component resolver's getFeatureDescriptors method. If null is returned by a resolver, it is skipped.

Specified by:
getFeatureDescriptors in class ELResolver
Parameters:
context - The context of this evaluation.
base - The base object whose set of valid properties is to be enumerated, or null to enumerate the set of top-level variables that this resolver can evaluate.
Returns:
An Iterator containing zero or more (possibly infinitely more) FeatureDescriptor objects, or null if this resolver does not handle the given base object or that the results are too complex to represent with this method
See Also:
FeatureDescriptor

public Class<T> getCommonPropertyType(ELContext context, Object base)
在给定 base 对象的情况下,返回对于 property 参数此解析器可以接受的最一般类型。此方法可以用于自动完成的辅助工具。将通过查询所有解析器组件获取结果。

返回的 Class 是最具体的类,它是每个解析器组件的 getCommonPropertyType 方法所返回的所有类中的一个常见超类。如果解析器返回 null,则跳过。

context 此计算的上下文。
base 要返回最一般属性类型的 base 对象;或者为 null,表示枚举此解析器可以计算的顶级变量集合。
return 如果此 ELResolver 不了解如何处理给定的 base 对象,则返回 null;否则,如果接受任何 property 类型,则返回 Object.class;其他情况下,返回给定 base 可接受的最一般的 property 类型。
英文文档:

getCommonPropertyType

public Class<?> getCommonPropertyType(ELContext context,
                                      Object base)
Returns the most general type that this resolver accepts for the property argument, given a base object. One use for this method is to assist tools in auto-completion. The result is obtained by querying all component resolvers.

The Class returned is the most specific class that is a common superclass of all the classes returned by each component resolver's getCommonPropertyType method. If null is returned by a resolver, it is skipped.

Specified by:
getCommonPropertyType in class ELResolver
Parameters:
context - The context of this evaluation.
base - The base object to return the most general property type for, or null to enumerate the set of top-level variables that this resolver can evaluate.
Returns:
null if this ELResolver does not know how to handle the given base object; otherwise Object.class if any type of property is accepted; otherwise the most general property type accepted for the given base.


Submit a bug or feature

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

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

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