Top Description Inners Fields Constructors Methods
javax.el

public Class BeanELResolver

extends ELResolver
Class Inheritance
Imports
java.lang.reflect.InvocationTargetException, .Method, java.lang.ref.SoftReference, .ReferenceQueue, java.beans.FeatureDescriptor, .BeanInfo, .Introspector, .PropertyDescriptor, .IntrospectionException, java.util.Iterator, .ArrayList, .Map, .HashMap, java.util.concurrent.ConcurrentHashMap

Defines property resolution behavior on objects using the JavaBeans component architecture.

This resolver handles base objects of any type, as long as the base is not null. It accepts any object as a property or method, and coerces it to a string.

For property resolution, the property string is used to find a JavaBeans compliant property on the base object. The value is accessed using JavaBeans getters and setters.

For method resolution, the method string is the name of the method in the bean. The parameter types can be optionally specified to identify the method. If the parameter types are not specified, the parameter objects are used in the method resolution.

This resolver can be constructed in read-only mode, which means that isReadOnly will always return true and setValue 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.

Because this resolver handles base objects of any type, it should be placed near the end of a composite resolver. Otherwise, it will claim to have resolved a property before any resolvers that come after it get a chance to test if they can do so as well.

Since
JSP 2.1
See Also
CompositeELResolver, ELResolver

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private boolean
private static final BeanELResolver.SoftConcurrentHashMap
Inherited from javax.el.ELResolver:
RESOLVABLE_AT_DESIGN_TIMETYPE

Constructor Summary

AccessConstructor and Description
public
BeanELResolver()

Creates a new read/write BeanELResolver.

public
BeanELResolver(boolean
true if this resolver cannot modify beans; false otherwise.
isReadOnly
)

Creates a new BeanELResolver whose read-only status is determined by the given parameter.

Method Summary

Modifier and TypeMethod and Description
private BeanELResolver.BeanProperty
getBeanProperty(ELContext context, Object base, Object prop)

public Class<?>

Returns:

null if base is null; otherwise Object.class.
getCommonPropertyType
(ELContext
The context of this evaluation.
context
,
Object
The bean to analyze.
base
)

Implements abstract javax.el.ELResolver.getCommonPropertyType.

If the base object is not null, returns the most general type that this resolver accepts for the property argument.
public Iterator<FeatureDescriptor>

Returns:

An Iterator containing zero or more FeatureDescriptor objects, each representing a property on this bean, or null if the base object is null.
getFeatureDescriptors
(ELContext
The context of this evaluation.
context
,
Object
The bean to analyze.
base
)

Implements abstract javax.el.ELResolver.getFeatureDescriptors.

If the base object is not null, returns an Iterator containing the set of JavaBeans properties available on the given object.
public Class<?>

Returns:

If the propertyResolved property of ELContext was set to true, then the most general acceptable type; otherwise undefined.
getType
(ELContext
The context of this evaluation.
context
,
Object
The bean to analyze.
base
,
Object
The name of the property to analyze. Will be coerced to a String.
property
)

Implements abstract javax.el.ELResolver.getType.

If the base object is not null, returns the most general acceptable type that can be set on this bean property.
public Object

Returns:

If the propertyResolved property of ELContext was set to true, then the value of the given property. Otherwise, undefined.
getValue
(ELContext
The context of this evaluation.
context
,
Object
The bean on which to get the property.
base
,
Object
The name of the property to get. Will be coerced to a String.
property
)

Implements abstract javax.el.ELResolver.getValue.

If the base object is not null, returns the current value of the given property on this bean.
public Object

Returns:

The result of the method invocation (null if the method has a void return type).
invoke
(ELContext
The context of this evaluation.
context
,
Object
The bean on which to invoke the method
base
,
Object
The simple name of the method to invoke. Will be coerced to a String. If method is "<init>"or "<clinit>" a MethodNotFoundException is thrown.
method
,
Class<?>[]
An array of Class objects identifying the method's formal parameter types, in declared order. Use an empty array if the method has no parameters. Can be null, in which case the method's formal parameter types are assumed to be unknown.
paramTypes
,
Object[]
The parameters to pass to the method, or null if no parameters.
params
)

Overrides javax.el.ELResolver.invoke.

If the base object is not null, invoke the method, with the given parameters on this bean.
public boolean

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.
isReadOnly
(ELContext
The context of this evaluation.
context
,
Object
The bean to analyze.
base
,
Object
The name of the property to analyzed. Will be coerced to a String.
property
)

Implements abstract javax.el.ELResolver.isReadOnly.

If the base object is not null, returns whether a call to setValue will always fail.
public void
setValue(ELContext
The context of this evaluation.
context
,
Object
The bean on which to set the property.
base
,
Object
The name of the property to set. Will be coerced to a String.
property
,
Object
The value to be associated with the specified key.
val
)

Implements abstract javax.el.ELResolver.setValue.

If the base object is not null, attempts to set the value of the given property on this bean.
Inherited from javax.el.ELResolver:
convertToType

Field Detail

isReadOnlyback to summary
private boolean isReadOnly
propertiesback to summary
private static final BeanELResolver.SoftConcurrentHashMap properties

Constructor Detail

BeanELResolverback to summary
public BeanELResolver()

Creates a new read/write BeanELResolver.

BeanELResolverback to summary
public BeanELResolver(boolean isReadOnly)

Creates a new BeanELResolver whose read-only status is determined by the given parameter.

Parameters
isReadOnly:boolean

true if this resolver cannot modify beans; false otherwise.

Method Detail

getBeanPropertyback to summary
private BeanELResolver.BeanProperty getBeanProperty(ELContext context, Object base, Object prop)
getCommonPropertyTypeback to summary
public Class<?> getCommonPropertyType(ELContext context, Object base)

Implements abstract javax.el.ELResolver.getCommonPropertyType.

If the base object is not null, returns the most general type that this resolver accepts for the property argument. Otherwise, returns null.

Assuming the base is not null, this method will always return Object.class. This is because any object is accepted as a key and is coerced into a string.

Parameters
context:ELContext

The context of this evaluation.

base:Object

The bean to analyze.

Returns:Class<?>

null if base is null; otherwise Object.class.

getFeatureDescriptorsback to summary
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)

Implements abstract javax.el.ELResolver.getFeatureDescriptors.

If the base object is not null, returns an Iterator containing the set of JavaBeans properties available on the given object. Otherwise, returns null.

The Iterator returned must contain zero or more instances of java.beans.FeatureDescriptor. Each info object contains information about a property in the bean, as obtained by calling the BeanInfo.getPropertyDescriptors method. The FeatureDescriptor is initialized using the same fields as are present in the PropertyDescriptor, with the additional required named attributes "type" and "resolvableAtDesignTime" set as follows:

  • ELResolver#TYPE - The runtime type of the property, from PropertyDescriptor.getPropertyType().
  • ELResolver#RESOLVABLE_AT_DESIGN_TIME - true.
  • Parameters
    context:ELContext

    The context of this evaluation.

    base:Object

    The bean to analyze.

    Returns:Iterator<FeatureDescriptor>

    An Iterator containing zero or more FeatureDescriptor objects, each representing a property on this bean, or null if the base object is null.

    getTypeback to summary
    public Class<?> getType(ELContext context, Object base, Object property)

    Implements abstract javax.el.ELResolver.getType.

    If the base object is not null, returns the most general acceptable type that can be set on this bean property.

    If the base is not null, 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.

    The provided property will first be coerced to a String. If there is a BeanInfoProperty for this property and there were no errors retrieving it, the propertyType of the propertyDescriptor is returned. Otherwise, a PropertyNotFoundException is thrown.

    Parameters
    context:ELContext

    The context of this evaluation.

    base:Object

    The bean to analyze.

    property:Object

    The name of the property to analyze. Will be coerced to a String.

    Returns:Class<?>

    If the propertyResolved property of ELContext was set to true, then the most general acceptable type; otherwise undefined.

    Exceptions
    NullPointerException:
    if context is null
    PropertyNotFoundException:
    if base is not null and the specified property does not exist or is not readable.
    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.
    getValueback to summary
    public Object getValue(ELContext context, Object base, Object property)

    Implements abstract javax.el.ELResolver.getValue.

    If the base object is not null, returns the current value of the given property on this bean.

    If the base is not null, 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.

    The provided property name will first be coerced to a String. If the property is a readable property of the base object, as per the JavaBeans specification, then return the result of the getter call. If the getter throws an exception, it is propagated to the caller. If the property is not found or is not readable, a PropertyNotFoundException is thrown.

    Parameters
    context:ELContext

    The context of this evaluation.

    base:Object

    The bean on which to get the property.

    property:Object

    The name of the property to get. Will be coerced to a String.

    Returns:Object

    If the propertyResolved property of ELContext was set to true, then the value of the given property. Otherwise, undefined.

    Exceptions
    NullPointerException:
    if context is null.
    PropertyNotFoundException:
    if base is not null and the specified property does not exist or is not readable.
    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.
    invokeback to summary
    public Object invoke(ELContext context, Object base, Object method, Class<?>[] paramTypes, Object[] params)

    Overrides javax.el.ELResolver.invoke.

    If the base object is not null, invoke the method, with the given parameters on this bean. The return value from the method is returned.

    If the base is not null, 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.

    The provided method object will first be coerced to a String. The methods in the bean is then examined and an attempt will be made to select one for invocation. If no suitable can be found, a MethodNotFoundException is thrown. If the given paramTypes is not null, select the method with the given name and parameter types. Else select the method with the given name that has the same number of parameters. If there are more than one such method, the method selection process is undefined. Else select the method with the given name that takes a variable number of arguments. Note the resolution for overloaded methods will likely be clarified in a future version of the spec. The provide parameters are coerced to the corresponding parameter types of the method, and the method is then invoked.

    Parameters
    context:ELContext

    The context of this evaluation.

    base:Object

    The bean on which to invoke the method

    method:Object

    The simple name of the method to invoke. Will be coerced to a String. If method is "<init>"or "<clinit>" a MethodNotFoundException is thrown.

    paramTypes:Class<?>[]

    An array of Class objects identifying the method's formal parameter types, in declared order. Use an empty array if the method has no parameters. Can be null, in which case the method's formal parameter types are assumed to be unknown.

    params:Object[]

    The parameters to pass to the method, or null if no parameters.

    Returns:Object

    The result of the method invocation (null if the method has a void return type).

    Exceptions
    MethodNotFoundException:
    if no suitable method can be found.
    ELException:
    if an exception was thrown while performing (base, method) resolution. The thrown exception must be included as the cause property of this exception, if available. If the exception thrown is an InvocationTargetException, extract its cause and pass it to the ELException constructor.
    Since
    EL 2.2
    isReadOnlyback to summary
    public boolean isReadOnly(ELContext context, Object base, Object property)

    Implements abstract javax.el.ELResolver.isReadOnly.

    If the base object is not null, returns whether a call to setValue will always fail.

    If the base is not null, 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 return true.

    The provided property name will first be coerced to a String. If property is a writable property of base, false is returned. If the property is found but is not writable, true is returned. If the property is not found, a PropertyNotFoundException is thrown.

    Parameters
    context:ELContext

    The context of this evaluation.

    base:Object

    The bean to analyze.

    property:Object

    The name of the property to analyzed. Will be coerced to a String.

    Returns:boolean

    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.

    Exceptions
    NullPointerException:
    if context is null
    PropertyNotFoundException:
    if base is not null and the specified property does not exist.
    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.
    setValueback to summary
    public void setValue(ELContext context, Object base, Object property, Object val)

    Implements abstract javax.el.ELResolver.setValue.

    If the base object is not null, attempts to set the value of the given property on this bean.

    If the base is not null, 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.

    The provided property name will first be coerced to a String. If property is a writable property of base (as per the JavaBeans Specification), the setter method is called (passing value). If the property exists but does not have a setter, then a PropertyNotFoundException is thrown. If the property does not exist, a PropertyNotFoundException is thrown.

    Parameters
    context:ELContext

    The context of this evaluation.

    base:Object

    The bean on which to set the property.

    property:Object

    The name of the property to set. Will be coerced to a String.

    val:Object

    The value to be associated with the specified key.

    Exceptions
    NullPointerException:
    if context is null.
    PropertyNotFoundException:
    if base is not null and the specified property does not exist.
    PropertyNotWritableException:
    if this resolver was constructed in read-only mode, or if there is no setter for the property.
    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.
    javax.el back to summary

    pack-priv final Class BeanELResolver.BeanProperties

    extends Object
    Class Inheritance

    Field Summary

    Modifier and TypeField and Description
    private final Map<String, BeanELResolver.BeanProperty>

    Constructor Summary

    AccessConstructor and Description
    public
    BeanProperties(Class<?> baseClass)

    Method Summary

    Modifier and TypeMethod and Description
    public BeanELResolver.BeanProperty
    Inherited from java.lang.Object:
    cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

    Field Detail

    propertyMapback to summary
    private final Map<String, BeanELResolver.BeanProperty> propertyMap

    Constructor Detail

    BeanPropertiesback to summary
    public BeanProperties(Class<?> baseClass)

    Method Detail

    getBeanPropertyback to summary
    public BeanELResolver.BeanProperty getBeanProperty(String property)
    javax.el back to summary

    pack-priv final Class BeanELResolver.BeanProperty

    extends Object
    Class Inheritance

    Field Summary

    Modifier and TypeField and Description
    private PropertyDescriptor
    private Method
    private Method

    Constructor Summary

    AccessConstructor and Description
    public
    BeanProperty(Class<?> baseClass, PropertyDescriptor descriptor)

    Method Summary

    Modifier and TypeMethod and Description
    public Class<T>
    public Method
    public Method
    public boolean
    Inherited from java.lang.Object:
    cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

    Field Detail

    descriptorback to summary
    private PropertyDescriptor descriptor
    readMethodback to summary
    private Method readMethod
    writeMethodback to summary
    private Method writeMethod

    Constructor Detail

    BeanPropertyback to summary
    public BeanProperty(Class<?> baseClass, PropertyDescriptor descriptor)

    Method Detail

    getPropertyTypeback to summary
    public Class<T> getPropertyType()
    getReadMethodback to summary
    public Method getReadMethod()
    getWriteMethodback to summary
    public Method getWriteMethod()
    isReadOnlyback to summary
    public boolean isReadOnly()
    javax.el back to summary

    private Class BeanELResolver.BPSoftReference

    extends SoftReference<BeanELResolver.BeanProperties>
    Class Inheritance

    Field Summary

    Modifier and TypeField and Description
    pack-priv final Class<?>

    Constructor Summary

    AccessConstructor and Description
    pack-priv

    Method Summary

    Inherited from java.lang.ref.SoftReference:
    get

    Field Detail

    keyback to summary
    pack-priv final Class<?> key

    Constructor Detail

    BPSoftReferenceback to summary
    pack-priv BPSoftReference(Class<?> key, BeanELResolver.BeanProperties beanProperties, ReferenceQueue<BeanELResolver.BeanProperties> refQ)
    javax.el back to summary

    private Class BeanELResolver.SoftConcurrentHashMap

    extends ConcurrentHashMap<Class<?>, BeanELResolver.BeanProperties>
    Class Inheritance

    Field Summary

    Modifier and TypeField and Description
    private static final int
    private ConcurrentHashMap<Class<?>, BeanELResolver.BPSoftReference>
    private ReferenceQueue<BeanELResolver.BeanProperties>

    Constructor Summary

    AccessConstructor and Description
    private

    Method Summary

    Modifier and TypeMethod and Description
    private void
    public BeanELResolver.BeanProperties
    get(Object
    the key whose associated value is to be returned
    key
    )

    Overrides java.util.concurrent.ConcurrentHashMap.get.

    Implements java.util.Map.get.

    Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
    public BeanELResolver.BeanProperties
    put(Class<?>
    key with which the specified value is to be associated
    key
    ,
    BeanELResolver.BeanProperties
    value to be associated with the specified key
    value
    )

    Overrides java.util.concurrent.ConcurrentHashMap.put.

    Implements java.util.Map.put.

    Maps the specified key to the specified value in this table.
    public BeanELResolver.BeanProperties
    putIfAbsent(Class<?>
    key with which the specified value is to be associated
    key
    ,
    BeanELResolver.BeanProperties
    value to be associated with the specified key
    value
    )

    Overrides java.util.concurrent.ConcurrentHashMap.putIfAbsent.

    Overrides default java.util.Map.putIfAbsent.

    Implements java.util.concurrent.ConcurrentMap.putIfAbsent.

    If the specified key is not already associated with a value, associates it with the given value.
    Inherited from java.util.concurrent.ConcurrentHashMap:
    clearcomputecomputeIfAbsentcomputeIfPresentcontainscontainsKeycontainsValueelementsentrySetequalsforEachforEachforEachforEachEntryforEachEntryforEachKeyforEachKeyforEachValueforEachValuegetOrDefaulthashCodeisEmptykeyskeySetkeySetmappingCountmergenewKeySetnewKeySetputAllreducereduceEntriesreduceEntriesreduceEntriesToDoublereduceEntriesToIntreduceEntriesToLongreduceKeysreduceKeysreduceKeysToDoublereduceKeysToIntreduceKeysToLongreduceToDoublereduceToIntreduceToLongreduceValuesreduceValuesreduceValuesToDoublereduceValuesToIntreduceValuesToLongremoveremovereplacereplacereplaceAllsearchsearchEntriessearchKeyssearchValuessizetoStringvalues

    Field Detail

    CACHE_INIT_SIZEback to summary
    private static final int CACHE_INIT_SIZE
    mapback to summary
    private ConcurrentHashMap<Class<?>, BeanELResolver.BPSoftReference> map
    refQback to summary
    private ReferenceQueue<BeanELResolver.BeanProperties> refQ

    Constructor Detail

    SoftConcurrentHashMapback to summary
    private SoftConcurrentHashMap()

    Method Detail

    cleanupback to summary
    private void cleanup()
    getback to summary
    public BeanELResolver.BeanProperties get(Object key)

    Overrides java.util.concurrent.ConcurrentHashMap.get.

    Implements java.util.Map.get.

    Doc from java.util.concurrent.ConcurrentHashMap.get.

    Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

    More formally, if this map contains a mapping from a key k to a value v such that key.equals(k), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

    Parameters
    key:Object

    Doc from java.util.Map.get.

    the key whose associated value is to be returned

    Returns:BeanELResolver.BeanProperties

    Doc from java.util.Map.get.

    the value to which the specified key is mapped, or null if this map contains no mapping for the key

    Annotations
    @Override
    putback to summary
    public BeanELResolver.BeanProperties put(Class<?> key, BeanELResolver.BeanProperties value)

    Overrides java.util.concurrent.ConcurrentHashMap.put.

    Implements java.util.Map.put.

    Doc from java.util.concurrent.ConcurrentHashMap.put.

    Maps the specified key to the specified value in this table. Neither the key nor the value can be null.

    The value can be retrieved by calling the get method with a key that is equal to the original key.

    Parameters
    key:Class<?>

    key with which the specified value is to be associated

    value:BeanELResolver.BeanProperties

    value to be associated with the specified key

    Returns:BeanELResolver.BeanProperties

    the previous value associated with key, or null if there was no mapping for key

    Annotations
    @Override
    putIfAbsentback to summary
    public BeanELResolver.BeanProperties putIfAbsent(Class<?> key, BeanELResolver.BeanProperties value)

    Overrides java.util.concurrent.ConcurrentHashMap.putIfAbsent.

    Overrides default java.util.Map.putIfAbsent.

    Implements java.util.concurrent.ConcurrentMap.putIfAbsent.

    Doc from java.util.concurrent.ConcurrentHashMap.putIfAbsent.

    If the specified key is not already associated with a value, associates it with the given value. This is equivalent to, for this map:

     if (!map.containsKey(key))
      return map.put(key, value);
    else
      return map.get(key);
    except that the action is performed atomically.
    Parameters
    key:Class<?>

    Doc from java.util.concurrent.ConcurrentMap.putIfAbsent.

    key with which the specified value is to be associated

    value:BeanELResolver.BeanProperties

    Doc from java.util.concurrent.ConcurrentMap.putIfAbsent.

    value to be associated with the specified key

    Returns:BeanELResolver.BeanProperties

    the previous value associated with the specified key, or null if there was no mapping for the key

    Annotations
    @Override