Provides an API for using EL in a stand-alone environment.
This class provides a direct and simple interface for
ValueExpression to a EL variable.This API is not a replacement for the APIs in EL 2.2. Containers that maintains EL environments can continue to do so, without using this API.
For EL users who want to manipulate EL environments, like adding custom
ELResolvers, ELManager can be used.
Since it maintains the state of the EL environments,
ELProcessor is not thread safe. In the simplest case,
an instance can be created and destroyed before and after evaluating
EL expressions. A more general usage is to use an instance of
ELProcessor for a session, so that the user can configure the
EL evaluation environment for that session.
A note about the EL expressions strings used in the class. The strings
allowed in the methods ELProcessor#getValue,
ELProcessor#setValue, and ELProcessor#setVariable are
limited to non-composite expressions, i.e. expressions
of the form ${...} or #{...} only. Also, it is not necessary (in fact not
allowed) to bracket the expression strings with ${ or #{ and } in these
methods: they will be automatically bracketed. This reduces the visual
cluster, without any lost of functionalities (thanks to the addition of the
concatenation operator).
ELProcessor elp = new ELProcessor();
elp.defineBean("employee", new Employee("Charlie Brown"));
String name = elp.eval("employee.name");
| Modifier and Type | Field and Description |
|---|---|
| private ELManager | |
| private ExpressionFactory |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private String | |
| public void | defineBean(String
The name of the bean name, Object The bean instance to be defined. If bean)null,
the name will be removed from the local bean repository.Define a bean in a local bean repository, hiding other beans of the same name. |
| public void | defineFunction(String
The namespace for the function or "" for no namesapce. prefix, String The name of the function.
If empty (""), the method name is used as the function name. function, String The full Java class name that implements the function. className, String The name (specified without parenthesis) or the signature
(as in the Java Language Spec) of the static method that implements
the function. If the name (e.g. "sum") is given, the first declared
method in class that matches the name is selected. If the signature
(e.g. "int sum(int, int)" ) is given, then the declared method
with the signature is selected. method)Define an EL function in the local function mapper. |
| public void | defineFunction(String
The namespace for the function or "" for no namesapce. prefix, String The name of the function.
If empty (""), the method name is used as the function name. function, Method The method)java.lang.reflect.Method instance of
the method that implements the function.Define an EL function in the local function mapper. |
| public Object | |
| public ELManager | Returns: The ELManager used for EL processing.Return the ELManager used for EL processing. |
| public Object | |
| public void | |
| public void | setVariable(String
The name of the variable. var, String The EL expression to be assigned to the variable. expression)Assign an EL expression to an EL variable. |
| private static Class | toClass(String type, ClassLoader loader)
Return the Class object associated with the class or interface with the given name. |
| elManager | back to summary |
|---|---|
| private ELManager elManager | |
| factory | back to summary |
|---|---|
| private ExpressionFactory factory | |
| ELProcessor | back to summary |
|---|---|
| public ELProcessor() | |
| bracket | back to summary |
|---|---|
| private String bracket(String expression) | |
| defineBean | back to summary |
|---|---|
| public void defineBean(String name, Object bean) Define a bean in a local bean repository, hiding other beans of the same name. | |
| defineFunction | back to summary |
|---|---|
| public void defineFunction(String prefix, String function, String className, String method) throws ClassNotFoundException, NoSuchMethodException Define an EL function in the local function mapper.
| |
| defineFunction | back to summary |
|---|---|
| public void defineFunction(String prefix, String function, Method method) throws NoSuchMethodException Define an EL function in the local function mapper.
| |
| eval | back to summary |
|---|---|
| public Object eval(String expression) Evaluates an EL expression. | |
| getELManager | back to summary |
|---|---|
| public ELManager getELManager() Return the ELManager used for EL processing.
| |
| getValue | back to summary |
|---|---|
| public Object getValue(String expression, Class<?> expectedType) Evaluates an EL expression, and coerces the result to the specified type. | |
| setValue | back to summary |
|---|---|
| public void setValue(String expression, Object value) Sets an expression with a new value. The target expression is evaluated, up to the last property resolution, and the resultant (base, property) pair is set to the provided value.
| |
| setVariable | back to summary |
|---|---|
| public void setVariable(String var, String expression) Assign an EL expression to an EL variable. The expression is parsed,
but not evaluated, and the parsed expression is mapped to the EL
variable in the local variable map.
Any previously assigned expression to the same variable will be replaced.
If the expression is | |
| toClass | back to summary |
|---|---|
| private static Class Return the Class object associated with the class or interface with the given name. | |