Defines property resolution behavior on instances of
| Method from javax.el.MapELResolver Detail: |
public Class getCommonPropertyType(ELContext context,
Object base) {
if (base != null && base instanceof Map) {
return Object.class;
}
return null;
}
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 Maps
accept any object as a key. |
public Iterator getFeatureDescriptors(ELContext context,
Object base) {
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;
}
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 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 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
|
public Class getType(ELContext context,
Object base,
Object property) {
if (context == null) {
throw new NullPointerException();
}
if (base != null && base instanceof Map) {
context.setPropertyResolved(true);
return Object.class;
}
return null;
}
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 Maps
accept any object as the value for a given key. |
public Object getValue(ELContext context,
Object base,
Object property) {
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;
}
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 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. |
public boolean isReadOnly(ELContext context,
Object base,
Object property) {
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;
}
If the base object is a map, returns whether a call to
#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
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. |
public void setValue(ELContext context,
Object base,
Object property,
Object val) {
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();
}
}
}
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
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. |