MapELResolverpublic class MapELResolver extends ELResolver Defines property resolution behavior on instances of {@link java.util.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
{@link #isReadOnly} will always return true and
{@link #setValue} will always throw
PropertyNotWritableException .
ELResolver s are combined together using
{@link CompositeELResolver}s, to define rich semantics for evaluating
an expression. See the javadocs for {@link ELResolver} for details.
|
Fields Summary |
---|
private static Class | theUnmodifiableMapClass | private boolean | isReadOnly |
Constructors Summary |
---|
public MapELResolver()Creates a new read/write MapELResolver .
this.isReadOnly = false;
| public MapELResolver(boolean isReadOnly)Creates a new MapELResolver whose read-only status is
determined by the given parameter.
this.isReadOnly = isReadOnly;
|
Methods Summary |
---|
public java.lang.Class | getCommonPropertyType(javax.el.ELContext context, java.lang.Object base)If the base object is a map, returns the most general type that
this resolver accepts for the property argument.
Otherwise, returns null .
Assuming the base is a Map , this method will always
return Object.class . This is because Map s
accept any object as a key.
if (base != null && base instanceof Map) {
return Object.class;
}
return null;
| public java.util.Iterator | getFeatureDescriptors(javax.el.ELContext context, java.lang.Object base)If the base object is a map, returns an Iterator
containing the set of keys available in the Map .
Otherwise, returns null .
The Iterator returned must contain zero or more
instances of {@link java.beans.FeatureDescriptor}. Each info object
contains information about a key in the Map, and is initialized as
follows:
displayName - The return value of calling the
toString method on this key, or
"null" if the key is null .
name - Same as displayName property.
shortDescription - Empty string
expert - false
hidden - false
preferred - true
In addition, the following named attributes must be set in the
returned FeatureDescriptor s:
{@link ELResolver#TYPE} - The return value of calling the getClass()
method on this key, or null if the key is
null .
{@link ELResolver#RESOLVABLE_AT_DESIGN_TIME} - true
if (base != null && base instanceof Map) {
Map map = (Map) base;
Iterator iter = map.keySet().iterator();
List<FeatureDescriptor> list = new ArrayList<FeatureDescriptor>();
while (iter.hasNext()) {
Object key = iter.next();
FeatureDescriptor descriptor = new FeatureDescriptor();
String name = (key==null)? null: key.toString();
descriptor.setName(name);
descriptor.setDisplayName(name);
descriptor.setShortDescription("");
descriptor.setExpert(false);
descriptor.setHidden(false);
descriptor.setPreferred(true);
descriptor.setValue("type", key==null? null: key.getClass());
descriptor.setValue("resolvableAtDesignTime", Boolean.TRUE);
list.add(descriptor);
}
return list.iterator();
}
return null;
| public java.lang.Class | getType(javax.el.ELContext context, java.lang.Object base, java.lang.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 , 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 Map , this method will always
return Object.class . This is because Map s
accept any object as the value for a given key.
if (context == null) {
throw new NullPointerException();
}
if (base != null && base instanceof Map) {
context.setPropertyResolved(true);
return Object.class;
}
return null;
| public java.lang.Object | getValue(javax.el.ELContext context, java.lang.Object base, java.lang.Object property)If the base object is a map, returns the value associated with the
given key, as specified by the property argument. If the
key was not found, null is returned.
If the base is a Map , 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.
Just as in {@link java.util.Map#get}, just because null
is returned doesn't mean there is no mapping for the key; it's also
possible that the Map explicitly maps the key to
null .
if (context == null) {
throw new NullPointerException();
}
if (base != null && base instanceof Map) {
context.setPropertyResolved(true);
Map map = (Map) base;
return map.get(property);
}
return null;
| public boolean | isReadOnly(javax.el.ELContext context, java.lang.Object base, java.lang.Object property)If the base object is a map, returns whether a call to
{@link #setValue} will always fail.
If the base is a Map , 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 Map was created using
{@link java.util.Collections#unmodifiableMap}, this method must
return true . Unfortunately, there is no Collections API
method to detect this. However, an implementation can create a
prototype unmodifiable Map and query its runtime type
to see if it matches the runtime type of the base object as a
workaround.
if (context == null) {
throw new NullPointerException();
}
if (base != null && base instanceof Map) {
context.setPropertyResolved(true);
Map map = (Map) base;
return isReadOnly || map.getClass() == theUnmodifiableMapClass;
}
return false;
| public void | setValue(javax.el.ELContext context, java.lang.Object base, java.lang.Object property, java.lang.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.
If the base is a Map , 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 Map was created using
{@link java.util.Collections#unmodifiableMap}, this method must
throw PropertyNotWritableException . Unfortunately,
there is no Collections API method to detect this. However, an
implementation can create a prototype unmodifiable Map
and query its runtime type to see if it matches the runtime type of
the base object as a workaround.
if (context == null) {
throw new NullPointerException();
}
if (base != null && base instanceof Map) {
context.setPropertyResolved(true);
Map map = (Map) base;
if (isReadOnly || map.getClass() == theUnmodifiableMapClass) {
throw new PropertyNotWritableException();
}
try {
map.put(property, val);
} catch (UnsupportedOperationException ex) {
throw new PropertyNotWritableException();
}
}
|
|