public class MVEL
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
(package private) static boolean |
ADVANCED_DEBUG |
(package private) static java.lang.String |
ADVANCED_DEBUGGING_FILE |
static java.lang.String |
CODENAME |
static boolean |
COMPILER_OPT_ALLOCATE_TYPE_LITERALS_TO_SHARED_SYMBOL_TABLE |
static boolean |
COMPILER_OPT_ALLOW_NAKED_METH_CALL |
static boolean |
COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING |
static boolean |
COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION |
static boolean |
COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS |
(package private) static boolean |
DEBUG_FILE |
static boolean |
INVOKED_METHOD_EXCEPTIONS_BUBBLE |
static java.lang.String |
NAME |
(package private) static boolean |
NO_JIT |
(package private) static boolean |
OPTIMIZER |
static java.lang.String |
VERSION |
static java.lang.String |
VERSION_SUB |
(package private) static boolean |
WEAK_CACHE |
Modifier | Constructor and Description |
---|---|
private |
MVEL() |
Modifier and Type | Method and Description |
---|---|
private static java.lang.Object |
_evalFile(java.io.File file,
java.lang.Object ctx,
VariableResolverFactory factory) |
private static java.lang.Object |
_evalFile(java.io.File file,
java.lang.String encoding,
java.lang.Object ctx,
VariableResolverFactory factory) |
static void |
analysisCompile(char[] expression,
ParserContext ctx)
Performs an analysis compileShared, which will populate the ParserContext with type, input and variable information,
but will not produce a payload.
|
static void |
analysisCompile(java.lang.String expression,
ParserContext ctx) |
static java.lang.Class |
analyze(char[] expression,
ParserContext ctx) |
static java.lang.Class |
analyze(java.lang.String expression,
ParserContext ctx) |
static java.io.Serializable |
compileExpression(char[] expression) |
static java.io.Serializable |
compileExpression(char[] expression,
int start,
int offset,
ParserContext ctx) |
static java.io.Serializable |
compileExpression(char[] expression,
java.util.Map<java.lang.String,java.lang.Object> imports) |
static java.io.Serializable |
compileExpression(char[] expression,
java.util.Map<java.lang.String,java.lang.Object> imports,
java.util.Map<java.lang.String,Interceptor> interceptors) |
static java.io.Serializable |
compileExpression(char[] expression,
java.util.Map<java.lang.String,java.lang.Object> imports,
java.util.Map<java.lang.String,Interceptor> interceptors,
java.lang.String sourceName)
Compiles an expression and returns a Serializable object containing the compiled
expression.
|
static java.io.Serializable |
compileExpression(char[] expression,
ParserContext ctx) |
static java.io.Serializable |
compileExpression(java.lang.String expression)
Compiles an expression and returns a Serializable object containing the compiled expression.
|
static java.io.Serializable |
compileExpression(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> imports)
Compiles an expression and returns a Serializable object containing the compiled expression.
|
static java.io.Serializable |
compileExpression(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> imports,
java.util.Map<java.lang.String,Interceptor> interceptors)
Compiles an expression and returns a Serializable object containing the compiled expression.
|
static java.io.Serializable |
compileExpression(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> imports,
java.util.Map<java.lang.String,Interceptor> interceptors,
java.lang.String sourceName) |
static java.io.Serializable |
compileExpression(java.lang.String expression,
ParserContext ctx)
Compiles an expression, and accepts a
ParserContext instance. |
static java.io.Serializable |
compileGetExpression(char[] expression) |
static java.io.Serializable |
compileGetExpression(char[] expression,
ParserContext ctx) |
static java.io.Serializable |
compileGetExpression(java.lang.String expression) |
static java.io.Serializable |
compileGetExpression(java.lang.String expression,
ParserContext ctx) |
static java.io.Serializable |
compileSetExpression(char[] expression) |
static java.io.Serializable |
compileSetExpression(char[] expression,
java.lang.Class ingressType,
ParserContext ctx) |
static java.io.Serializable |
compileSetExpression(char[] expression,
int start,
int offset,
ParserContext ctx) |
static java.io.Serializable |
compileSetExpression(char[] expression,
ParserContext ctx) |
static java.io.Serializable |
compileSetExpression(java.lang.String expression) |
static java.io.Serializable |
compileSetExpression(java.lang.String expression,
java.lang.Class ingressType,
ParserContext ctx) |
static java.io.Serializable |
compileSetExpression(java.lang.String expression,
ParserContext ctx) |
static java.lang.Object |
eval(char[] expression)
Evaluate an expression and return the value.
|
static <T> T |
eval(char[] expression,
java.lang.Class<T> type) |
static java.lang.Object |
eval(char[] expression,
int start,
int offset,
java.lang.Object ctx,
VariableResolverFactory vars) |
static <T> T |
eval(char[] expression,
int start,
int offset,
java.lang.Object ctx,
VariableResolverFactory vars,
java.lang.Class<T> toType) |
static <T> T |
eval(char[] expression,
java.util.Map<java.lang.String,java.lang.Object> vars,
java.lang.Class<T> toType)
Evaluate an expression with injected variables and return the resultant value.
|
static java.lang.Object |
eval(char[] expression,
java.lang.Object ctx)
Evaluate an expression against a context object and return the value
|
static <T> T |
eval(char[] expression,
java.lang.Object ctx,
java.lang.Class<T> toType)
Evaluate an expression with a context object and return the value.
|
static java.lang.Object |
eval(char[] expression,
java.lang.Object ctx,
java.util.Map vars)
Evaluate an expression against a context object and return the value
|
static <T> T |
eval(char[] expression,
java.lang.Object ctx,
java.util.Map<java.lang.String,java.lang.Object> vars,
java.lang.Class<T> toType)
Evaluate an expression with a context object and injected variables and return the value.
|
static java.lang.Object |
eval(char[] expression,
java.lang.Object ctx,
VariableResolverFactory vars)
Evaluate an expression against a context object and return the value
|
static <T> T |
eval(char[] expression,
java.lang.Object ctx,
VariableResolverFactory vars,
java.lang.Class<T> toType)
Evaluate an expression with a context object and injected variables and return the value.
|
static <T> T |
eval(char[] expression,
VariableResolverFactory vars,
java.lang.Class<T> toType)
Evaluate an expression with injected variables and return the value.
|
static java.lang.Object |
eval(java.lang.String expression)
Evaluate an expression and return the value.
|
static <T> T |
eval(java.lang.String expression,
java.lang.Class<T> toType)
Evaluates an expression and, if necessary, coerces the resultant value to the specified type.
|
static java.lang.Object |
eval(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> vars)
Evaluates an expression against externally injected variables.
|
static <T> T |
eval(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> vars,
java.lang.Class<T> toType)
Evaluates an expression against externally injected variables.
|
static java.lang.Object |
eval(java.lang.String expression,
java.lang.Object ctx)
Evaluate an expression against a context object.
|
static <T> T |
eval(java.lang.String expression,
java.lang.Object ctx,
java.lang.Class<T> toType)
Evaluates an expression against a context object and, if necessary, coerces the resultant value to the specified
type.
|
static java.lang.Object |
eval(java.lang.String expression,
java.lang.Object ctx,
java.util.Map<java.lang.String,java.lang.Object> vars)
Evaluates an expression against a context object and externally injected variables.
|
static <T> T |
eval(java.lang.String expression,
java.lang.Object ctx,
java.util.Map<java.lang.String,java.lang.Object> vars,
java.lang.Class<T> toType)
Evaluates an expression against a context object and externally injected variables.
|
static java.lang.Object |
eval(java.lang.String expression,
java.lang.Object ctx,
VariableResolverFactory resolverFactory)
Evaluates an expression against a context object and injected variables from a
VariableResolverFactory . |
static <T> T |
eval(java.lang.String expression,
java.lang.Object ctx,
VariableResolverFactory vars,
java.lang.Class<T> toType)
Evaluates an expression against a context object and externally injected variables.
|
static java.lang.Object |
eval(java.lang.String expression,
VariableResolverFactory resolverFactory)
Evaluate an expression with externally injected variables via a
VariableResolverFactory . |
static <T> T |
eval(java.lang.String expression,
VariableResolverFactory vars,
java.lang.Class<T> toType)
Evaluates an expression against externally injected variables and, if necessary, coerces the resultant value
to the specified type.
|
static java.lang.Object |
evalFile(java.io.File file)
Evaluate a script from a file and return the resultant value.
|
static java.lang.Object |
evalFile(java.io.File file,
java.util.Map<java.lang.String,java.lang.Object> vars)
Evaluate a script from a file with injected variables and return the resultant value.
|
static java.lang.Object |
evalFile(java.io.File file,
java.lang.Object ctx)
Evaluate a script from a file, against a context object and return the resultant value.
|
static java.lang.Object |
evalFile(java.io.File file,
java.lang.Object ctx,
java.util.Map<java.lang.String,java.lang.Object> vars)
Evaluate a script from a file with injected variables and a context object, then return the resultant value.
|
static java.lang.Object |
evalFile(java.io.File file,
java.lang.Object ctx,
VariableResolverFactory vars)
Evaluate a script from a file with injected variables and a context object, then return the resultant value.
|
static java.lang.Object |
evalFile(java.io.File file,
java.lang.String encoding) |
static java.lang.Object |
evalFile(java.io.File file,
java.lang.String encoding,
java.lang.Object ctx) |
static java.lang.Object |
evalFile(java.io.File file,
java.lang.String encoding,
java.lang.Object ctx,
java.util.Map<java.lang.String,java.lang.Object> vars) |
static java.lang.Object |
evalFile(java.io.File file,
java.lang.String encoding,
java.lang.Object ctx,
VariableResolverFactory vars) |
static java.lang.Boolean |
evalToBoolean(java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> vars)
Evaluate an expression in Boolean-only with injected variables.
|
static java.lang.Boolean |
evalToBoolean(java.lang.String expression,
java.lang.Object ctx)
Evaluate an expression in Boolean-only mode against a root context object.
|
static java.lang.Boolean |
evalToBoolean(java.lang.String expression,
java.lang.Object ctx,
java.util.Map<java.lang.String,java.lang.Object> vars)
Evaluate an expression in Boolean-only mode against a root context object and injected variables.
|
static java.lang.Boolean |
evalToBoolean(java.lang.String expression,
java.lang.Object ctx,
VariableResolverFactory vars)
Evaluate an expression in Boolean-only mode against a root context object and injected variables.
|
static java.lang.Boolean |
evalToBoolean(java.lang.String expression,
VariableResolverFactory vars)
Evaluate an expression in Boolean-only with injected variables.
|
static java.lang.String |
evalToString(java.lang.String expression)
Evaluates an expression and returns the resultant value as a String.
|
static java.lang.String |
evalToString(java.lang.String expression,
java.util.Map vars)
Evaluates an expression and returns the resultant value as a String.
|
static java.lang.String |
evalToString(java.lang.String expression,
java.lang.Object ctx)
Evaluates an expression and returns the resultant value as a String.
|
static java.lang.String |
evalToString(java.lang.String expression,
java.lang.Object ctx,
java.util.Map vars)
Evaluates an expression and returns the resultant value as a String.
|
static java.lang.String |
evalToString(java.lang.String expression,
java.lang.Object ctx,
VariableResolverFactory vars)
Evaluates an expression and returns the resultant value as a String.
|
static java.lang.String |
evalToString(java.lang.String expression,
VariableResolverFactory vars)
Evaluates an expression and returns the resultant value as a String.
|
static java.lang.Object[] |
executeAllExpression(java.io.Serializable[] compiledExpressions,
java.lang.Object ctx,
VariableResolverFactory vars) |
static java.lang.Object |
executeDebugger(CompiledExpression expression,
java.lang.Object ctx,
VariableResolverFactory vars) |
static void |
executeExpression(java.lang.Iterable<CompiledExpression> compiledExpression) |
static void |
executeExpression(java.lang.Iterable<CompiledExpression> compiledExpression,
java.util.Map vars) |
static void |
executeExpression(java.lang.Iterable<CompiledExpression> compiledExpression,
java.lang.Object ctx) |
static void |
executeExpression(java.lang.Iterable<CompiledExpression> compiledExpression,
java.lang.Object ctx,
java.util.Map vars) |
static void |
executeExpression(java.lang.Iterable<CompiledExpression> compiledExpression,
java.lang.Object ctx,
VariableResolverFactory vars) |
static java.lang.Object |
executeExpression(java.lang.Object compiledExpression) |
static java.lang.Object |
executeExpression(java.lang.Object compiledExpression,
java.util.Map vars)
Executes a compiled expression.
|
static <T> T |
executeExpression(java.lang.Object compiledExpression,
java.util.Map vars,
java.lang.Class<T> toType)
Execute a compiled expression and convert the result to a type
|
static java.lang.Object |
executeExpression(java.lang.Object compiledExpression,
java.lang.Object ctx)
Executes a compiled expression.
|
static <T> T |
executeExpression(java.lang.Object compiledExpression,
java.lang.Object ctx,
java.lang.Class<T> toType)
Execute a compiled expression and convert the result to a type.
|
static java.lang.Object |
executeExpression(java.lang.Object compiledExpression,
java.lang.Object ctx,
java.util.Map vars)
Executes a compiled expression.
|
static <T> T |
executeExpression(java.lang.Object compiledExpression,
java.lang.Object ctx,
java.util.Map vars,
java.lang.Class<T> toType)
Execute a compiled expression and convert the result to a type
|
static java.lang.Object |
executeExpression(java.lang.Object compiledExpression,
java.lang.Object ctx,
VariableResolverFactory resolverFactory) |
static <T> T |
executeExpression(java.lang.Object compiledExpression,
java.lang.Object ctx,
VariableResolverFactory vars,
java.lang.Class<T> toType) |
static java.lang.Object |
executeExpression(java.lang.Object compiledExpression,
VariableResolverFactory factory)
Executes a compiled expression.
|
static void |
executeSetExpression(java.io.Serializable compiledSet,
java.lang.Object ctx,
java.lang.Object value) |
static void |
executeSetExpression(java.io.Serializable compiledSet,
java.lang.Object ctx,
VariableResolverFactory vrf,
java.lang.Object value) |
static java.lang.String |
getDebuggingOutputFileName() |
static java.lang.Object |
getProperty(java.lang.String property,
java.lang.Object ctx) |
static java.lang.reflect.Method |
getStaticMethod(java.lang.Class cls,
java.lang.String methodName,
java.lang.Class[] signature)
A simple utility method to get a static method from a class with no checked exception.
|
static boolean |
isAdvancedDebugging() |
static boolean |
isFileDebugging() |
static java.lang.String |
parseMacros(java.lang.String input,
java.util.Map<java.lang.String,Macro> macros) |
static java.lang.String |
preprocess(char[] input,
PreProcessor[] preprocessors) |
static java.lang.String |
preprocess(java.lang.String input,
PreProcessor[] preprocessors) |
static void |
setProperty(java.lang.Object ctx,
java.lang.String property,
java.lang.Object value) |
public static final java.lang.String NAME
public static final java.lang.String VERSION
public static final java.lang.String VERSION_SUB
public static final java.lang.String CODENAME
static boolean DEBUG_FILE
static java.lang.String ADVANCED_DEBUGGING_FILE
static boolean ADVANCED_DEBUG
static boolean WEAK_CACHE
static boolean NO_JIT
public static boolean INVOKED_METHOD_EXCEPTIONS_BUBBLE
public static boolean COMPILER_OPT_ALLOW_NAKED_METH_CALL
public static boolean COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING
public static boolean COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION
public static boolean COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS
public static boolean COMPILER_OPT_ALLOCATE_TYPE_LITERALS_TO_SHARED_SYMBOL_TABLE
static boolean OPTIMIZER
public static boolean isAdvancedDebugging()
public static java.lang.String getDebuggingOutputFileName()
public static boolean isFileDebugging()
public static java.lang.Object eval(java.lang.String expression)
expression
- A String containing the expression to be evaluated.public static java.lang.Object eval(java.lang.String expression, java.lang.Object ctx)
MVEL.eval("foo == 1", ctx);
In this case, the identifier foo would be resolved against the ctx object. So it would have
the equivalent of: ctc.getFoo() == 1 in Java.expression
- A String containing the expression to be evaluated.ctx
- The context object to evaluate against.public static java.lang.Object eval(java.lang.String expression, VariableResolverFactory resolverFactory)
VariableResolverFactory
. A factory
provides the means by which MVEL can resolve external variables. MVEL contains a straight-forward implementation
for wrapping Maps: MapVariableResolverFactory
, which is used implicitly when calling overloaded methods
in this class that use Maps.
An example:
Map varsMap = new HashMap();
varsMap.put("x", 5);
varsMap.put("y", 2);
VariableResolverFactory factory = new MapVariableResolverFactory(varsMap);
Integer i = (Integer) MVEL.eval("x * y", factory);
assert i == 10;
expression
- A String containing the expression to be evaluated.resolverFactory
- The instance of the VariableResolverFactory to be used.public static java.lang.Object eval(java.lang.String expression, java.lang.Object ctx, VariableResolverFactory resolverFactory)
VariableResolverFactory
.
This method of execution will prefer to find variables from the factory and then from the context.expression
- A string containing the expression to be evaluatedctx
- The context object to evaluate against.resolverFactory
- The instance of the VariableResolverFactory to be used.eval(String, org.mvel2.integration.VariableResolverFactory)
public static java.lang.Object eval(java.lang.String expression, java.util.Map<java.lang.String,java.lang.Object> vars)
MapVariableResolverFactory
expression
- A string containing the expression to be evaluated.vars
- A map of vars to be injectedeval(String, org.mvel2.integration.VariableResolverFactory)
public static java.lang.Object eval(java.lang.String expression, java.lang.Object ctx, java.util.Map<java.lang.String,java.lang.Object> vars)
MapVariableResolverFactory
expression
- A string containing the expression to be evaluated.ctx
- The context object to evaluate against.vars
- A map of vars to be injectedeval(String, VariableResolverFactory)
public static <T> T eval(java.lang.String expression, java.lang.Class<T> toType)
Float output = MVEL.eval("5 + 5", Float.class);
This converts an expression that would otherwise return an Integer to a Float.T
- typeexpression
- A string containing the expression to be evaluated.toType
- The target type that the resultant value will be converted to, if necessary.public static <T> T eval(java.lang.String expression, java.lang.Object ctx, java.lang.Class<T> toType)
T
- typeexpression
- A string containing the expression to be evaluated.ctx
- The context object to evaluate against.toType
- The target type that the resultant value will be converted to, if necessary.eval(String, Class)
public static <T> T eval(java.lang.String expression, VariableResolverFactory vars, java.lang.Class<T> toType)
T
- typeexpression
- A string containing the expression to be evaluatedvars
- The variables to be injectedtoType
- The target type that the resultant value will be converted to, if necessary.eval(String, VariableResolverFactory)
,
eval(String, Class)
public static <T> T eval(java.lang.String expression, java.util.Map<java.lang.String,java.lang.Object> vars, java.lang.Class<T> toType)
MapVariableResolverFactory
T
- typeexpression
- A string containing the expression to be evaluated.vars
- A map of vars to be injectedtoType
- The target type the resultant value will be converted to, if necessary.eval(String, org.mvel2.integration.VariableResolverFactory)
public static <T> T eval(java.lang.String expression, java.lang.Object ctx, VariableResolverFactory vars, java.lang.Class<T> toType)
T
- typeexpression
- A string containing the expression to be evaluated.ctx
- The context object to evaluate againstvars
- The vars to be injectedtoType
- The target type that the resultant value will be converted to, if necessary.eval(String, Object, VariableResolverFactory)
,
eval(String, Class)
public static <T> T eval(java.lang.String expression, java.lang.Object ctx, java.util.Map<java.lang.String,java.lang.Object> vars, java.lang.Class<T> toType)
T
- typeexpression
- A string containing the expression to be evaluated.ctx
- The context object to evaluate againstvars
- A Map of variables to be injected.toType
- The target type that the resultant value will be converted to, if necessary.eval(String, Object, VariableResolverFactory)
,
eval(String, Class)
public static java.lang.String evalToString(java.lang.String expression)
expression
- A string containing the expressino to be evaluated.public static java.lang.String evalToString(java.lang.String expression, java.lang.Object ctx)
expression
- A string containing the expressino to be evaluated.ctx
- The context object to evaluate againsteval(String, Object)
public static java.lang.String evalToString(java.lang.String expression, VariableResolverFactory vars)
expression
- A string containing the expressino to be evaluated.vars
- The variables to be injectedeval(String, VariableResolverFactory)
public static java.lang.String evalToString(java.lang.String expression, java.util.Map vars)
expression
- A string containing the expressino to be evaluated.vars
- A Map of variables to be injectedeval(String, Map)
public static java.lang.String evalToString(java.lang.String expression, java.lang.Object ctx, VariableResolverFactory vars)
expression
- A string containing the expressino to be evaluated.ctx
- The context object to evaluate against.vars
- The variables to be injectedeval(String, Map)
public static java.lang.String evalToString(java.lang.String expression, java.lang.Object ctx, java.util.Map vars)
expression
- A string containing the expressino to be evaluated.ctx
- The context object to evaluate against.vars
- A Map of variables to be injectedeval(String, Map)
public static java.lang.Object eval(char[] expression)
expression
- A char[] containing the expression to be evaluated.eval(String)
public static java.lang.Object eval(char[] expression, java.lang.Object ctx)
expression
- A char[] containing the expression to be evaluated.ctx
- The context object to evaluate againsteval(String, Object)
public static <T> T eval(char[] expression, java.lang.Class<T> type)
public static java.lang.Object eval(char[] expression, java.lang.Object ctx, VariableResolverFactory vars)
expression
- A char[] containing the expression to be evaluated.ctx
- The context object to evaluate againstvars
- The variables to be injectedeval(String, Object, VariableResolverFactory)
public static java.lang.Object eval(char[] expression, int start, int offset, java.lang.Object ctx, VariableResolverFactory vars)
public static <T> T eval(char[] expression, int start, int offset, java.lang.Object ctx, VariableResolverFactory vars, java.lang.Class<T> toType)
public static java.lang.Object eval(char[] expression, java.lang.Object ctx, java.util.Map vars)
expression
- A char[] containing the expression to be evaluated.ctx
- The context object to evaluate againstvars
- A Map of variables to be injectedeval(String, Object, Map)
public static <T> T eval(char[] expression, java.lang.Object ctx, java.util.Map<java.lang.String,java.lang.Object> vars, java.lang.Class<T> toType)
T
- typeexpression
- A char[] containing the expression to be evaluated.ctx
- The context object to evaluate againstvars
- A Map of variables to be injectedtoType
- The target type the resultant value will be converted to, if necessary.eval(String, Object, Map, Class)
public static <T> T eval(char[] expression, java.lang.Object ctx, java.lang.Class<T> toType)
T
- typeexpression
- A char[] containing the expression to be evaluated.ctx
- The context object to evaluate againsttoType
- The target type the resultant value will be converted to, if necessary.eval(String, Object, Class)
public static <T> T eval(char[] expression, java.lang.Object ctx, VariableResolverFactory vars, java.lang.Class<T> toType)
T
- typeexpression
- A char[] containing the expression to be evaluated.ctx
- The context object to evaluate againstvars
- The variables to be injectedtoType
- The target type the resultant value will be converted to, if necessary.eval(String, Object, VariableResolverFactory, Class)
public static <T> T eval(char[] expression, VariableResolverFactory vars, java.lang.Class<T> toType)
T
- typeexpression
- A char[] containing the expression to be evaluated.vars
- The variables to be injectedtoType
- The target type the resultant value will be converted to, if necessary.eval(String, VariableResolverFactory, Class)
public static <T> T eval(char[] expression, java.util.Map<java.lang.String,java.lang.Object> vars, java.lang.Class<T> toType)
T
- typeexpression
- A char[] containing the expression to be evaluated.vars
- The variables to be injectedtoType
- The target type the resultant value will be converted to, if necessary.eval(String, Map, Class)
public static java.lang.Object evalFile(java.io.File file) throws java.io.IOException
file
- The file to processjava.io.IOException
- Exception thrown if there is an IO problem accessing the file.public static java.lang.Object evalFile(java.io.File file, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static java.lang.Object evalFile(java.io.File file, java.lang.Object ctx) throws java.io.IOException
file
- The file to processctx
- The context to evaluate the script against.java.io.IOException
- Exception thrown if there is an IO problem accessing the file.public static java.lang.Object evalFile(java.io.File file, java.lang.String encoding, java.lang.Object ctx) throws java.io.IOException
java.io.IOException
public static java.lang.Object evalFile(java.io.File file, java.util.Map<java.lang.String,java.lang.Object> vars) throws java.io.IOException
file
- The file to processvars
- Variables to be injectedjava.io.IOException
- Exception thrown if there is an IO problem accessing the file.public static java.lang.Object evalFile(java.io.File file, java.lang.Object ctx, java.util.Map<java.lang.String,java.lang.Object> vars) throws java.io.IOException
file
- The file to processctx
- The context to evaluate the script against.vars
- Variables to be injectedjava.io.IOException
- Exception thrown if there is an IO problem accessing the file.public static java.lang.Object evalFile(java.io.File file, java.lang.String encoding, java.lang.Object ctx, java.util.Map<java.lang.String,java.lang.Object> vars) throws java.io.IOException
java.io.IOException
public static java.lang.Object evalFile(java.io.File file, java.lang.Object ctx, VariableResolverFactory vars) throws java.io.IOException
file
- The file to processctx
- The context to evaluate the script against.vars
- Variables to be injectedjava.io.IOException
- Exception thrown if there is an IO problem accessing the file.public static java.lang.Object evalFile(java.io.File file, java.lang.String encoding, java.lang.Object ctx, VariableResolverFactory vars) throws java.io.IOException
java.io.IOException
private static java.lang.Object _evalFile(java.io.File file, java.lang.Object ctx, VariableResolverFactory factory) throws java.io.IOException
java.io.IOException
private static java.lang.Object _evalFile(java.io.File file, java.lang.String encoding, java.lang.Object ctx, VariableResolverFactory factory) throws java.io.IOException
java.io.IOException
public static java.lang.Boolean evalToBoolean(java.lang.String expression, java.lang.Object ctx, java.util.Map<java.lang.String,java.lang.Object> vars)
expression
- A string containing the expression to be evaluated.ctx
- The context against which to evaluate the expressionvars
- The variables to be injectedpublic static java.lang.Boolean evalToBoolean(java.lang.String expression, java.lang.Object ctx)
expression
- A string containing the expression to be evaluated.ctx
- The context against which to evaluate the expressionpublic static java.lang.Boolean evalToBoolean(java.lang.String expression, java.lang.Object ctx, VariableResolverFactory vars)
expression
- A string containing the expression to be evaluated.ctx
- The context against which to evaluate the expressionvars
- The variables to be injectedpublic static java.lang.Boolean evalToBoolean(java.lang.String expression, VariableResolverFactory vars)
expression
- A string containing the expression to be evaluated.vars
- The variables to be injectedpublic static java.lang.Boolean evalToBoolean(java.lang.String expression, java.util.Map<java.lang.String,java.lang.Object> vars)
expression
- A string containing the expression to be evaluated.vars
- The variables to be injectedpublic static void analysisCompile(char[] expression, ParserContext ctx)
expression
- - the expression to analyzectx
- - the parser contextpublic static void analysisCompile(java.lang.String expression, ParserContext ctx)
public static java.lang.Class analyze(char[] expression, ParserContext ctx)
public static java.lang.Class analyze(java.lang.String expression, ParserContext ctx)
public static java.io.Serializable compileExpression(java.lang.String expression)
// Compile the expression
Serializable compiled = MVEL.compileExpression("x * 10");
// Create a Map to hold the variables.
Map vars = new HashMap();
// Create a factory to envelop the variable map
VariableResolverFactory factory = new MapVariableResolverFactory(vars);
int total = 0;
for (int i = 0; i < 100; i++) {
// Update the 'x' variable.
vars.put("x", i);
// Execute the expression against the compiled payload and factory, and add the result to the total variable.
total += (Integer) MVEL.executeExpression(compiled, factory);
}
// Total should be 49500
assert total == 49500;
The above example demonstrates a compiled expression being reused ina tight, closed, loop. Doing this greatly
improves performance as re-parsing of the expression is not required, and the runtime can dynamically compileShared
the expression to bytecode of necessary.expression
- A String contaiing the expression to be compiled.public static java.io.Serializable compileExpression(java.lang.String expression, java.util.Map<java.lang.String,java.lang.Object> imports)
Map imports = new HashMap();
imports.put("HashMap", java.util.HashMap.class); // import a class
imports.put("time", MVEL.getStaticMethod(System.class, "currentTimeMillis", new Class[0])); // import a static method
// Compile the expression
Serializable compiled = MVEL.compileExpression("map = new HashMap(); map.put('time', time()); map.time");
// Execute with a blank Map to allow vars to be declared.
Long val = (Long) MVEL.executeExpression(compiled, new HashMap());
assert val > 0;
expression
- A String contaiing the expression to be compiled.imports
- A String-Class/String-Method pair Map containing imports for the compiler.public static java.io.Serializable compileExpression(java.lang.String expression, java.util.Map<java.lang.String,java.lang.Object> imports, java.util.Map<java.lang.String,Interceptor> interceptors)
compileExpression(String, Map)
for information on
imports. The imports parameter in this method is optional and it is safe to pass a null
value. Interceptors
are markers within an expression that allow external hooks
to be tied into the expression.
// Create a Map to hold the interceptors.
Map interceptors = new HashMap();
// Create a simple interceptor.
Interceptor logInterceptor = new Interceptor() {
public int doBefore(ASTNode node, VariableResolverFactory factory) {
System.out.println("Interceptor called before!");
}
public int doAfter(Object exitValue, ASTNode node, VariableResolverFactory factory) {
System.out.println("Interceptor called after!");
}
};
// Add the interceptor to the Map.
interceptors.put("log", logInterceptor);
// Create an expression
String expr = "list = [1,2,3,4,5]; @log for (item : list) { System.out.println(item); };
Serializable compiled = MVEL.compileExpression(expr, null, interceptors);
// Execute expression with a blank Map to allow vars to be declared.
MVEL.executeExpression(compiled, new HashMap());
The above example demonstrates inserting an interceptor into a piece of code. The @log interceptor
wraps the subsequent statement. In this case, the interceptor is fired before the for loop and
after the for loop finishes.expression
- A String containing the expression to be evaluated.imports
- A String-Class/String-Method pair Map containing imports for the compiler.interceptors
- A Map of registered interceptors.public static java.io.Serializable compileExpression(java.lang.String expression, ParserContext ctx)
ParserContext
instance. The ParserContext object is the
fine-grained configuration object for the MVEL parser and compiler.expression
- A string containing the expression to be compiled.ctx
- The parser contextpublic static java.io.Serializable compileExpression(char[] expression, int start, int offset, ParserContext ctx)
public static java.io.Serializable compileExpression(java.lang.String expression, java.util.Map<java.lang.String,java.lang.Object> imports, java.util.Map<java.lang.String,Interceptor> interceptors, java.lang.String sourceName)
public static java.io.Serializable compileExpression(char[] expression, ParserContext ctx)
public static java.io.Serializable compileExpression(char[] expression, java.util.Map<java.lang.String,java.lang.Object> imports, java.util.Map<java.lang.String,Interceptor> interceptors, java.lang.String sourceName)
expression
- The expression to be compiledimports
- Imported classesinterceptors
- Map of named interceptossourceName
- The name of the source file being evaluated (optional)public static java.io.Serializable compileExpression(char[] expression)
public static java.io.Serializable compileExpression(char[] expression, java.util.Map<java.lang.String,java.lang.Object> imports)
public static java.io.Serializable compileExpression(char[] expression, java.util.Map<java.lang.String,java.lang.Object> imports, java.util.Map<java.lang.String,Interceptor> interceptors)
public static java.io.Serializable compileGetExpression(java.lang.String expression)
public static java.io.Serializable compileGetExpression(java.lang.String expression, ParserContext ctx)
public static java.io.Serializable compileGetExpression(char[] expression)
public static java.io.Serializable compileGetExpression(char[] expression, ParserContext ctx)
public static java.io.Serializable compileSetExpression(java.lang.String expression)
public static java.io.Serializable compileSetExpression(java.lang.String expression, ParserContext ctx)
public static java.io.Serializable compileSetExpression(java.lang.String expression, java.lang.Class ingressType, ParserContext ctx)
public static java.io.Serializable compileSetExpression(char[] expression)
public static java.io.Serializable compileSetExpression(char[] expression, ParserContext ctx)
public static java.io.Serializable compileSetExpression(char[] expression, int start, int offset, ParserContext ctx)
public static java.io.Serializable compileSetExpression(char[] expression, java.lang.Class ingressType, ParserContext ctx)
public static void executeSetExpression(java.io.Serializable compiledSet, java.lang.Object ctx, java.lang.Object value)
public static void executeSetExpression(java.io.Serializable compiledSet, java.lang.Object ctx, VariableResolverFactory vrf, java.lang.Object value)
public static java.lang.Object executeExpression(java.lang.Object compiledExpression)
public static java.lang.Object executeExpression(java.lang.Object compiledExpression, java.lang.Object ctx, java.util.Map vars)
compiledExpression
- -ctx
- -vars
- -compileExpression(String)
public static java.lang.Object executeExpression(java.lang.Object compiledExpression, java.lang.Object ctx, VariableResolverFactory resolverFactory)
public static java.lang.Object executeExpression(java.lang.Object compiledExpression, VariableResolverFactory factory)
compiledExpression
- -factory
- -compileExpression(String)
public static java.lang.Object executeExpression(java.lang.Object compiledExpression, java.lang.Object ctx)
compiledExpression
- -ctx
- -compileExpression(String)
public static java.lang.Object executeExpression(java.lang.Object compiledExpression, java.util.Map vars)
compiledExpression
- -vars
- -compileExpression(String)
public static <T> T executeExpression(java.lang.Object compiledExpression, java.lang.Object ctx, java.util.Map vars, java.lang.Class<T> toType)
T
- typecompiledExpression
- -ctx
- -vars
- -toType
- -public static <T> T executeExpression(java.lang.Object compiledExpression, java.lang.Object ctx, VariableResolverFactory vars, java.lang.Class<T> toType)
public static <T> T executeExpression(java.lang.Object compiledExpression, java.util.Map vars, java.lang.Class<T> toType)
T
- typecompiledExpression
- -vars
- -toType
- -public static <T> T executeExpression(java.lang.Object compiledExpression, java.lang.Object ctx, java.lang.Class<T> toType)
T
- typecompiledExpression
- -ctx
- -toType
- -public static void executeExpression(java.lang.Iterable<CompiledExpression> compiledExpression)
public static void executeExpression(java.lang.Iterable<CompiledExpression> compiledExpression, java.lang.Object ctx)
public static void executeExpression(java.lang.Iterable<CompiledExpression> compiledExpression, java.util.Map vars)
public static void executeExpression(java.lang.Iterable<CompiledExpression> compiledExpression, java.lang.Object ctx, java.util.Map vars)
public static void executeExpression(java.lang.Iterable<CompiledExpression> compiledExpression, java.lang.Object ctx, VariableResolverFactory vars)
public static java.lang.Object[] executeAllExpression(java.io.Serializable[] compiledExpressions, java.lang.Object ctx, VariableResolverFactory vars)
public static java.lang.Object executeDebugger(CompiledExpression expression, java.lang.Object ctx, VariableResolverFactory vars)
public static java.lang.String parseMacros(java.lang.String input, java.util.Map<java.lang.String,Macro> macros)
public static java.lang.String preprocess(char[] input, PreProcessor[] preprocessors)
public static java.lang.String preprocess(java.lang.String input, PreProcessor[] preprocessors)
public static java.lang.Object getProperty(java.lang.String property, java.lang.Object ctx)
public static void setProperty(java.lang.Object ctx, java.lang.String property, java.lang.Object value)
public static java.lang.reflect.Method getStaticMethod(java.lang.Class cls, java.lang.String methodName, java.lang.Class[] signature)
cls
- The class containing the static methodmethodName
- The method namesignature
- The signature of the method