/** * Create a parser with default settings. */ public SpelExpressionParser() { this.configuration = new SpelParserConfiguration(); }
/** * Perform expression compilation. This will only succeed once exit descriptors for all nodes have * been determined. If the compilation fails and has failed more than 100 times the expression is * no longer considered suitable for compilation. */ public boolean compileExpression() { if (this.failedAttempts > FAILED_ATTEMPTS_THRESHOLD) { // Don't try again return false; } if (this.compiledAst == null) { synchronized (this.expression) { // Possibly compiled by another thread before this thread got into the sync block if (this.compiledAst != null) { return true; } SpelCompiler compiler = SpelCompiler.getCompiler(this.configuration.getCompilerClassLoader()); this.compiledAst = compiler.compile(this.ast); if (this.compiledAst == null) { this.failedAttempts++; } } } return (this.compiledAst != null); }
/** * Compile the expression if it has been evaluated more than the threshold number * of times to trigger compilation. * @param expressionState the expression state used to determine compilation mode */ private void checkCompile(ExpressionState expressionState) { this.interpretedCount++; SpelCompilerMode compilerMode = expressionState.getConfiguration().getCompilerMode(); if (compilerMode != SpelCompilerMode.OFF) { if (compilerMode == SpelCompilerMode.IMMEDIATE) { if (this.interpretedCount > 1) { compileExpression(); } } else { // compilerMode = SpelCompilerMode.MIXED if (this.interpretedCount > INTERPRETED_COUNT_THRESHOLD) { compileExpression(); } } } }
state.getTypeConverter(), state.getConfiguration().isAutoGrowCollections(), state.getConfiguration().getMaximumAutoGrowSize());
state.getTypeConverter(), state.getConfiguration().isAutoGrowCollections(), state.getConfiguration().getMaximumAutoGrowSize());
public ExpressionState(EvaluationContext context, TypedValue rootObject) { this(context, rootObject, new SpelParserConfiguration(false, false)); }
@Override @Nullable public Object getValue(EvaluationContext context, Object rootObject) throws EvaluationException { Assert.notNull(context, "EvaluationContext is required"); if (this.compiledAst != null) { try { return this.compiledAst.getValue(rootObject, context); } catch (Throwable ex) { // If running in mixed mode, revert to interpreted if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) { this.interpretedCount = 0; this.compiledAst = null; } else { // Running in SpelCompilerMode.immediate mode - propagate exception to caller throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION); } } } ExpressionState expressionState = new ExpressionState(context, toTypedValue(rootObject), this.configuration); Object result = this.ast.getValue(expressionState); checkCompile(expressionState); return result; }
state.getTypeConverter(), state.getConfiguration().isAutoGrowCollections(), state.getConfiguration().getMaximumAutoGrowSize());
/** * Perform expression compilation. This will only succeed once exit descriptors for all nodes have * been determined. If the compilation fails and has failed more than 100 times the expression is * no longer considered suitable for compilation. */ public boolean compileExpression() { if (this.failedAttempts > FAILED_ATTEMPTS_THRESHOLD) { // Don't try again return false; } if (this.compiledAst == null) { synchronized (this.expression) { // Possibly compiled by another thread before this thread got into the sync block if (this.compiledAst != null) { return true; } SpelCompiler compiler = SpelCompiler.getCompiler(this.configuration.getCompilerClassLoader()); this.compiledAst = compiler.compile(this.ast); if (this.compiledAst == null) { this.failedAttempts++; } } } return (this.compiledAst != null); }
/** * Create a new {@code StandardBeanExpressionResolver} with the given bean class loader, * using it as the basis for expression compilation. * @param beanClassLoader the factory's bean class loader */ public StandardBeanExpressionResolver(@Nullable ClassLoader beanClassLoader) { this.expressionParser = new SpelExpressionParser(new SpelParserConfiguration(null, beanClassLoader)); }
@Override @Nullable public Object getValue(EvaluationContext context) throws EvaluationException { Assert.notNull(context, "EvaluationContext is required"); if (this.compiledAst != null) { try { return this.compiledAst.getValue(context.getRootObject().getValue(), context); } catch (Throwable ex) { // If running in mixed mode, revert to interpreted if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) { this.interpretedCount = 0; this.compiledAst = null; } else { // Running in SpelCompilerMode.immediate mode - propagate exception to caller throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION); } } } ExpressionState expressionState = new ExpressionState(context, this.configuration); Object result = this.ast.getValue(expressionState); checkCompile(expressionState); return result; }
/** * Perform expression compilation. This will only succeed once exit descriptors for all nodes have * been determined. If the compilation fails and has failed more than 100 times the expression is * no longer considered suitable for compilation. */ public boolean compileExpression() { if (this.failedAttempts > FAILED_ATTEMPTS_THRESHOLD) { // Don't try again return false; } if (this.compiledAst == null) { synchronized (this.expression) { // Possibly compiled by another thread before this thread got into the sync block if (this.compiledAst != null) { return true; } SpelCompiler compiler = SpelCompiler.getCompiler(this.configuration.getCompilerClassLoader()); this.compiledAst = compiler.compile(this.ast); if (this.compiledAst == null) { this.failedAttempts++; } } } return (this.compiledAst != null); }
/** * Create a parser with default settings. */ public SpelExpressionParser() { this.configuration = new SpelParserConfiguration(); }
if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) { this.interpretedCount = 0; this.compiledAst = null;
public ExpressionState(EvaluationContext context, TypedValue rootObject) { this(context, rootObject, new SpelParserConfiguration(false, false)); }
if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) { this.interpretedCount = 0; this.compiledAst = null;
/** * Create a new {@code StandardBeanExpressionResolver} with the given bean class loader, * using it as the basis for expression compilation. * @param beanClassLoader the factory's bean class loader */ public StandardBeanExpressionResolver(@Nullable ClassLoader beanClassLoader) { this.expressionParser = new SpelExpressionParser(new SpelParserConfiguration(null, beanClassLoader)); }
@Override @Nullable public Object getValue(Object rootObject) throws EvaluationException { if (this.compiledAst != null) { try { return this.compiledAst.getValue(rootObject, getEvaluationContext()); } catch (Throwable ex) { // If running in mixed mode, revert to interpreted if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) { this.interpretedCount = 0; this.compiledAst = null; } else { // Running in SpelCompilerMode.immediate mode - propagate exception to caller throw new SpelEvaluationException(ex, SpelMessage.EXCEPTION_RUNNING_COMPILED_EXPRESSION); } } } ExpressionState expressionState = new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration); Object result = this.ast.getValue(expressionState); checkCompile(expressionState); return result; }
public ExpressionState(EvaluationContext context) { this(context, context.getRootObject(), new SpelParserConfiguration(false, false)); }
/** * Compile the expression if it has been evaluated more than the threshold number * of times to trigger compilation. * @param expressionState the expression state used to determine compilation mode */ private void checkCompile(ExpressionState expressionState) { this.interpretedCount++; SpelCompilerMode compilerMode = expressionState.getConfiguration().getCompilerMode(); if (compilerMode != SpelCompilerMode.OFF) { if (compilerMode == SpelCompilerMode.IMMEDIATE) { if (this.interpretedCount > 1) { compileExpression(); } } else { // compilerMode = SpelCompilerMode.MIXED if (this.interpretedCount > INTERPRETED_COUNT_THRESHOLD) { compileExpression(); } } } }