Java Code Examples for org.springframework.expression.spel.SpelEvaluationException#setPosition()

The following examples show how to use org.springframework.expression.spel.SpelEvaluationException#setPosition() . 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: FunctionReference.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	TypedValue value = state.lookupVariable(this.name);
	if (value == null) {
		throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_NOT_DEFINED, this.name);
	}

	// Two possibilities: a lambda function or a Java static method registered as a function
	if (!(value.getValue() instanceof Method)) {
		throw new SpelEvaluationException(
				SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass());
	}

	try {
		return executeFunctionJLRMethod(state, (Method) value.getValue());
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getStartPosition());
		throw ex;
	}
}
 
Example 2
Source File: OperatorBetween.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a boolean based on whether a value is in the range expressed. The first
 * operand is any value whilst the second is a list of two values - those two values
 * being the bounds allowed for the first operand (inclusive).
 * @param state the expression state
 * @return true if the left operand is in the range specified, false otherwise
 * @throws EvaluationException if there is a problem evaluating the expression
 */
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	Object left = getLeftOperand().getValueInternal(state).getValue();
	Object right = getRightOperand().getValueInternal(state).getValue();
	if (!(right instanceof List) || ((List<?>) right).size() != 2) {
		throw new SpelEvaluationException(getRightOperand().getStartPosition(),
				SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST);
	}

	List<?> list = (List<?>) right;
	Object low = list.get(0);
	Object high = list.get(1);
	TypeComparator comp = state.getTypeComparator();
	try {
		return BooleanTypedValue.forValue(comp.compare(left, low) >= 0 && comp.compare(left, high) <= 0);
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getStartPosition());
		throw ex;
	}
}
 
Example 3
Source File: FunctionReference.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	TypedValue value = state.lookupVariable(this.name);
	if (value == null) {
		throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_NOT_DEFINED, this.name);
	}

	// Two possibilities: a lambda function or a Java static method registered as a function
	if (!(value.getValue() instanceof Method)) {
		throw new SpelEvaluationException(
				SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass());
	}

	try {
		return executeFunctionJLRMethod(state, (Method) value.getValue());
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getStartPosition());
		throw ex;
	}
}
 
Example 4
Source File: OperatorBetween.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a boolean based on whether a value is in the range expressed. The first
 * operand is any value whilst the second is a list of two values - those two values
 * being the bounds allowed for the first operand (inclusive).
 * @param state the expression state
 * @return true if the left operand is in the range specified, false otherwise
 * @throws EvaluationException if there is a problem evaluating the expression
 */
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	Object left = getLeftOperand().getValueInternal(state).getValue();
	Object right = getRightOperand().getValueInternal(state).getValue();
	if (!(right instanceof List) || ((List<?>) right).size() != 2) {
		throw new SpelEvaluationException(getRightOperand().getStartPosition(),
				SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST);
	}

	List<?> list = (List<?>) right;
	Object low = list.get(0);
	Object high = list.get(1);
	TypeComparator comp = state.getTypeComparator();
	try {
		return BooleanTypedValue.forValue(comp.compare(left, low) >= 0 && comp.compare(left, high) <= 0);
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getStartPosition());
		throw ex;
	}
}
 
Example 5
Source File: FunctionReference.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	TypedValue value = state.lookupVariable(this.name);
	if (value == TypedValue.NULL) {
		throw new SpelEvaluationException(getStartPosition(), SpelMessage.FUNCTION_NOT_DEFINED, this.name);
	}
	if (!(value.getValue() instanceof Method)) {
		// Possibly a static Java method registered as a function
		throw new SpelEvaluationException(
				SpelMessage.FUNCTION_REFERENCE_CANNOT_BE_INVOKED, this.name, value.getClass());
	}

	try {
		return executeFunctionJLRMethod(state, (Method) value.getValue());
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getStartPosition());
		throw ex;
	}
}
 
Example 6
Source File: OperatorBetween.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Returns a boolean based on whether a value is in the range expressed. The first
 * operand is any value whilst the second is a list of two values - those two values
 * being the bounds allowed for the first operand (inclusive).
 * @param state the expression state
 * @return true if the left operand is in the range specified, false otherwise
 * @throws EvaluationException if there is a problem evaluating the expression
 */
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	Object left = getLeftOperand().getValueInternal(state).getValue();
	Object right = getRightOperand().getValueInternal(state).getValue();
	if (!(right instanceof List) || ((List<?>) right).size() != 2) {
		throw new SpelEvaluationException(getRightOperand().getStartPosition(),
				SpelMessage.BETWEEN_RIGHT_OPERAND_MUST_BE_TWO_ELEMENT_LIST);
	}

	List<?> list = (List<?>) right;
	Object low = list.get(0);
	Object high = list.get(1);
	TypeComparator comp = state.getTypeComparator();
	try {
		return BooleanTypedValue.forValue(comp.compare(left, low) >= 0 && comp.compare(left, high) <= 0);
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getStartPosition());
		throw ex;
	}
}
 
Example 7
Source File: CompoundExpression.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected ValueRef getValueRef(ExpressionState state) throws EvaluationException {
	if (getChildCount() == 1) {
		return this.children[0].getValueRef(state);
	}

	SpelNodeImpl nextNode = this.children[0];
	try {
		TypedValue result = nextNode.getValueInternal(state);
		int cc = getChildCount();
		for (int i = 1; i < cc - 1; i++) {
			try {
				state.pushActiveContextObject(result);
				nextNode = this.children[i];
				result = nextNode.getValueInternal(state);
			}
			finally {
				state.popActiveContextObject();
			}
		}
		try {
			state.pushActiveContextObject(result);
			nextNode = this.children[cc - 1];
			return nextNode.getValueRef(state);
		}
		finally {
			state.popActiveContextObject();
		}
	}
	catch (SpelEvaluationException ex) {
		// Correct the position for the error before re-throwing
		ex.setPosition(nextNode.getStartPosition());
		throw ex;
	}
}
 
Example 8
Source File: OpAnd.java    From java-technology-stack with MIT License 5 votes vote down vote up
private boolean getBooleanValue(ExpressionState state, SpelNodeImpl operand) {
	try {
		Boolean value = operand.getValue(state, Boolean.class);
		assertValueNotNull(value);
		return value;
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(operand.getStartPosition());
		throw ex;
	}
}
 
Example 9
Source File: OpOr.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private boolean getBooleanValue(ExpressionState state, SpelNodeImpl operand) {
	try {
		Boolean value = operand.getValue(state, Boolean.class);
		assertValueNotNull(value);
		return value;
	}
	catch (SpelEvaluationException ee) {
		ee.setPosition(operand.getStartPosition());
		throw ee;
	}
}
 
Example 10
Source File: OpOr.java    From java-technology-stack with MIT License 5 votes vote down vote up
private boolean getBooleanValue(ExpressionState state, SpelNodeImpl operand) {
	try {
		Boolean value = operand.getValue(state, Boolean.class);
		assertValueNotNull(value);
		return value;
	}
	catch (SpelEvaluationException ee) {
		ee.setPosition(operand.getStartPosition());
		throw ee;
	}
}
 
Example 11
Source File: OperatorNot.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	try {
		Boolean value = this.children[0].getValue(state, Boolean.class);
		if (value == null) {
			throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean");
		}
		return BooleanTypedValue.forValue(!value);
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getChild(0).getStartPosition());
		throw ex;
	}
}
 
Example 12
Source File: CompoundExpression.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected ValueRef getValueRef(ExpressionState state) throws EvaluationException {
	if (getChildCount() == 1) {
		return this.children[0].getValueRef(state);
	}

	SpelNodeImpl nextNode = this.children[0];
	try {
		TypedValue result = nextNode.getValueInternal(state);
		int cc = getChildCount();
		for (int i = 1; i < cc - 1; i++) {
			try {
				state.pushActiveContextObject(result);
				nextNode = this.children[i];
				result = nextNode.getValueInternal(state);
			}
			finally {
				state.popActiveContextObject();
			}
		}
		try {
			state.pushActiveContextObject(result);
			nextNode = this.children[cc - 1];
			return nextNode.getValueRef(state);
		}
		finally {
			state.popActiveContextObject();
		}
	}
	catch (SpelEvaluationException ex) {
		// Correct the position for the error before re-throwing
		ex.setPosition(nextNode.getStartPosition());
		throw ex;
	}
}
 
Example 13
Source File: CompoundExpression.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected ValueRef getValueRef(ExpressionState state) throws EvaluationException {
	if (getChildCount() == 1) {
		return this.children[0].getValueRef(state);
	}

	SpelNodeImpl nextNode = this.children[0];
	try {
		TypedValue result = nextNode.getValueInternal(state);
		int cc = getChildCount();
		for (int i = 1; i < cc - 1; i++) {
			try {
				state.pushActiveContextObject(result);
				nextNode = this.children[i];
				result = nextNode.getValueInternal(state);
			}
			finally {
				state.popActiveContextObject();
			}
		}
		try {
			state.pushActiveContextObject(result);
			nextNode = this.children[cc - 1];
			return nextNode.getValueRef(state);
		}
		finally {
			state.popActiveContextObject();
		}
	}
	catch (SpelEvaluationException ex) {
		// Correct the position for the error before re-throwing
		ex.setPosition(nextNode.getStartPosition());
		throw ex;
	}
}
 
Example 14
Source File: OpAnd.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private boolean getBooleanValue(ExpressionState state, SpelNodeImpl operand) {
	try {
		Boolean value = operand.getValue(state, Boolean.class);
		assertValueNotNull(value);
		return value;
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(operand.getStartPosition());
		throw ex;
	}
}
 
Example 15
Source File: OperatorNot.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	try {
		Boolean value = this.children[0].getValue(state, Boolean.class);
		if (value == null) {
			throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean");
		}
		return BooleanTypedValue.forValue(!value);
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getChild(0).getStartPosition());
		throw ex;
	}
}
 
Example 16
Source File: OpOr.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private boolean getBooleanValue(ExpressionState state, SpelNodeImpl operand) {
	try {
		Boolean value = operand.getValue(state, Boolean.class);
		assertValueNotNull(value);
		return value;
	}
	catch (SpelEvaluationException ee) {
		ee.setPosition(operand.getStartPosition());
		throw ee;
	}
}
 
Example 17
Source File: OperatorNot.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException {
	try {
		Boolean value = this.children[0].getValue(state, Boolean.class);
		if (value == null) {
			throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean");
		}
		return BooleanTypedValue.forValue(!value);
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(getChild(0).getStartPosition());
		throw ex;
	}
}
 
Example 18
Source File: OpOr.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private boolean getBooleanValue(ExpressionState state, SpelNodeImpl operand) {
	try {
		Boolean value = operand.getValue(state, Boolean.class);
		assertValueNotNull(value);
		return value;
	}
	catch (SpelEvaluationException ee) {
		ee.setPosition(operand.getStartPosition());
		throw ee;
	}
}
 
Example 19
Source File: CompoundExpression.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected ValueRef getValueRef(ExpressionState state) throws EvaluationException {
	if (getChildCount() == 1) {
		return this.children[0].getValueRef(state);
	}

	SpelNodeImpl nextNode = this.children[0];
	try {
		TypedValue result = nextNode.getValueInternal(state);
		int cc = getChildCount();
		for (int i = 1; i < cc - 1; i++) {
			try {
				state.pushActiveContextObject(result);
				nextNode = this.children[i];
				result = nextNode.getValueInternal(state);
			}
			finally {
				state.popActiveContextObject();
			}
		}
		try {
			state.pushActiveContextObject(result);
			nextNode = this.children[cc - 1];
			return nextNode.getValueRef(state);
		}
		finally {
			state.popActiveContextObject();
		}
	}
	catch (SpelEvaluationException ex) {
		// Correct the position for the error before re-throwing
		ex.setPosition(nextNode.getStartPosition());
		throw ex;
	}
}
 
Example 20
Source File: OpAnd.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private boolean getBooleanValue(ExpressionState state, SpelNodeImpl operand) {
	try {
		Boolean value = operand.getValue(state, Boolean.class);
		assertValueNotNull(value);
		return value;
	}
	catch (SpelEvaluationException ex) {
		ex.setPosition(operand.getStartPosition());
		throw ex;
	}
}