Nullability fine-tuning and related polishing
Issue: SPR-15720
This commit is contained in:
parent
f46520e6e8
commit
301e2ea493
|
|
@ -30,6 +30,12 @@ import org.springframework.lang.Nullable;
|
|||
*/
|
||||
public interface Expression {
|
||||
|
||||
/**
|
||||
* Return the original string used to create this expression, unmodified.
|
||||
* @return the original expression string
|
||||
*/
|
||||
String getExpressionString();
|
||||
|
||||
/**
|
||||
* Evaluate this expression in the default standard context.
|
||||
* @return the evaluation result
|
||||
|
|
@ -38,15 +44,6 @@ public interface Expression {
|
|||
@Nullable
|
||||
Object getValue() throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Evaluate this expression against the specified root object
|
||||
* @param rootObject the root object against which properties/etc will be resolved
|
||||
* @return the evaluation result
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
@Nullable
|
||||
Object getValue(Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Evaluate the expression in the default context. If the result of the evaluation does not match (and
|
||||
* cannot be converted to) the expected result type then an exception will be returned.
|
||||
|
|
@ -57,6 +54,15 @@ public interface Expression {
|
|||
@Nullable
|
||||
<T> T getValue(@Nullable Class<T> desiredResultType) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Evaluate this expression against the specified root object
|
||||
* @param rootObject the root object against which properties/etc will be resolved
|
||||
* @return the evaluation result
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
@Nullable
|
||||
Object getValue(Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Evaluate the expression in the default context against the specified root object. If the
|
||||
* result of the evaluation does not match (and cannot be converted to) the expected result type
|
||||
|
|
@ -196,6 +202,14 @@ public interface Expression {
|
|||
@Nullable
|
||||
TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Determine if an expression can be written to, i.e. setValue() can be called.
|
||||
* @param rootObject the root object against which to evaluate the expression
|
||||
* @return true if the expression is writable
|
||||
* @throws EvaluationException if there is a problem determining if it is writable
|
||||
*/
|
||||
boolean isWritable(Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Determine if an expression can be written to, i.e. setValue() can be called.
|
||||
* @param context the context in which the expression should be checked
|
||||
|
|
@ -215,29 +229,20 @@ public interface Expression {
|
|||
boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Determine if an expression can be written to, i.e. setValue() can be called.
|
||||
* Set this expression in the provided context to the value provided.
|
||||
* @param rootObject the root object against which to evaluate the expression
|
||||
* @return true if the expression is writable
|
||||
* @throws EvaluationException if there is a problem determining if it is writable
|
||||
* @param value the new value
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
boolean isWritable(Object rootObject) throws EvaluationException;
|
||||
void setValue(Object rootObject, @Nullable Object value) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Set this expression in the provided context to the value provided.
|
||||
*
|
||||
* @param context the context in which to set the value of the expression
|
||||
* @param value the new value
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
void setValue(EvaluationContext context, Object value) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Set this expression in the provided context to the value provided.
|
||||
* @param rootObject the root object against which to evaluate the expression
|
||||
* @param value the new value
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
void setValue(Object rootObject, Object value) throws EvaluationException;
|
||||
void setValue(EvaluationContext context, @Nullable Object value) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Set this expression in the provided context to the value provided.
|
||||
|
|
@ -247,12 +252,6 @@ public interface Expression {
|
|||
* @param value the new value
|
||||
* @throws EvaluationException if there is a problem during evaluation
|
||||
*/
|
||||
void setValue(EvaluationContext context, Object rootObject, Object value) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Returns the original string used to create this expression, unmodified.
|
||||
* @return the original expression string
|
||||
*/
|
||||
String getExpressionString();
|
||||
void setValue(EvaluationContext context, Object rootObject, @Nullable Object value) throws EvaluationException;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -21,6 +21,7 @@ import org.springframework.expression.EvaluationContext;
|
|||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a template expression broken into pieces. Each piece will be an Expression
|
||||
|
|
@ -58,6 +59,10 @@ public class CompositeStringExpression implements Expression {
|
|||
return this.expressionString;
|
||||
}
|
||||
|
||||
public final Expression[] getExpressions() {
|
||||
return this.expressions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() throws EvaluationException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
@ -70,6 +75,12 @@ public class CompositeStringExpression implements Expression {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(@Nullable Class<T> expectedResultType) throws EvaluationException {
|
||||
Object value = getValue();
|
||||
return ExpressionUtils.convertTypedValue(null, new TypedValue(value), expectedResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(Object rootObject) throws EvaluationException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
@ -82,6 +93,12 @@ public class CompositeStringExpression implements Expression {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(Object rootObject, @Nullable Class<T> desiredResultType) throws EvaluationException {
|
||||
Object value = getValue(rootObject);
|
||||
return ExpressionUtils.convertTypedValue(null, new TypedValue(value), desiredResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(EvaluationContext context) throws EvaluationException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
@ -94,6 +111,14 @@ public class CompositeStringExpression implements Expression {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(EvaluationContext context, @Nullable Class<T> expectedResultType)
|
||||
throws EvaluationException {
|
||||
|
||||
Object value = getValue(context);
|
||||
return ExpressionUtils.convertTypedValue(context, new TypedValue(value), expectedResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
@ -107,8 +132,11 @@ public class CompositeStringExpression implements Expression {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType(EvaluationContext context) {
|
||||
return String.class;
|
||||
public <T> T getValue(EvaluationContext context, Object rootObject, @Nullable Class<T> desiredResultType)
|
||||
throws EvaluationException {
|
||||
|
||||
Object value = getValue(context,rootObject);
|
||||
return ExpressionUtils.convertTypedValue(context, new TypedValue(value), desiredResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -117,53 +145,8 @@ public class CompositeStringExpression implements Expression {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor() {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(EvaluationContext context, Class<T> expectedResultType) throws EvaluationException {
|
||||
Object value = getValue(context);
|
||||
return ExpressionUtils.convertTypedValue(context, new TypedValue(value), expectedResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(Class<T> expectedResultType) throws EvaluationException {
|
||||
Object value = getValue();
|
||||
return ExpressionUtils.convertTypedValue(null, new TypedValue(value), expectedResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(EvaluationContext context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Expression[] getExpressions() {
|
||||
return this.expressions;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public <T> T getValue(Object rootObject, Class<T> desiredResultType) throws EvaluationException {
|
||||
Object value = getValue(rootObject);
|
||||
return ExpressionUtils.convertTypedValue(null, new TypedValue(value), desiredResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> desiredResultType)
|
||||
throws EvaluationException {
|
||||
Object value = getValue(context,rootObject);
|
||||
return ExpressionUtils.convertTypedValue(context, new TypedValue(value), desiredResultType);
|
||||
public Class<?> getValueType(EvaluationContext context) {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -176,24 +159,26 @@ public class CompositeStringExpression implements Expression {
|
|||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor() {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject)
|
||||
throws EvaluationException {
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, Object rootObject, Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression");
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -202,7 +187,27 @@ public class CompositeStringExpression implements Expression {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object rootObject, Object value) throws EvaluationException {
|
||||
public boolean isWritable(EvaluationContext context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, @Nullable Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.expressionString, "Cannot call setValue on a composite expression");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -21,14 +21,16 @@ import org.springframework.expression.EvaluationContext;
|
|||
import org.springframework.expression.EvaluationException;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.TypedValue;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* A very simple hardcoded implementation of the Expression interface that represents a
|
||||
* string literal. It is used with CompositeStringExpression when representing a template
|
||||
* expression which is made up of pieces - some being real expressions to be handled by an
|
||||
* EL implementation like Spel, and some being just textual elements.
|
||||
* expression which is made up of pieces - some being real expressions to be handled by
|
||||
* an EL implementation like SpEL, and some being just textual elements.
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
*/
|
||||
public class LiteralExpression implements Expression {
|
||||
|
|
@ -47,14 +49,20 @@ public class LiteralExpression implements Expression {
|
|||
return this.literalValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType(EvaluationContext context) {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return this.literalValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(EvaluationContext context) {
|
||||
return this.literalValue;
|
||||
public <T> T getValue(@Nullable Class<T> expectedResultType) throws EvaluationException {
|
||||
Object value = getValue();
|
||||
return ExpressionUtils.convertTypedValue(null, new TypedValue(value), expectedResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -63,64 +71,42 @@ public class LiteralExpression implements Expression {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType(EvaluationContext context) {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor() {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(EvaluationContext context, Class<T> expectedResultType) throws EvaluationException {
|
||||
Object value = getValue(context);
|
||||
return ExpressionUtils.convertTypedValue(context, new TypedValue(value), expectedResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(Class<T> expectedResultType) throws EvaluationException {
|
||||
Object value = getValue();
|
||||
return ExpressionUtils.convertTypedValue(null, new TypedValue(value), expectedResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(EvaluationContext context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(Object rootObject, Class<T> desiredResultType) throws EvaluationException {
|
||||
public <T> T getValue(Object rootObject, @Nullable Class<T> desiredResultType) throws EvaluationException {
|
||||
Object value = getValue(rootObject);
|
||||
return ExpressionUtils.convertTypedValue(null, new TypedValue(value), desiredResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(EvaluationContext context) {
|
||||
return this.literalValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(EvaluationContext context, @Nullable Class<T> expectedResultType)
|
||||
throws EvaluationException {
|
||||
|
||||
Object value = getValue(context);
|
||||
return ExpressionUtils.convertTypedValue(context, new TypedValue(value), expectedResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
return this.literalValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getValue(EvaluationContext context, Object rootObject, Class<T> desiredResultType) throws EvaluationException {
|
||||
public <T> T getValue(EvaluationContext context, Object rootObject, @Nullable Class<T> desiredResultType)
|
||||
throws EvaluationException {
|
||||
|
||||
Object value = getValue(context, rootObject);
|
||||
return ExpressionUtils.convertTypedValue(context, new TypedValue(value), desiredResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType(Object rootObject) throws EvaluationException {
|
||||
return String.class;
|
||||
|
|
@ -131,33 +117,53 @@ public class LiteralExpression implements Expression {
|
|||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor() {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(Object rootObject) throws EvaluationException {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
return TypeDescriptor.valueOf(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, Object rootObject, Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(Object rootObject) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object rootObject, Object value) throws EvaluationException {
|
||||
public boolean isWritable(EvaluationContext context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, @Nullable Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
throw new EvaluationException(this.literalValue, "Cannot call setValue() on a LiteralExpression");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import org.springframework.util.Assert;
|
|||
* references to types, beans, properties, and methods.
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
*/
|
||||
public class SpelExpression implements Expression {
|
||||
|
|
@ -107,6 +108,11 @@ public class SpelExpression implements Expression {
|
|||
|
||||
// implementing Expression
|
||||
|
||||
@Override
|
||||
public String getExpressionString() {
|
||||
return this.expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() throws EvaluationException {
|
||||
Object result;
|
||||
|
|
@ -135,6 +141,42 @@ public class SpelExpression implements Expression {
|
|||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getValue(@Nullable Class<T> expectedResultType) throws EvaluationException {
|
||||
if (this.compiledAst != null) {
|
||||
try {
|
||||
TypedValue contextRoot =
|
||||
(this.evaluationContext != null ? this.evaluationContext.getRootObject() : null);
|
||||
Object result = this.compiledAst.getValue(
|
||||
(contextRoot != null ? contextRoot.getValue() : null), this.evaluationContext);
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(Object rootObject) throws EvaluationException {
|
||||
Object result;
|
||||
|
|
@ -154,45 +196,13 @@ public class SpelExpression implements Expression {
|
|||
}
|
||||
}
|
||||
}
|
||||
ExpressionState expressionState = new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration);
|
||||
ExpressionState expressionState =
|
||||
new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration);
|
||||
result = this.ast.getValue(expressionState);
|
||||
checkCompile(expressionState);
|
||||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getValue(@Nullable Class<T> expectedResultType) throws EvaluationException {
|
||||
if (this.compiledAst != null) {
|
||||
try {
|
||||
TypedValue contextRoot = (this.evaluationContext != null ? this.evaluationContext.getRootObject() : null);
|
||||
Object result = this.compiledAst.getValue(
|
||||
(contextRoot != null ? contextRoot.getValue() : null), this.evaluationContext);
|
||||
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);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getValue(Object rootObject, @Nullable Class<T> expectedResultType) throws EvaluationException {
|
||||
|
|
@ -203,7 +213,8 @@ public class SpelExpression implements Expression {
|
|||
return (T)result;
|
||||
}
|
||||
else {
|
||||
return ExpressionUtils.convertTypedValue(getEvaluationContext(), new TypedValue(result), expectedResultType);
|
||||
return ExpressionUtils.convertTypedValue(
|
||||
getEvaluationContext(), new TypedValue(result), expectedResultType);
|
||||
}
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
|
|
@ -218,10 +229,12 @@ public class SpelExpression implements Expression {
|
|||
}
|
||||
}
|
||||
}
|
||||
ExpressionState expressionState = new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration);
|
||||
ExpressionState expressionState =
|
||||
new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration);
|
||||
TypedValue typedResultValue = this.ast.getTypedValue(expressionState);
|
||||
checkCompile(expressionState);
|
||||
return ExpressionUtils.convertTypedValue(expressionState.getEvaluationContext(), typedResultValue, expectedResultType);
|
||||
return ExpressionUtils.convertTypedValue(
|
||||
expressionState.getEvaluationContext(), typedResultValue, expectedResultType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -250,31 +263,6 @@ public class SpelExpression implements Expression {
|
|||
return result;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getValue(EvaluationContext context, @Nullable Class<T> expectedResultType) throws EvaluationException {
|
||||
|
|
@ -307,6 +295,31 @@ public class SpelExpression implements Expression {
|
|||
return ExpressionUtils.convertTypedValue(context, typedResultValue, expectedResultType);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T getValue(EvaluationContext context, Object rootObject, @Nullable Class<T> expectedResultType)
|
||||
|
|
@ -385,15 +398,18 @@ public class SpelExpression implements Expression {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, Object rootObject)
|
||||
throws EvaluationException {
|
||||
|
||||
Assert.notNull(context, "EvaluationContext is required");
|
||||
ExpressionState expressionState = new ExpressionState(context, toTypedValue(rootObject), this.configuration);
|
||||
return this.ast.getValueInternal(expressionState).getTypeDescriptor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpressionString() {
|
||||
return this.expression;
|
||||
public boolean isWritable(Object rootObject) throws EvaluationException {
|
||||
return this.ast.isWritable(
|
||||
new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -402,11 +418,6 @@ public class SpelExpression implements Expression {
|
|||
return this.ast.isWritable(new ExpressionState(context, this.configuration));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(Object rootObject) throws EvaluationException {
|
||||
return this.ast.isWritable(new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWritable(EvaluationContext context, Object rootObject) throws EvaluationException {
|
||||
Assert.notNull(context, "EvaluationContext is required");
|
||||
|
|
@ -414,18 +425,21 @@ public class SpelExpression implements Expression {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, Object value) throws EvaluationException {
|
||||
public void setValue(Object rootObject, @Nullable Object value) throws EvaluationException {
|
||||
this.ast.setValue(
|
||||
new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, @Nullable Object value) throws EvaluationException {
|
||||
Assert.notNull(context, "EvaluationContext is required");
|
||||
this.ast.setValue(new ExpressionState(context, this.configuration), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object rootObject, Object value) throws EvaluationException {
|
||||
this.ast.setValue(new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration), value);
|
||||
}
|
||||
public void setValue(EvaluationContext context, Object rootObject, @Nullable Object value)
|
||||
throws EvaluationException {
|
||||
|
||||
@Override
|
||||
public void setValue(EvaluationContext context, Object rootObject, Object value) throws EvaluationException {
|
||||
Assert.notNull(context, "EvaluationContext is required");
|
||||
this.ast.setValue(new ExpressionState(context, toTypedValue(rootObject), this.configuration), value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,6 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
|
|||
/**
|
||||
* Return the underlying {@code ObjectMapper} for this view.
|
||||
*/
|
||||
@Nullable
|
||||
public ObjectMapper getObjectMapper() {
|
||||
return this.objectMapper;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,7 +167,8 @@ public class Jaxb2CollectionHttpMessageConverter<T extends Collection>
|
|||
return result;
|
||||
}
|
||||
catch (UnmarshalException ex) {
|
||||
throw new HttpMessageNotReadableException("Could not unmarshal to [" + elementClass + "]: " + ex.getMessage(), ex);
|
||||
throw new HttpMessageNotReadableException(
|
||||
"Could not unmarshal to [" + elementClass + "]: " + ex.getMessage(), ex);
|
||||
}
|
||||
catch (JAXBException ex) {
|
||||
throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
|
||||
|
|
|
|||
|
|
@ -54,9 +54,8 @@ import org.springframework.util.ClassUtils;
|
|||
* {@link XmlType}, and write classes annotated with {@link XmlRootElement},
|
||||
* or subclasses thereof.
|
||||
*
|
||||
* <p>Note that if using Spring's Marshaller/Unmarshaller abstractions from the
|
||||
* {@code spring-oxm} module you should can the
|
||||
* {@link MarshallingHttpMessageConverter} instead.
|
||||
* <p>Note: When using Spring's Marshaller/Unmarshaller abstractions from {@code spring-oxm},
|
||||
* you should use the {@link MarshallingHttpMessageConverter} instead.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Sebastien Deleuze
|
||||
|
|
@ -140,8 +139,7 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
|
|||
catch (NullPointerException ex) {
|
||||
if (!isSupportDtd()) {
|
||||
throw new HttpMessageNotReadableException("NPE while unmarshalling. " +
|
||||
"This can happen on JDK 1.6 due to the presence of DTD " +
|
||||
"declarations, which are disabled.", ex);
|
||||
"This can happen due to the presence of DTD declarations which are disabled.", ex);
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
|
@ -202,11 +200,7 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa
|
|||
}
|
||||
|
||||
|
||||
private static final EntityResolver NO_OP_ENTITY_RESOLVER = new EntityResolver() {
|
||||
@Override
|
||||
public InputSource resolveEntity(String publicId, String systemId) {
|
||||
return new InputSource(new StringReader(""));
|
||||
}
|
||||
};
|
||||
private static final EntityResolver NO_OP_ENTITY_RESOLVER =
|
||||
(publicId, systemId) -> new InputSource(new StringReader(""));
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue