Top Description Inners Fields Constructors Methods
jakarta.el

public Class BeanELResolver

extends ELResolver
Class Inheritance
Static Imports
jakarta.el.ELUtil.getExceptionMessageString

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

If the java.beans.* package is available (part of the java.desktop module) the JavaBeans implementation provided by the JRE is used. If the java.beans.* package is not available, a built-in stand-alone implementation is used that just provides getter/setter support (as everything else requires classes from java.beans.*).

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.

The JavaBeans specification predates the introduction of default method implementations defined on an interface. In addition to the JavaBeans specification requirements for looking up property getters, property setters and methods, this resolver also considers default methods and includes them in the results.

The JavaBeans specification predates the introduction of Modules. In addition to the JavaBeans specification requirements for looking up property getters, property setters and methods, this resolver also considers module visibility.

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
Jakarta Server Pages 2.1
See Also
CompositeELResolver, ELResolver

Nested and Inner Type Summary

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

Field Summary

Modifier and TypeField and Description
private boolean
private final BeanELResolver.SoftConcurrentHashMap

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 jakarta.el.ELResolver.getCommonPropertyType.

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

public Class<?>

Returns:

If the propertyResolved property of ELContext was set to true, then the most general acceptable type which must be null if the either the property or the resolver is read-only; 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 jakarta.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 jakarta.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.
methodName
,
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 jakarta.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 jakarta.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 jakarta.el.ELResolver.setValue.

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

Inherited from jakarta.el.ELResolver:
convertToType

Field Detail

isReadOnlyback to summary
private boolean isReadOnly
propertiesback to summary
private 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 jakarta.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.

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

Implements abstract jakarta.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, there were no errors retrieving it and neither the property nor the resolver are read-only, the propertyType of the propertyDescriptor is returned. If the property is resolved but either the property or the resolver is read-only then null will be 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 which must be null if the either the property or the resolver is read-only; otherwise undefined

Annotations
@Override
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 jakarta.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.

Annotations
@Override
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 methodName, Class<?>[] paramTypes, Object[] params)

Overrides jakarta.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

methodName: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).

Annotations
@Override
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
Jakarta Expression Language 2.2
isReadOnlyback to summary
public boolean isReadOnly(ELContext context, Object base, Object property)

Implements abstract jakarta.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.

Annotations
@Override
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 jakarta.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.

Annotations
@Override
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.
jakarta.el back to summary

pack-priv abstract Class BeanELResolver.BeanProperties

extends Object
Class Inheritance
Known Direct Subclasses
jakarta.el.BeanSupportFull.BeanPropertiesFull, jakarta.el.BeanSupportStandalone.BeanPropertiesStandalone

Field Summary

Modifier and TypeField and Description
protected final Class<?>
protected final Map<String, BeanELResolver.BeanProperty>

Constructor Summary

AccessConstructor and Description
pack-priv
BeanProperties(Class<?> baseClass)

Method Summary

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

Field Detail

baseClassback to summary
protected final Class<?> baseClass
propertyMapback to summary
protected final Map<String, BeanELResolver.BeanProperty> propertyMap

Constructor Detail

BeanPropertiesback to summary
pack-priv BeanProperties(Class<?> baseClass)

Method Detail

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

pack-priv abstract Class BeanELResolver.BeanProperty

extends Object
Class Inheritance
Known Direct Subclasses
jakarta.el.BeanSupportFull.BeanPropertyFull, jakarta.el.BeanSupportStandalone.BeanPropertyStandalone

Field Summary

Modifier and TypeField and Description
private final Class<?>
private Method
private final Class<?>
private Method

Constructor Summary

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

Method Summary

Modifier and TypeMethod and Description
public Class<?>
public Method
pack-priv abstract Method
public Method
pack-priv abstract Method
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

baseClassback to summary
private final Class<?> baseClass
readMethodback to summary
private Method readMethod
typeback to summary
private final Class<?> type
writeMethodback to summary
private Method writeMethod

Constructor Detail

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

Method Detail

getPropertyTypeback to summary
public Class<?> getPropertyType()
getReadMethodback to summary
public Method getReadMethod(Object base)
getReadMethodback to summary
pack-priv abstract Method getReadMethod()
getWriteMethodback to summary
public Method getWriteMethod(Object base)
getWriteMethodback to summary
pack-priv abstract Method getWriteMethod()
isReadOnlyback to summary
public boolean isReadOnly(Object base)
jakarta.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)
jakarta.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>
private static final long

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
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.util.concurrent.ConcurrentHashMap.serialVersionUID.

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