|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
javax.el Class MapELResolver
java.lang.Objectjavax.el.ELResolver
javax.el.MapELResolver
public class MapELResolver
- extends ELResolver
在
java.util.Map 的实例上定义属性解析行为。
此解析器处理类型为 java.util.Map 的 base 对象。它接受任何对象作为属性,并且使用该对象作为映射中的键。所得值就是映射中与该键关联的值。
此解析器可以以只读模式构建,这意味着 #isReadOnly 将总是返回 true,#setValue 将总是抛出 PropertyNotWritableException。
ELResolver 使用 CompositeELResolver 连接到一起,以定义丰富语义来计算表达式。有关 ELResolver 的详细信息,请参阅 javadoc。
| since | JSP 2.1 |
| See also | javax.el.CompositeELResolver, javax.el.ELResolver, java.util.Map |
Defines property resolution behavior on instances of Map.
This resolver handles base objects of type java.util.Map.
It accepts any object as a property and uses that object as a key in
the map. The resulting value is the value in the map that is associated with
that key.
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,Map
| Field Summary |
|---|
| Fields inherited from class javax.el.ELResolver |
|---|
RESOLVABLE_AT_DESIGN_TIME, TYPE |
| Constructor Summary | |
|---|---|
MapELResolver()
Creates a new read/write MapELResolver. |
|
MapELResolver(boolean isReadOnly)
Creates a new MapELResolver whose read-only status is
determined by the given parameter. |
|
| Method Summary | |
|---|---|
Class<?> |
getCommonPropertyType(ELContext context,
Object base)
If the base object is a map, returns the most general type that this resolver accepts for the property argument. |
Iterator<FeatureDescriptor> |
getFeatureDescriptors(ELContext context,
Object base)
If the base object is a map, returns an Iterator
containing the set of keys available in the Map. |
Class<?> |
getType(ELContext context,
Object base,
Object property)
If the base object is a map, returns the most general acceptable type for a value in this map. |
Object |
getValue(ELContext context,
Object base,
Object property)
If the base object is a map, returns the value associated with the given key, as specified by the property argument. |
boolean |
isReadOnly(ELContext context,
Object base,
Object property)
If the base object is a map, 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 map, attempts to set the value associated with the given key, as specified by the property argument. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public
MapELResolver()
创建新的读/写 MapELResolver。
英文文档:
MapELResolver
public MapELResolver()
- Creates a new read/write
MapELResolver.
public
MapELResolver(boolean isReadOnly)
创建新的 MapELResolver,它的只读状态由给定的参数确定。
| isReadOnly |
如果此解析器无法修改映射,则为 true;否则为 false。 |
MapELResolver
public MapELResolver(boolean isReadOnly)
- Creates a new
MapELResolverwhose read-only status is determined by the given parameter.- Parameters:
isReadOnly-trueif this resolver cannot modify maps;falseotherwise.
| Method Detail |
|---|
public Class<T>
getType(ELContext context, Object base, Object property)
如果 base 对象是映射,则返回此映射中的值可以接受的最一般类型。
如果 base 为 Map,则在返回前,此解析器必须将 ELContext 对象的 propertyResolved 属性设置为 true。如果调用此方法后此属性不为 true,则调用者应该忽略返回值。
假定 base 为 Map,则此方法将总是返回 Object.class。这是因为 Map 接受任何对象作为给定键的值。
| context | 此计算的上下文。 |
| base |
要分析的映射。此解析器仅处理属于 Map 类型的 base。 |
| property | 要返回可接受类型的键。此解析器将忽略它。 |
| return |
如果 ELContext 的 propertyResolved 属性设置为 true,则返回最一般的可接受类型;其他情况未定义。 |
| Throws | NullPointerException:
如果 context 为 null |
| Throws | ELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。 |
getType
public Class<?> getType(ELContext context, Object base, Object property)
- If the base object is a map, returns the most general acceptable type
for a value in this map.
If the base is a
Map, thepropertyResolvedproperty of theELContextobject must be set totrueby this resolver, before returning. If this property is nottrueafter this method is called, the caller should ignore the return value.Assuming the base is a
Map, this method will always returnObject.class. This is becauseMaps accept any object as the value for a given key. - Specified by:
getTypein classELResolver
- Parameters:
context- The context of this evaluation.base- The map to analyze. Only bases of typeMapare handled by this resolver.property- The key to return the acceptable type for. Ignored by this resolver.- Returns:
- If the
propertyResolvedproperty ofELContextwas set totrue, then the most general acceptable type; otherwise undefined. - Throws:
NullPointerException- if context isnullELException- 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 参数指定)关联的值。如果未找到该键,则返回 null。
如果 base 为 Map,则在返回前,此解析器必须将 ELContext 对象的 propertyResolved 属性设置为 true。如果调用此方法后此属性不为 true,则调用者应该忽略返回值。
正如在 java.util.Map#get 中一样,返回 null 并不意味着没有该键的映射;也可能 Map 显式将该键映射为 null。
| context | 此计算的上下文。 |
| base |
要分析的映射。此解析器仅处理属于 Map 类型的 base。 |
| property | 要返回其关联值的键。 |
| return |
如果 ELContext 的 propertyResolved 属性设置为 true,则返回与给定键关联的值;如果没有找到键,则返回 null。其他情况未定义。 |
| Throws | ClassCastException:
如果该键不是此映射的正确类型(也可由底层 Map 抛出)。 |
| Throws | NullPointerException:
如果上下文为 null,或者键为 null 并且此映射不允许 null 键(后者也可由底层 Map 抛出)。 |
| Throws | ELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。 |
getValue
public Object getValue(ELContext context, Object base, Object property)
- If the base object is a map, returns the value associated with the
given key, as specified by the
propertyargument. If the key was not found,nullis returned.If the base is a
Map, thepropertyResolvedproperty of theELContextobject must be set totrueby this resolver, before returning. If this property is nottrueafter this method is called, the caller should ignore the return value.Just as in
Map.get(java.lang.Object), just becausenullis returned doesn't mean there is no mapping for the key; it's also possible that theMapexplicitly maps the key tonull. - Specified by:
getValuein classELResolver
- Parameters:
context- The context of this evaluation.base- The map to be analyzed. Only bases of typeMapare handled by this resolver.property- The key whose associated value is to be returned.- Returns:
- If the
propertyResolvedproperty ofELContextwas set totrue, then the value associated with the given key ornullif the key was not found. Otherwise, undefined. - Throws:
ClassCastException- if the key is of an inappropriate type for this map (optionally thrown by the underlyingMap).NullPointerException- if context isnull, or if the key is null and this map does not permit null keys (the latter is optionally thrown by the underlyingMap).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 为 Map,则在返回前,此解析器必须将 ELContext 对象的 propertyResolved 属性设置为 true。如果调用此方法后此属性不为 true,则调用者可以放心地假定没有设置任何值。
如果此解析器以只读模式构造,则此方法将总是抛出 PropertyNotWritableException。
如果使用 java.util.Collections#unmodifiableMap 创建 Map,则此方法必须抛出 PropertyNotWritableException。不幸的是,没有任何 Collection API 方法可以检测这一点。但是,实现可以使用以下方法解决该问题:创建原型不可修改的 Map,并查询其运行时类型,以确定它是否匹配 base 对象的运行时类型。
| context | 此计算的上下文。 |
| base |
要修改的映射。此解析器仅处理属于 Map 类型的 base。 |
| property | 要关联到指定值的键。 |
| val | 要关联到指定键的值。 |
| Throws | ClassCastException: 如果指定键或值的类不允许它存储在此映射中。 |
| Throws | NullPointerException:
如果上下文为 null,或者此映射不允许 null 键或值并且指定的键或值为 null。 |
| Throws | IllegalArgumentException: 如果此键或值的某个方面不允许它存储在此映射中。 |
| Throws | ELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。 |
| Throws | PropertyNotWritableException: 如果此解析器以只读模式构造,或者底层映射不支持放置操作。 |
setValue
public void setValue(ELContext context, Object base, Object property, Object val)
- If the base object is a map, attempts to set the value associated with
the given key, as specified by the
propertyargument.If the base is a
Map, thepropertyResolvedproperty of theELContextobject must be set totrueby this resolver, before returning. If this property is nottrueafter 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
Mapwas created usingCollections.unmodifiableMap(java.util.Map), this method must throwPropertyNotWritableException. Unfortunately, there is no Collections API method to detect this. However, an implementation can create a prototype unmodifiableMapand query its runtime type to see if it matches the runtime type of the base object as a workaround. - Specified by:
setValuein classELResolver
- Parameters:
context- The context of this evaluation.base- The map to be modified. Only bases of typeMapare handled by this resolver.property- The key with which the specified value is to be associated.val- The value to be associated with the specified key.- Throws:
ClassCastException- if the class of the specified key or value prevents it from being stored in this map.NullPointerException- if context isnull, or if this map does not permitnullkeys or values, and the specified key or value isnull.IllegalArgumentException- if some aspect of this key or value prevents it from being stored in this map.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.PropertyNotWritableException- if this resolver was constructed in read-only mode, or if the put operation is not supported by the underlying map.
public boolean
isReadOnly(ELContext context, Object base, Object property)
如果 base 对象是映射,则返回对 #setValue 的调用是否总是失败。
如果 base 为 Map,则在返回前,此解析器必须将 ELContext 对象的 propertyResolved 属性设置为 true。如果调用此方法后此属性不为 true,则调用者应该忽略返回值。
如果此解析器以只读模式构造,则此方法将总是返回 true。
如果使用 java.util.Collections#unmodifiableMap 创建 Map,则该方法必须返回 true。不幸的是,没有任何 Collection API 方法可以检测这一点。但是,实现可以使用以下方法解决该问题:创建原型不可修改的 Map,并查询其运行时类型,以确定它是否匹配 base 对象的运行时类型。
| context | 此计算的上下文。 |
| base |
要分析的映射。此解析器仅处理属于 Map 类型的 base。 |
| property | 要返回只读状态的键。此解析器将忽略它。 |
| return |
如果 ELContext 的 propertyResolved 属性设置为 true,则调用 setValue 方法总是失败的情况下返回 true,该调用可能成功的情况下返回 false;其他情况未定义。 |
| Throws | NullPointerException:
如果 context 为 null |
| Throws | ELException: 如果执行属性或变量解析时抛出异常。抛出的异常必须作为此异常的 cause 属性包含(如果可用)。 |
isReadOnly
public boolean isReadOnly(ELContext context, Object base, Object property)
- If the base object is a map, 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
Map, thepropertyResolvedproperty of theELContextobject must be set totrueby this resolver, before returning. If this property is nottrueafter 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
Mapwas created usingCollections.unmodifiableMap(java.util.Map), this method must returntrue. Unfortunately, there is no Collections API method to detect this. However, an implementation can create a prototype unmodifiableMapand query its runtime type to see if it matches the runtime type of the base object as a workaround. - Specified by:
isReadOnlyin classELResolver
- Parameters:
context- The context of this evaluation.base- The map to analyze. Only bases of typeMapare handled by this resolver.property- The key to return the read-only status for. Ignored by this resolver.- Returns:
- If the
propertyResolvedproperty ofELContextwas set totrue, thentrueif calling thesetValuemethod will always fail orfalseif it is possible that such a call may succeed; otherwise undefined. - Throws:
NullPointerException- if context isnullELException- 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 对象是映射,则返回一个 Iterator,它包含 Map 中可用的一组键。否则返回 null。
返回的 Iterator 必须包含 0 个或多个 java.beans.FeatureDescriptor 实例。每个 info 对象包含有关 Map 中一个键的信息,并且初始化如下:
toString 方法的返回值;如果该键为 null,则为 "null"。falsefalsetrueFeatureDescriptor 中设置以下指定的属性:
ELResolver#TYPE - 在此键上调用 getClass() 方法的返回值;如果该键为 null,则为 null。ELResolver#RESOLVABLE_AT_DESIGN_TIME - true| context | 此计算的上下文。 |
| base |
要迭代其键的映射。此解析器仅处理属于 Map 类型的 base。 |
| return |
包含 0 个或多个(可能无限多个)FeatureDescriptor 对象的 Iterator,每个对象代表此映射中的一个键;如果 base 对象不是映射,则返回 null。 |
getFeatureDescriptors
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
- If the base object is a map, returns an
Iteratorcontaining the set of keys available in theMap. Otherwise, returnsnull.The
Iteratorreturned must contain zero or more instances ofFeatureDescriptor. Each info object contains information about a key in the Map, and is initialized as follows:- displayName - The return value of calling the
toStringmethod on this key, or"null"if the key isnull.- name - Same as displayName property.
- shortDescription - Empty string
- expert -
false- hidden -
false- preferred -
true - displayName - The return value of calling the
FeatureDescriptors:
ELResolver.TYPE - The return value of calling the getClass()
method on this key, or null if the key is
null.ELResolver.RESOLVABLE_AT_DESIGN_TIME - true
- Specified by:
getFeatureDescriptorsin classELResolver
- Parameters:
context- The context of this evaluation.base- The map whose keys are to be iterated over. Only bases of typeMapare handled by this resolver.- Returns:
- An
Iteratorcontaining zero or more (possibly infinitely more)FeatureDescriptorobjects, each representing a key in this map, ornullif the base object is not a map. - See Also:
FeatureDescriptor
public Class<T>
getCommonPropertyType(ELContext context, Object base)
如果 base 对象是映射,则返回对于 property 参数此解析器可接受的最一般类型。否则返回 null。
假定 base 为 Map,则此方法将总是返回 Object.class。这是因为 Map 接受任何对象作为键。
| context | 此计算的上下文。 |
| base |
要分析的映射。此解析器仅处理属于 Map 类型的 base。 |
| return |
如果 base 不为 Map,则返回 null;否则返回 Object.class。 |
getCommonPropertyType
public Class<?> getCommonPropertyType(ELContext context, Object base)
- If the base object is a map, returns the most general type that
this resolver accepts for the
propertyargument. Otherwise, returnsnull.Assuming the base is a
Map, this method will always returnObject.class. This is becauseMaps accept any object as a key. - Specified by:
getCommonPropertyTypein classELResolver
- Parameters:
context- The context of this evaluation.base- The map to analyze. Only bases of typeMapare handled by this resolver.- Returns:
nullif base is not aMap; otherwiseObject.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 : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!
