Java Code Examples for org.springframework.expression.EvaluationContext#getRootObject()

The following examples show how to use org.springframework.expression.EvaluationContext#getRootObject() . 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 File: SpelExpression.java    From spring4-understanding with 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 2
Source File: SpelExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object getValue(EvaluationContext context) throws EvaluationException {
	Assert.notNull(context, "EvaluationContext is required");

	if (this.compiledAst != null) {
		try {
			TypedValue contextRoot = context.getRootObject();
			return this.compiledAst.getValue(contextRoot.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 3
Source File: SpelExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(EvaluationContext context, Class<T> expectedResultType) throws EvaluationException {
	Assert.notNull(context, "EvaluationContext is required");

	if (this.compiledAst != null) {
		try {
			TypedValue contextRoot = context.getRootObject();
			Object result = this.compiledAst.getValue(contextRoot.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 4
Source File: SpelExpression.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(EvaluationContext context, Class<T> expectedResultType) throws EvaluationException {
	if (this.compiledAst != null) {
		try {
			TypedValue contextRoot = context == null ? null : context.getRootObject();
			Object result = this.compiledAst.getValue(contextRoot==null?null:contextRoot.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 5
Source File: ExpressionState.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public ExpressionState(EvaluationContext context) {
	this(context, context.getRootObject(), new SpelParserConfiguration(false, false));
}
 
Example 6
Source File: ExpressionState.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public ExpressionState(EvaluationContext context, SpelParserConfiguration configuration) {
	this(context, context.getRootObject(), configuration);
}
 
Example 7
Source File: ExpressionState.java    From java-technology-stack with MIT License 4 votes vote down vote up
public ExpressionState(EvaluationContext context) {
	this(context, context.getRootObject(), new SpelParserConfiguration(false, false));
}
 
Example 8
Source File: ExpressionState.java    From java-technology-stack with MIT License 4 votes vote down vote up
public ExpressionState(EvaluationContext context, SpelParserConfiguration configuration) {
	this(context, context.getRootObject(), configuration);
}
 
Example 9
Source File: ExpressionState.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ExpressionState(EvaluationContext context) {
	this(context, context.getRootObject(), new SpelParserConfiguration(false, false));
}
 
Example 10
Source File: ExpressionState.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public ExpressionState(EvaluationContext context, SpelParserConfiguration configuration) {
	this(context, context.getRootObject(), configuration);
}
 
Example 11
Source File: ExpressionState.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public ExpressionState(EvaluationContext context) {
	this(context, context.getRootObject(), new SpelParserConfiguration(false, false));
}
 
Example 12
Source File: ExpressionState.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public ExpressionState(EvaluationContext context, SpelParserConfiguration configuration) {
	this(context, context.getRootObject(), configuration);
}