Java Code Examples for org.springframework.expression.spel.SpelCompilerMode

The following examples show how to use org.springframework.expression.spel.SpelCompilerMode. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: SpelExpression.java    License: MIT License 6 votes vote down vote up
@Override
@Nullable
public Object getValue() throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			EvaluationContext context = getEvaluationContext();
			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.set(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(), this.configuration);
	Object result = this.ast.getValue(expressionState);
	checkCompile(expressionState);
	return result;
}
 
Example 2
Source Project: spring-analysis-note   Source File: SpelExpression.java    License: MIT License 6 votes vote down vote up
@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.set(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;
}
 
Example 3
Source Project: spring-analysis-note   Source File: SpelExpression.java    License: MIT License 6 votes vote down vote up
/**
 * 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.incrementAndGet();
	SpelCompilerMode compilerMode = expressionState.getConfiguration().getCompilerMode();
	if (compilerMode != SpelCompilerMode.OFF) {
		if (compilerMode == SpelCompilerMode.IMMEDIATE) {
			if (this.interpretedCount.get() > 1) {
				compileExpression();
			}
		}
		else {
			// compilerMode = SpelCompilerMode.MIXED
			if (this.interpretedCount.get() > INTERPRETED_COUNT_THRESHOLD) {
				compileExpression();
			}
		}
	}
}
 
Example 4
Source Project: java-technology-stack   Source File: SpelExpression.java    License: MIT License 6 votes vote down vote up
@Override
@Nullable
public Object getValue() throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			EvaluationContext context = getEvaluationContext();
			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(getEvaluationContext(), this.configuration);
	Object result = this.ast.getValue(expressionState);
	checkCompile(expressionState);
	return result;
}
 
Example 5
Source Project: java-technology-stack   Source File: SpelExpression.java    License: MIT License 6 votes vote down vote up
@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;
}
 
Example 6
Source Project: java-technology-stack   Source File: SpelExpression.java    License: MIT License 6 votes vote down vote up
/**
 * 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();
			}
		}
	}
}
 
Example 7
Source Project: lams   Source File: SpelExpression.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object getValue(Object rootObject) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			return this.compiledAst.getValue(rootObject, evaluationContext);
		}
		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;
}
 
Example 8
Source Project: lams   Source File: SpelExpression.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
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;
}
 
Example 9
Source Project: lams   Source File: SpelExpression.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
			}
		}
	}
}
 
Example 10
Source Project: spring4-understanding   Source File: SpelExpression.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object getValue() throws EvaluationException {
	Object result;
	if (this.compiledAst != null) {
		try {
			TypedValue contextRoot = evaluationContext == null ? null : evaluationContext.getRootObject();
			return this.compiledAst.getValue(contextRoot == null ? null : contextRoot.getValue(), evaluationContext);
		}
		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(), this.configuration);
	result = this.ast.getValue(expressionState);
	checkCompile(expressionState);
	return result;
}
 
Example 11
Source Project: spring4-understanding   Source File: SpelExpression.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object getValue(Object rootObject) throws EvaluationException {
	Object result;
	if (this.compiledAst != null) {
		try {
			return this.compiledAst.getValue(rootObject, evaluationContext);
		}
		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);
	result = this.ast.getValue(expressionState);
	checkCompile(expressionState);
	return result;
}
 
Example 12
Source Project: spring4-understanding   Source File: SpelExpression.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Object getValue(EvaluationContext context) throws EvaluationException {
	Assert.notNull(context, "EvaluationContext is required");
	if (compiledAst!= null) {
		try {
			TypedValue contextRoot = context == null ? null : context.getRootObject();
			return this.compiledAst.getValue(contextRoot != null ? contextRoot.getValue() : null, 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;
}
 
Example 13
Source Project: spring4-understanding   Source File: SpelExpression.java    License: Apache License 2.0 6 votes vote down vote up
@Override
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;
}
 
Example 14
Source Project: spring4-understanding   Source File: SpelExpression.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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();
			}
		}
	}
}
 
Example 15
Source Project: spring-analysis-note   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T getValue(@Nullable Class<T> expectedResultType) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			EvaluationContext context = getEvaluationContext();
			Object result = this.compiledAst.getValue(context.getRootObject().getValue(), context);
			if (expectedResultType == null) {
				return (T) result;
			}
			else {
				return ExpressionUtils.convertTypedValue(
						getEvaluationContext(), new TypedValue(result), expectedResultType);
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount.set(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(), this.configuration);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(
			expressionState.getEvaluationContext(), typedResultValue, expectedResultType);
}
 
Example 16
Source Project: spring-analysis-note   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T getValue(Object rootObject, @Nullable Class<T> expectedResultType) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			Object result = this.compiledAst.getValue(rootObject, getEvaluationContext());
			if (expectedResultType == null) {
				return (T)result;
			}
			else {
				return ExpressionUtils.convertTypedValue(
						getEvaluationContext(), new TypedValue(result), expectedResultType);
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount.set(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);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(
			expressionState.getEvaluationContext(), typedResultValue, expectedResultType);
}
 
Example 17
Source Project: spring-analysis-note   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@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.set(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;
}
 
Example 18
Source Project: spring-analysis-note   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T getValue(EvaluationContext context, @Nullable Class<T> expectedResultType) throws EvaluationException {
	Assert.notNull(context, "EvaluationContext is required");

	if (this.compiledAst != null) {
		try {
			Object result = this.compiledAst.getValue(context.getRootObject().getValue(), context);
			if (expectedResultType != null) {
				return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType);
			}
			else {
				return (T) result;
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount.set(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);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
}
 
Example 19
Source Project: spring-analysis-note   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@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.set(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;
}
 
Example 20
Source Project: spring-analysis-note   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T getValue(EvaluationContext context, Object rootObject, @Nullable Class<T> expectedResultType)
		throws EvaluationException {

	Assert.notNull(context, "EvaluationContext is required");

	if (this.compiledAst != null) {
		try {
			Object result = this.compiledAst.getValue(rootObject, context);
			if (expectedResultType != null) {
				return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType);
			}
			else {
				return (T) result;
			}
		}
		catch (Throwable ex) {
			// If running in mixed mode, revert to interpreted
			if (this.configuration.getCompilerMode() == SpelCompilerMode.MIXED) {
				this.interpretedCount.set(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);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
}
 
Example 21
Source Project: java-technology-stack   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T getValue(@Nullable Class<T> expectedResultType) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			EvaluationContext context = getEvaluationContext();
			Object result = this.compiledAst.getValue(context.getRootObject().getValue(), context);
			if (expectedResultType == null) {
				return (T) result;
			}
			else {
				return ExpressionUtils.convertTypedValue(
						getEvaluationContext(), new TypedValue(result), expectedResultType);
			}
		}
		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(), this.configuration);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(
			expressionState.getEvaluationContext(), typedResultValue, expectedResultType);
}
 
Example 22
Source Project: java-technology-stack   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T getValue(Object rootObject, @Nullable Class<T> expectedResultType) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			Object result = this.compiledAst.getValue(rootObject, getEvaluationContext());
			if (expectedResultType == null) {
				return (T)result;
			}
			else {
				return ExpressionUtils.convertTypedValue(
						getEvaluationContext(), new TypedValue(result), expectedResultType);
			}
		}
		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);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(
			expressionState.getEvaluationContext(), typedResultValue, expectedResultType);
}
 
Example 23
Source Project: java-technology-stack   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@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;
}
 
Example 24
Source Project: java-technology-stack   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T getValue(EvaluationContext context, @Nullable Class<T> expectedResultType) throws EvaluationException {
	Assert.notNull(context, "EvaluationContext is required");

	if (this.compiledAst != null) {
		try {
			Object result = this.compiledAst.getValue(context.getRootObject().getValue(), context);
			if (expectedResultType != null) {
				return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType);
			}
			else {
				return (T) result;
			}
		}
		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);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
}
 
Example 25
Source Project: java-technology-stack   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@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;
}
 
Example 26
Source Project: java-technology-stack   Source File: SpelExpression.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public <T> T getValue(EvaluationContext context, Object rootObject, @Nullable Class<T> expectedResultType)
		throws EvaluationException {

	Assert.notNull(context, "EvaluationContext is required");

	if (this.compiledAst != null) {
		try {
			Object result = this.compiledAst.getValue(rootObject, context);
			if (expectedResultType != null) {
				return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType);
			}
			else {
				return (T) result;
			}
		}
		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);
	TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
	checkCompile(expressionState);
	return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
}
 
Example 27
Source Project: eclair   Source File: EclairAutoConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public ExpressionEvaluator expressionEvaluator() {
    ExpressionParser expressionParser = new SpelExpressionParser(new SpelParserConfiguration(SpelCompilerMode.MIXED, null));
    StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
    evaluationContext.setBeanResolver(new BeanFactoryResolver(applicationContext));
    return new ExpressionEvaluator(expressionParser, evaluationContext);
}
 
Example 28
@Bean
public ExpressionParser zuulExpressionParser() {
	SpelParserConfiguration config = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE,
			this.getClass().getClassLoader());
	ExpressionParser parser = new SpelExpressionParser(config);
	return parser;
}
 
Example 29
@Bean
public ExpressionParser servletFilterExpressionParser() {
	SpelParserConfiguration config = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, this.getClass().getClassLoader());
	ExpressionParser parser = new SpelExpressionParser(config);
	
	return parser;
}
 
Example 30
@Bean
public ExpressionParser webFilterExpressionParser() {
	SpelParserConfiguration config = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE,
			this.getClass().getClassLoader());
	ExpressionParser parser = new SpelExpressionParser(config);

	return parser;
}