ListELResolver (Java EE 5)

Java EE API


javax.el Class ListELResolver

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

public class ListELResolver
extends ELResolver

Extends: ELResolver

定义 java.util.List 实例上的属性解析行为。

此解析器处理类型为 java.util.List 的 base 对象。它接受任何对象作为属性,并且将该对象强制匹配为列表中的整数索引。所得值就是列表中位于该索引处的值。

此解析器可以以只读模式构建,这意味着 #isReadOnly 将总是返回 true#setValue 将总是抛出 PropertyNotWritableException

ELResolver 使用 CompositeELResolver 连接到一起,以定义丰富语义来计算表达式。有关 ELResolver 的详细信息,请参阅 javadoc。

英文文档:

Defines property resolution behavior on instances of List.

This resolver handles base objects of type java.util.List. It accepts any object as a property and coerces that object into an integer index into the list. The resulting value is the value in the list at that index.

This resolver can be constructed in read-only mode, which means that isReadOnly will always return true and setValue(javax.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object) will always throw PropertyNotWritableException.

ELResolvers are combined together using CompositeELResolvers, to define rich semantics for evaluating an expression. See the javadocs for ELResolver for details.

Since:
JSP 2.1
See Also:
CompositeELResolver, ELResolver, List

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

Constructor Detail

public ListELResolver()
创建新的读/写 ListELResolver
英文文档:

ListELResolver

public ListELResolver()
Creates a new read/write ListELResolver.


public ListELResolver(boolean isReadOnly)
创建新的 ListELResolver,其只读状态由给定的参数确定。
isReadOnly 如果该解析器无法修改列表,则为 true;否则为 false
英文文档:

ListELResolver

public ListELResolver(boolean isReadOnly)
Creates a new ListELResolver whose read-only status is determined by the given parameter.

Parameters:
isReadOnly - true if this resolver cannot modify lists; false otherwise.

Method Detail

public Class<T> getType(ELContext context, Object base, Object property)
如果 base 对象是列表,则返回此列表中的值可以接受的最一般类型。

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

假定 base 为 List,则此方法将总是返回 Object.class。这是因为 List 接受任何对象作为元素。

context 此计算的上下文。
base 要分析的列表。此解析器仅处理属于 List 类型的 base。
property 返回可接受类型的列表元素的索引。将强制匹配为整数,其他情况下将被此解析器忽略。
return 如果 ELContextpropertyResolved 属性设置为 true,则返回最一般的可接受类型;其他情况未定义。
ThrowsPropertyNotFoundException: 如果给定索引超出此列表的范围。
ThrowsNullPointerException: 如果 context 为 null
ThrowsELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。
英文文档:

getType

public Class<?> getType(ELContext context,
                        Object base,
                        Object property)
If the base object is a list, returns the most general acceptable type for a value in this list.

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

Assuming the base is a List, this method will always return Object.class. This is because Lists accept any object as an element.

Specified by:
getType in class ELResolver
Parameters:
context - The context of this evaluation.
base - The list to analyze. Only bases of type List are handled by this resolver.
property - The index of the element in the list to return the acceptable type for. Will be coerced into an integer, but otherwise ignored by this resolver.
Returns:
If the propertyResolved property of ELContext was set to true, then the most general acceptable type; otherwise undefined.
Throws:
PropertyNotFoundException - if the given index is out of bounds for this list.
NullPointerException - if context is null
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 Object getValue(ELContext context, Object base, Object property)
如果 base 对象为列表,则返回给定索引位置的值。property 参数指定的索引,强制匹配为整数。如果无法执行强制匹配,则抛出 IllegalArgumentException。如果索引超出边界,则返回 null

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

context 此计算的上下文。
base 要分析的列表。此解析器仅处理属于 List 类型的 base。
property 要返回的值的索引。将强制匹配为整数。
return 如果 ELContextpropertyResolved 属性设置为 true,则返回给定索引处的值;如果索引超出边界,则返回 null。其他情况未定义。
ThrowsIllegalArgumentException: 如果属性无法强制匹配为整数。
ThrowsNullPointerException: 如果 context 为 null
ThrowsELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。
英文文档:

getValue

public Object getValue(ELContext context,
                       Object base,
                       Object property)
If the base object is a list, returns the value at the given index. The index is specified by the property argument, and coerced into an integer. If the coercion could not be performed, an IllegalArgumentException is thrown. If the index is out of bounds, null is returned.

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

Specified by:
getValue in class ELResolver
Parameters:
context - The context of this evaluation.
base - The list to be analyzed. Only bases of type List are handled by this resolver.
property - The index of the value to be returned. Will be coerced into an integer.
Returns:
If the propertyResolved property of ELContext was set to true, then the value at the given index or null if the index was out of bounds. Otherwise, undefined.
Throws:
IllegalArgumentException - if the property could not be coerced into an integer.
NullPointerException - if context is null.
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 参数指定的索引,强制匹配为整数。如果无法执行强制匹配,则抛出 IllegalArgumentException。如果索引超出边界,则抛出 PropertyNotFoundException

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

如果此解析器以只读模式构造,则此方法将总是抛出 PropertyNotWritableException

如果使用 java.util.Collections#unmodifiableList 创建 List,则此方法必须抛出 PropertyNotWritableException。不幸的是,没有任何 Collection API 方法可以检测这一点。但是,实现可以使用以下方法解决该问题:创建原型不可修改的 List,并查询其运行时类型,以确定它是否匹配 base 对象的运行时类型。

context 此计算的上下文。
base 要修改的列表。此解析器仅处理属于 List 类型的 base。
property 要设置的值的索引。将强制匹配为整数。
val 要在给定索引处设置的值。
ThrowsClassCastException: 如果指定元素的类不允许该元素添加到此列表。
ThrowsNullPointerException: 如果上下文为 null,或者值为 null,并且此 List 不支持 null 元素。
ThrowsIllegalArgumentException: 如果属性无法强制匹配为整数,或者指定元素的某个方面不允许该元素添加到此列表。
ThrowsPropertyNotWritableException: 如果此解析器以只读模式构造,或者底层列表不支持设置操作。
ThrowsPropertyNotFoundException: 如果给定索引超出此列表的范围。
ThrowsELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。
英文文档:

setValue

public void setValue(ELContext context,
                     Object base,
                     Object property,
                     Object val)
If the base object is a list, attempts to set the value at the given index with the given value. The index is specified by the property argument, and coerced into an integer. If the coercion could not be performed, an IllegalArgumentException is thrown. If the index is out of bounds, a PropertyNotFoundException is thrown.

If the base is a List, the propertyResolved property of the ELContext object must be set to true by this resolver, before returning. If this property is not true after this method is called, the caller can safely assume no value was set.

If this resolver was constructed in read-only mode, this method will always throw PropertyNotWritableException.

If a List was created using Collections.unmodifiableList(java.util.List), this method must throw PropertyNotWritableException. Unfortunately, there is no Collections API method to detect this. However, an implementation can create a prototype unmodifiable List and query its runtime type to see if it matches the runtime type of the base object as a workaround.

Specified by:
setValue in class ELResolver
Parameters:
context - The context of this evaluation.
base - The list to be modified. Only bases of type List are handled by this resolver.
property - The index of the value to be set. Will be coerced into an integer.
val - The value to be set at the given index.
Throws:
ClassCastException - if the class of the specified element prevents it from being added to this list.
NullPointerException - if context is null, or if the value is null and this List does not support null elements.
IllegalArgumentException - if the property could not be coerced into an integer, or if some aspect of the specified element prevents it from being added to this list.
PropertyNotWritableException - if this resolver was constructed in read-only mode, or if the set operation is not supported by the underlying list.
PropertyNotFoundException - if the given index is out of bounds for this list.
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 boolean isReadOnly(ELContext context, Object base, Object property)
如果 base 对象是列表,则返回对 #setValue 的调用是否总是失败。

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

如果此解析器以只读模式构造,则此方法将总是返回 true

如果使用 java.util.Collections#unmodifiableList 创建 List,则此方法必须返回 true。不幸的是,没有任何 Collection API 方法可以检测这一点。但是,实现可以使用以下方法解决该问题:创建原型不可修改的 List,并查询其运行时类型,以确定它是否匹配 base 对象的运行时类型。

context 此计算的上下文。
base 要分析的列表。此解析器仅处理属于 List 类型的 base。
property 返回可接受类型的列表元素的索引。将强制匹配为整数,其他情况下将被此解析器忽略。
return 如果 ELContextpropertyResolved 属性设置为 true,则调用 setValue 方法总是失败的情况下返回 true,该调用可能成功的情况下返回 false;其他情况未定义。
ThrowsPropertyNotFoundException: 如果给定索引超出此列表的范围。
ThrowsNullPointerException: 如果 context 为 null
ThrowsELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。
英文文档:

isReadOnly

public boolean isReadOnly(ELContext context,
                          Object base,
                          Object property)
If the base object is a list, returns whether a call to setValue(javax.el.ELContext, java.lang.Object, java.lang.Object, java.lang.Object) will always fail.

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

If this resolver was constructed in read-only mode, this method will always return true.

If a List was created using Collections.unmodifiableList(java.util.List), this method must return true. Unfortunately, there is no Collections API method to detect this. However, an implementation can create a prototype unmodifiable List and query its runtime type to see if it matches the runtime type of the base object as a workaround.

Specified by:
isReadOnly in class ELResolver
Parameters:
context - The context of this evaluation.
base - The list to analyze. Only bases of type List are handled by this resolver.
property - The index of the element in the list to return the acceptable type for. Will be coerced into an integer, but otherwise ignored by this resolver.
Returns:
If the propertyResolved property of ELContext was set to true, then true if calling the setValue method will always fail or false if it is possible that such a call may succeed; otherwise undefined.
Throws:
PropertyNotFoundException - if the given index is out of bounds for this list.
NullPointerException - if context is null
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)
总是返回 null,因为没有理由迭代所有整数集。

#getCommonPropertyType 方法返回有关此解析器接受的属性的足够信息。

context 此计算的上下文。
base 列表。此解析器仅处理属于 List 类型的 base。
return null
英文文档:

getFeatureDescriptors

public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context,
                                                         Object base)
Always returns null, since there is no reason to iterate through set set of all integers.

The getCommonPropertyType(javax.el.ELContext, java.lang.Object) method returns sufficient information about what properties this resolver accepts.

Specified by:
getFeatureDescriptors in class ELResolver
Parameters:
context - The context of this evaluation.
base - The list. Only bases of type List are handled by this resolver.
Returns:
null.
See Also:
FeatureDescriptor

public Class<T> getCommonPropertyType(ELContext context, Object base)
如果 base 对象是列表,则返回对于 property 参数此解析器可接受的最一般类型。否则返回 null

假定 base 为 List,则此方法将总是返回 Integer.class。这是因为 List 接受整数作为其索引。

context 此计算的上下文。
base 要分析的列表。此解析器仅处理属于 List 类型的 base。
return 如果 base 不为 List,则返回 null;否则返回 Integer.class
英文文档:

getCommonPropertyType

public Class<?> getCommonPropertyType(ELContext context,
                                      Object base)
If the base object is a list, returns the most general type that this resolver accepts for the property argument. Otherwise, returns null.

Assuming the base is a List, this method will always return Integer.class. This is because Lists accept integers as their index.

Specified by:
getCommonPropertyType in class ELResolver
Parameters:
context - The context of this evaluation.
base - The list to analyze. Only bases of type List are handled by this resolver.
Returns:
null if base is not a List; otherwise Integer.class.


Submit a bug or feature

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

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

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