- java.lang.Object
-
- javax.el.ELResolver
-
- javax.el.StaticFieldELResolver
-
public class StaticFieldELResolver extends ELResolver
An
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 an EL implementation.- Since:
- EL 3.0
- See Also:
ELClass
-
-
Field Summary
-
Fields inherited from class javax.el.ELResolver
RESOLVABLE_AT_DESIGN_TIME, TYPE
-
-
Constructor Summary
Constructors Constructor and Description StaticFieldELResolver()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description Class<?>
getCommonPropertyType(ELContext context, Object base)
Returns the type of the property.Iterator<FeatureDescriptor>
getFeatureDescriptors(ELContext context, Object base)
Returns the properties that can be resolved.Class<?>
getType(ELContext context, Object base, Object property)
Returns the type of a static field.Object
getValue(ELContext context, Object base, Object property)
Returns the value of a static field.Object
invoke(ELContext context, Object base, Object method, Class<?>[] paramTypes, Object[] params)
Invokes a public static method or the constructor for a class.boolean
isReadOnly(ELContext context, Object base, Object property)
Inquires whether the static field is writable.void
setValue(ELContext context, Object base, Object property, Object value)
Attempts to write to a static field.-
Methods inherited from class javax.el.ELResolver
convertToType
-
-
-
-
Method Detail
-
getValue
public Object getValue(ELContext context, Object base, Object property)
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 inELClass
and the property is String, thepropertyResolved
property of theELContext
object must be set totrue
by this resolver, before returning. If this property is nottrue
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.- Specified by:
getValue
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- AnELClass
.property
- A static field name.- Returns:
- If the
propertyResolved
property ofELContext
was 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
public void setValue(ELContext context, Object base, Object property, Object value)
Attempts to write to a static field.
If the base object is an instance of
ELClass
and the property is String, aPropertyNotWritableException
will always be thrown, because writing to a static field is not allowed.- Specified by:
setValue
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- AnELClass
property
- The name of the fieldvalue
- The value to set the field of the class to.- Throws:
NullPointerException
- if context isnull
PropertyNotWritableException
-
invoke
public Object invoke(ELContext context, Object base, Object method, Class<?>[] paramTypes, Object[] params)
Invokes a public static method or the constructor for a class.
If the base object is an instance ofELClass
and the method is a String, thepropertyResolved
property of theELContext
object must be set totrue
by the resolver, before returning. If this property is nottrue
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.
- Overrides:
invoke
in classELResolver
- Parameters:
base
- AnELClass
method
- 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, ornull
if no parameters.context
- The context of this evaluation.- Returns:
- The result of the method invocation (
null
if the method has avoid
return 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 itscause
and pass it to theELException
constructor.
-
getType
public Class<?> getType(ELContext context, Object base, Object property)
Returns the type of a static field.
If the base object is an instance of
If the property string is a public static field of class specified in ELClass, return the type of the static field.ELClass
and the property is a String, thepropertyResolved
property of theELContext
object must be set totrue
by the resolver, before returning. If this property is nottrue
after this method is called, the caller can safely assume no value has been set.- Specified by:
getType
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- AnELClass
.property
- The name of the field.- Returns:
- If the
propertyResolved
property ofELContext
was set totrue
, then the type of the type of the field. - Throws:
NullPointerException
- if context isnull
.PropertyNotFoundException
- if field is not a public static filed of the class, or if the field is inaccessible.
-
isReadOnly
public boolean isReadOnly(ELContext context, Object base, Object property)
Inquires whether the static field is writable.
If the base object is an instance of
ELClass
and the property is a String, thepropertyResolved
property of theELContext
object must be set totrue
by the resolver, before returning. If this property is nottrue
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.- Specified by:
isReadOnly
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- AnELClass
.property
- The name of the bean.- Returns:
true
- Throws:
NullPointerException
- if context isnull
.
-
getFeatureDescriptors
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
Returns the properties that can be resolved. Always returnsnull
, since there is no reason to iterate through a list of one element: field name.- Specified by:
getFeatureDescriptors
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- AnELClass
.- Returns:
null
.- See Also:
FeatureDescriptor
-
getCommonPropertyType
public Class<?> getCommonPropertyType(ELContext context, Object base)
Returns the type of the property. Always returnsString.class
, since a field name is a String.- Specified by:
getCommonPropertyType
in classELResolver
- Parameters:
context
- The context of this evaluation.base
- AnELClass
.- Returns:
String.class
.
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/08/2025 17:05:50 Cette version de la page est en cache (à la date du 21/08/2025 17:05:50) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 11/06/2005, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/el/StaticFieldELResolver.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.