# Class ELProcessor

java.lang.Object
jakarta.el.ELProcessor

public class ELProcessor extends Object
Provides a simple API for evaluating EL expressions in a standalone environment. This class wraps an `ELManager` and provides methods for evaluating expressions, defining beans and functions, and managing variables. It is the primary entry point for applications that use the EL API outside of a Jakarta EE container.

Since:
  EL 3.0

## Constructor Summary

Constructors
Constructor
Description
`ELProcessor()`
Constructs an ELProcessor with a default `ELManager` and `StandardELContext`.

## Method Summary

Modifier and Type
Method
Description
`void`
`defineBean(String name, Object bean)`
Defines or removes a bean accessible by name in EL expressions.
`void`
`defineFunction(String prefix, String function, Method method)`
Map a method to a function name.
`void`
`defineFunction(String prefix, String function, String className, String methodName)`
Registers a function in the EL context by looking up the static method in the given class.
`<T> T`
`eval(String expression)`
Evaluates the given EL expression and returns the result as the requested type.
`ELManager`
`getELManager()`
Returns the `ELManager` that manages the EL context, resolvers, functions, and variables for this processor.
`<T> T`
`getValue(String expression, Class<T> expectedType)`
Evaluates the given EL expression and returns the result coerced to the expected type.
`void`
`setValue(String expression, Object value)`
Evaluates the given EL expression and sets the result to the specified value.
`void`
`setVariable(String variable, String expression)`
Registers a variable in the EL context.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ELProcessor

public ELProcessor()
Constructs an ELProcessor with a default `ELManager` and `StandardELContext`. The processor is ready to evaluate expressions immediately after construction.

## Method Details

### getELManager

public ELManager getELManager()
Returns the `ELManager` that manages the EL context, resolvers, functions, and variables for this processor.

Returns:
  the ELManager instance

### eval

public <T> T eval(String expression)
Evaluates the given EL expression and returns the result as the requested type. The expression is automatically wrapped in ${} delimiters before evaluation.

Type Parameters:
  `T` - the expected result type
Parameters:
  `expression` - the EL expression to evaluate
Returns:
  the result of evaluating the expression, coerced to the requested type
Throws:
  `ELException` - if the expression cannot be evaluated

### getValue

public <T> T getValue(String expression, Class<T> expectedType)
Evaluates the given EL expression and returns the result coerced to the expected type. The expression is automatically wrapped in ${} delimiters before evaluation.

Type Parameters:
  `T` - the expected result type
Parameters:
  `expression` - the EL expression to evaluate
  `expectedType` - the class of the expected result type
Returns:
  the result of evaluating the expression, coerced to the expected type
Throws:
  `ELException` - if the expression cannot be evaluated

### setValue

public void setValue(String expression, Object value)
Evaluates the given EL expression and sets the result to the specified value. This is used for EL assignment expressions. The expression is automatically wrapped in ${} delimiters before evaluation.

Parameters:
  `expression` - the EL expression to evaluate
  `value` - the value to assign
Throws:
  `ELException` - if the expression cannot be evaluated or the target is not writable

### setVariable

public void setVariable(String variable, String expression)
Registers a variable in the EL context. The variable is associated with the result of evaluating the given expression. Passing a `null` expression removes the variable from the context.

Parameters:
  `variable` - the variable name
  `expression` - the EL expression to associate with the variable, or `null` to remove
Throws:
  `ELException` - if the expression cannot be evaluated

### defineFunction

public void defineFunction(String prefix, String function, String className, String methodName) throws ClassNotFoundException, NoSuchMethodException
Registers a function in the EL context by looking up the static method in the given class. The method name may include a return type and parameter signature in the format `returnType methodName(paramTypes)`. The function is then callable in EL expressions as `prefix:function(args)`.

Parameters:
  `prefix` - the namespace prefix for the function
  `function` - the local function name, or empty to use the method name
  `className` - the fully qualified name of the class containing the static method
  `methodName` - the method name, optionally with return type and parameter signature
Throws:
  `ClassNotFoundException` - if the class cannot be found or is not public
  `NoSuchMethodException` - if the method cannot be found or is not a public static method

### defineFunction

public void defineFunction(String prefix, String function, Method method) throws NoSuchMethodException
Map a method to a function name.

Parameters:
  `prefix` - Function prefix
  `function` - Function name
  `method` - Method
Throws:
  `NullPointerException` - If any of the arguments are null
  `NoSuchMethodException` - If the method is not static

### defineBean

public void defineBean(String name, Object bean)
Defines or removes a bean accessible by name in EL expressions. When a non-null bean is provided, it is stored under the given name. When `null` is provided, the bean with the given name is removed.

Parameters:
  `name` - the bean name
  `bean` - the bean object to define, or `null` to remove the bean