Search in sources :

Example 21 with SpelEvaluationException

use of org.springframework.expression.spel.SpelEvaluationException in project spring-framework by spring-projects.

the class SpelExpression method getValue.

@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;
}
Also used : SpelEvaluationException(org.springframework.expression.spel.SpelEvaluationException) ExpressionState(org.springframework.expression.spel.ExpressionState)

Example 22 with SpelEvaluationException

use of org.springframework.expression.spel.SpelEvaluationException in project spring-framework by spring-projects.

the class SpelExpression method getValue.

@SuppressWarnings("unchecked")
@Override
public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> expectedResultType) throws EvaluationException {
    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);
}
Also used : SpelEvaluationException(org.springframework.expression.spel.SpelEvaluationException) ExpressionState(org.springframework.expression.spel.ExpressionState) TypedValue(org.springframework.expression.TypedValue)

Example 23 with SpelEvaluationException

use of org.springframework.expression.spel.SpelEvaluationException in project spring-framework by spring-projects.

the class SpelExpression method getValue.

@SuppressWarnings("unchecked")
@Override
public <T> T getValue(Object rootObject, Class<T> expectedResultType) throws EvaluationException {
    if (this.compiledAst != null) {
        try {
            Object result = this.compiledAst.getValue(rootObject, null);
            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);
}
Also used : SpelEvaluationException(org.springframework.expression.spel.SpelEvaluationException) ExpressionState(org.springframework.expression.spel.ExpressionState) TypedValue(org.springframework.expression.TypedValue)

Example 24 with SpelEvaluationException

use of org.springframework.expression.spel.SpelEvaluationException in project spring-framework by spring-projects.

the class SpelExpression method getValue.

// implementing Expression
@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;
}
Also used : SpelEvaluationException(org.springframework.expression.spel.SpelEvaluationException) ExpressionState(org.springframework.expression.spel.ExpressionState) TypedValue(org.springframework.expression.TypedValue)

Example 25 with SpelEvaluationException

use of org.springframework.expression.spel.SpelEvaluationException in project spring-framework by spring-projects.

the class SpelExpression method getValue.

@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);
}
Also used : SpelEvaluationException(org.springframework.expression.spel.SpelEvaluationException) ExpressionState(org.springframework.expression.spel.ExpressionState) TypedValue(org.springframework.expression.TypedValue)

Aggregations

SpelEvaluationException (org.springframework.expression.spel.SpelEvaluationException)30 TypedValue (org.springframework.expression.TypedValue)18 ExpressionState (org.springframework.expression.spel.ExpressionState)8 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)6 AccessException (org.springframework.expression.AccessException)6 ArrayList (java.util.ArrayList)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Map (java.util.Map)4 EvaluationException (org.springframework.expression.EvaluationException)4 BigDecimal (java.math.BigDecimal)3 BigInteger (java.math.BigInteger)3 TypeConverter (org.springframework.expression.TypeConverter)3 HashMap (java.util.HashMap)2 List (java.util.List)2 MethodParameter (org.springframework.core.MethodParameter)2 ConstructorExecutor (org.springframework.expression.ConstructorExecutor)2 EvaluationContext (org.springframework.expression.EvaluationContext)2 PropertyAccessor (org.springframework.expression.PropertyAccessor)2 CompilablePropertyAccessor (org.springframework.expression.spel.CompilablePropertyAccessor)2 ReflectiveConstructorExecutor (org.springframework.expression.spel.support.ReflectiveConstructorExecutor)2