|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.el Class ListELResolver
java.lang.Object javax.el.ELResolver javax.el.ListELResolver
public class ListELResolver
- extends ELResolver
定义
java.util.List
实例上的属性解析行为。
此解析器处理类型为 java.util.List
的 base 对象。它接受任何对象作为属性,并且将该对象强制匹配为列表中的整数索引。所得值就是列表中位于该索引处的值。
此解析器可以以只读模式构建,这意味着 #isReadOnly
将总是返回 true
,#setValue
将总是抛出 PropertyNotWritableException
。
ELResolver
使用 CompositeELResolver
连接到一起,以定义丰富语义来计算表达式。有关 ELResolver
的详细信息,请参阅 javadoc。
since | JSP 2.1 |
See also | javax.el.CompositeELResolver, javax.el.ELResolver, java.util.List |
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
.
ELResolver
s are combined together using
CompositeELResolver
s, 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 |
---|
RESOLVABLE_AT_DESIGN_TIME, TYPE |
Constructor Summary | |
---|---|
ListELResolver()
Creates a new read/write ListELResolver . |
|
ListELResolver(boolean isReadOnly)
Creates a new ListELResolver whose read-only status is
determined by the given parameter. |
Method Summary | |
---|---|
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. |
Iterator<FeatureDescriptor> |
getFeatureDescriptors(ELContext context,
Object base)
Always returns null , since there is no reason to
iterate through set set of all integers. |
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. |
Object |
getValue(ELContext context,
Object base,
Object property)
If the base object is a list, returns the value at the given index. |
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. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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 |
如果 ELContext 的 propertyResolved 属性设置为 true ,则返回最一般的可接受类型;其他情况未定义。 |
Throws | PropertyNotFoundException: 如果给定索引超出此列表的范围。 |
Throws | NullPointerException:
如果 context 为 null |
Throws | ELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 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
, thepropertyResolved
property of theELContext
object must be set totrue
by this resolver, before returning. If this property is nottrue
after this method is called, the caller should ignore the return value.Assuming the base is a
List
, this method will always returnObject.class
. This is becauseList
s accept any object as an element. - Specified by:
getType
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- The list to analyze. Only bases of typeList
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 ofELContext
was set totrue
, then the most general acceptable type; otherwise undefined. - Throws:
PropertyNotFoundException
- if the given index is out of bounds for this list.NullPointerException
- if context isnull
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 |
如果 ELContext 的 propertyResolved 属性设置为 true ,则返回给定索引处的值;如果索引超出边界,则返回 null 。其他情况未定义。 |
Throws | IllegalArgumentException: 如果属性无法强制匹配为整数。 |
Throws | NullPointerException:
如果 context 为 null 。 |
Throws | ELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 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, anIllegalArgumentException
is thrown. If the index is out of bounds,null
is returned.If the base is a
List
, thepropertyResolved
property of theELContext
object must be set totrue
by this resolver, before returning. If this property is nottrue
after this method is called, the caller should ignore the return value. - Specified by:
getValue
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- The list to be analyzed. Only bases of typeList
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 ofELContext
was set totrue
, then the value at the given index ornull
if the index was out of bounds. Otherwise, undefined. - Throws:
IllegalArgumentException
- if the property could not be coerced into an integer.NullPointerException
- if context isnull
.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 | 要在给定索引处设置的值。 |
Throws | ClassCastException: 如果指定元素的类不允许该元素添加到此列表。 |
Throws | NullPointerException:
如果上下文为 null ,或者值为 null ,并且此 List 不支持 null 元素。 |
Throws | IllegalArgumentException: 如果属性无法强制匹配为整数,或者指定元素的某个方面不允许该元素添加到此列表。 |
Throws | PropertyNotWritableException: 如果此解析器以只读模式构造,或者底层列表不支持设置操作。 |
Throws | PropertyNotFoundException: 如果给定索引超出此列表的范围。 |
Throws | ELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 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, anIllegalArgumentException
is thrown. If the index is out of bounds, aPropertyNotFoundException
is thrown.If the base is a
List
, thepropertyResolved
property of theELContext
object must be set totrue
by this resolver, before returning. If this property is nottrue
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 usingCollections.unmodifiableList(java.util.List)
, this method must throwPropertyNotWritableException
. Unfortunately, there is no Collections API method to detect this. However, an implementation can create a prototype unmodifiableList
and query its runtime type to see if it matches the runtime type of the base object as a workaround. - Specified by:
setValue
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- The list to be modified. Only bases of typeList
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 isnull
, or if the value isnull
and thisList
does not supportnull
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 |
如果 ELContext 的 propertyResolved 属性设置为 true ,则调用 setValue 方法总是失败的情况下返回 true ,该调用可能成功的情况下返回 false ;其他情况未定义。 |
Throws | PropertyNotFoundException: 如果给定索引超出此列表的范围。 |
Throws | NullPointerException:
如果 context 为 null |
Throws | ELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 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
, thepropertyResolved
property of theELContext
object must be set totrue
by this resolver, before returning. If this property is nottrue
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 usingCollections.unmodifiableList(java.util.List)
, this method must returntrue
. Unfortunately, there is no Collections API method to detect this. However, an implementation can create a prototype unmodifiableList
and query its runtime type to see if it matches the runtime type of the base object as a workaround. - Specified by:
isReadOnly
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- The list to analyze. Only bases of typeList
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 ofELContext
was set totrue
, thentrue
if calling thesetValue
method will always fail orfalse
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 isnull
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 classELResolver
- Parameters:
context
- The context of this evaluation.base
- The list. Only bases of typeList
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, returnsnull
.Assuming the base is a
List
, this method will always returnInteger.class
. This is becauseList
s accept integers as their index. - Specified by:
getCommonPropertyType
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- The list to analyze. Only bases of typeList
are handled by this resolver.- Returns:
null
if base is not aList
; otherwiseInteger.class
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!