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.
- Since:
- Jakarta Expression Language 3.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionClass<?>getCommonPropertyType(ELContext context, Object base) Returns the type of the property.Class<?>Returns the type of a static field.Returns the value of a static field.Invokes a public static method or the constructor for a class.booleanisReadOnly(ELContext context, Object base, Object property) Inquires whether the static field is writable.voidAttempts to write to a static field.Methods inherited from class jakarta.el.ELResolver
convertToType
-
Constructor Details
-
StaticFieldELResolver
public StaticFieldELResolver()
-
-
Method Details
-
getValue
Returns the value of a static field.
If the base object is an instance of
If the property is a public static field of class specified inELClassand the property is String, thepropertyResolvedproperty of theELContextobject must be set totrueby this resolver, before returning. If this property is nottrueafter 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.- Specified by:
getValuein classELResolver- Parameters:
context- The context of this evaluation.base- AnELClass.property- A static field name.- Returns:
- If the
propertyResolvedproperty ofELContextwas set totrue, then the static field value. - Throws:
NullPointerException- if context isnull.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.
-
setValue
Attempts to write to a static field.
If the base object is an instance of
ELClassand the property is String, aPropertyNotWritableExceptionwill always be thrown, because writing to a static field is not allowed.- Specified by:
setValuein classELResolver- Parameters:
context- The context of this evaluation.base- AnELClassproperty- The name of the fieldvalue- The value to set the field of the class to.- Throws:
NullPointerException- if context isnullPropertyNotWritableException- if base object instance ofELClassandpropertyinstance of String
-
invoke
public Object invoke(ELContext context, Object base, Object methodName, Class<?>[] paramTypes, Object[] params) Invokes a public static method or the constructor for a class.If the base object is an instance of
ELClassand the method is a String, thepropertyResolvedproperty of theELContextobject must be set totrueby the resolver, before returning. If this property is nottrueafter 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.
- Overrides:
invokein classELResolver- Parameters:
base- AnELClassmethodName- When coerced to aString, 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 benull, in which case the method's formal parameter types are assumed to be unknown.params- The parameters to pass to the method, ornullif no parameters.context- The context of this evaluation.- Returns:
- The result of the method invocation (
nullif the method has avoidreturn type). - Throws:
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 anInvocationTargetException, extract itscauseand pass it to theELExceptionconstructor.
-
getType
Returns the type of a static field.If the base object is an instance of
ELClassand the property is a String, thepropertyResolvedproperty of theELContextobject must be set totrueby the resolver, before returning. If this property is nottrueafter this method is called, the caller can safely assume no value has been set.- Specified by:
getTypein classELResolver- Parameters:
context- The context of this evaluation.base- AnELClass.property- The name of the field.- Returns:
- If the
propertyResolvedproperty ofELContextwas set totrue, thennull; otherwise undefined. - Throws:
NullPointerException- if context isnull.PropertyNotFoundException- if field is not a public static filed of the class, or if the field is inaccessible.
-
isReadOnly
Inquires whether the static field is writable.
If the base object is an instance of
ELClassand the property is a String, thepropertyResolvedproperty of theELContextobject must be set totrueby the resolver, before returning. If this property is nottrueafter this method is called, the caller can safely assume no value has been set.Always returns a
truebecause writing to a static field is not allowed.- Specified by:
isReadOnlyin classELResolver- Parameters:
context- The context of this evaluation.base- AnELClass.property- The name of the bean.- Returns:
true- Throws:
NullPointerException- if context isnull.
-
getCommonPropertyType
Returns the type of the property. Always returnsString.class, since a field name is a String.- Specified by:
getCommonPropertyTypein classELResolver- Parameters:
context- The context of this evaluation.base- AnELClass.- Returns:
String.class.
-