public class StaticFieldELResolver extends ELResolver
ELResolver
for resolving static fields, enum constants and static methods. Also handles constructor calls
as a special case.
The resolver handles base objects of the type ELClass
, which is usually generated by a Jakarta Expression
Language implementation.
ELClass
RESOLVABLE_AT_DESIGN_TIME, TYPE
Constructor and Description |
---|
StaticFieldELResolver() |
Modifier and Type | Method and Description |
---|---|
java.lang.Class<?> |
getCommonPropertyType(ELContext context,
java.lang.Object base)
Returns the type of the property.
|
java.util.Iterator<java.beans.FeatureDescriptor> |
getFeatureDescriptors(ELContext context,
java.lang.Object base)
Deprecated.
This method will be removed without replacement in EL 6.0
|
java.lang.Class<?> |
getType(ELContext context,
java.lang.Object base,
java.lang.Object property)
Returns the type of a static field.
|
java.lang.Object |
getValue(ELContext context,
java.lang.Object base,
java.lang.Object property)
Returns the value of a static field.
|
java.lang.Object |
invoke(ELContext context,
java.lang.Object base,
java.lang.Object methodName,
java.lang.Class<?>[] paramTypes,
java.lang.Object[] params)
Invokes a public static method or the constructor for a class.
|
boolean |
isReadOnly(ELContext context,
java.lang.Object base,
java.lang.Object property)
Inquires whether the static field is writable.
|
void |
setValue(ELContext context,
java.lang.Object base,
java.lang.Object property,
java.lang.Object value)
Attempts to write to a static field.
|
convertToType
public java.lang.Object getValue(ELContext context, java.lang.Object base, java.lang.Object property)
Returns the value of a static field.
If the base object is an instance of ELClass
and the property is String, 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.
ELClass
, return the value of the static
field. An Enum constant is a public static field of an Enum object, and is a special case of this.getValue
in class ELResolver
context
- The context of this evaluation.base
- An ELClass
.property
- A static field name.propertyResolved
property of ELContext
was set to true
, then
the static field value.java.lang.NullPointerException
- if context is null
.PropertyNotFoundException
- if the specified class does not exist, or if the field is not a public static filed
of the class, or if the field is inaccessible.public void setValue(ELContext context, java.lang.Object base, java.lang.Object property, java.lang.Object value)
Attempts to write to a static field.
If the base object is an instance of ELClass
and the property is String, a
PropertyNotWritableException
will always be thrown, because writing to a static field is not allowed.
setValue
in class ELResolver
context
- The context of this evaluation.base
- An ELClass
property
- The name of the fieldvalue
- The value to set the field of the class to.java.lang.NullPointerException
- if context is null
PropertyNotWritableException
- if base object instance of ELClass
and property
instance of Stringpublic java.lang.Object invoke(ELContext context, java.lang.Object base, java.lang.Object methodName, java.lang.Class<?>[] paramTypes, java.lang.Object[] params)
If the base object is an instance of ELClass
and the method is a String, the
propertyResolved
property of the ELContext
object must be set to true
by the
resolver, before returning. If this property is not true
after this method is called, the caller should
ignore the return value.
Invoke the public static method specified by method
.
The process involved in the method selection is the same as that used in BeanELResolver
.
As a special case, if the name of the method is "<init>", the constructor for the class will be invoked.
invoke
in class ELResolver
base
- An ELClass
methodName
- When coerced to a String
, the simple name of the method.paramTypes
- 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
- The parameters to pass to the method, or null
if no parameters.context
- The context of this evaluation.null
if the method has a void
return type).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.public java.lang.Class<?> getType(ELContext context, java.lang.Object base, java.lang.Object property)
If the base object is an instance of ELClass
and the property is a String, the
propertyResolved
property of the ELContext
object must be set to true
by the
resolver, before returning. If this property is not true
after this method is called, the caller can
safely assume no value has been set.
getType
in class ELResolver
context
- The context of this evaluation.base
- An ELClass
.property
- The name of the field.propertyResolved
property of ELContext
was set to true
, then
null
; otherwise undefined.java.lang.NullPointerException
- if context is null
.PropertyNotFoundException
- if field is not a public static filed of the class, or if the field is
inaccessible.public boolean isReadOnly(ELContext context, java.lang.Object base, java.lang.Object property)
Inquires whether the static field is writable.
If the base object is an instance of ELClass
and the property is a String, the
propertyResolved
property of the ELContext
object must be set to true
by the
resolver, before returning. If this property is not true
after this method is called, the caller can
safely assume no value has been set.
Always returns a true
because writing to a static field is not allowed.
isReadOnly
in class ELResolver
context
- The context of this evaluation.base
- An ELClass
.property
- The name of the bean.true
java.lang.NullPointerException
- if context is null
.@Deprecated public java.util.Iterator<java.beans.FeatureDescriptor> getFeatureDescriptors(ELContext context, java.lang.Object base)
null
, since there is no reason to iterate
through a list of one element: field name.getFeatureDescriptors
in class ELResolver
context
- The context of this evaluation.base
- An ELClass
.null
.FeatureDescriptor
public java.lang.Class<?> getCommonPropertyType(ELContext context, java.lang.Object base)
String.class
, since a field name is a String.getCommonPropertyType
in class ELResolver
context
- The context of this evaluation.base
- An ELClass
.String.class
.