Refine search
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { SpelNodeImpl operand = getLeftOperand(); ValueRef valueRef = operand.getValueRef(state); Object value = typedValue.getValue(); TypedValue returnValue = typedValue; TypedValue newValue = null; Number op1 = (Number) value; if (op1 instanceof BigDecimal) { newValue = new TypedValue(((BigDecimal) op1).add(BigDecimal.ONE), typedValue.getTypeDescriptor()); newValue = state.operate(Operation.ADD, returnValue.getValue(), 1); if (ex.getMessageCode() == SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES) { throw new SpelEvaluationException(operand.getStartPosition(), SpelMessage.OPERAND_NOT_INCREMENTABLE, operand.toStringAST()); if (see.getMessageCode() == SpelMessage.SETVALUE_NOT_SUPPORTED) { throw new SpelEvaluationException(operand.getStartPosition(), SpelMessage.OPERAND_NOT_INCREMENTABLE);
logger.debug("Failed to evaluate selector: " + ex.getMessage());
/** * 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; } }
@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; } }
@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; } }
private void assertValueNotNull(@Nullable Boolean value) { if (value == null) { throw new SpelEvaluationException(SpelMessage.TYPE_CONVERSION_ERROR, "null", "boolean"); } }
@SuppressWarnings("unchecked") @Override @Nullable public <T> T getValue(EvaluationContext context, @Nullable Class<T> expectedResultType) throws EvaluationException { Assert.notNull(context, "EvaluationContext is required"); Object result = this.compiledAst.getValue(context.getRootObject().getValue(), context); if (expectedResultType != null) { return ExpressionUtils.convertTypedValue(context, new TypedValue(result), expectedResultType); 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);
@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; }
public TypedValue operate(Operation op, @Nullable Object left, @Nullable Object right) throws EvaluationException { OperatorOverloader overloader = this.relatedContext.getOperatorOverloader(); if (overloader.overridesOperation(op, left, right)) { Object returnValue = overloader.operate(op, left, right); return new TypedValue(returnValue); } else { String leftType = (left == null ? "null" : left.getClass().getName()); String rightType = (right == null? "null" : right.getClass().getName()); throw new SpelEvaluationException(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES, op, leftType, rightType); } }
@Override public void setValue(@Nullable Object newValue) { throw new SpelEvaluationException( this.node.getStartPosition(), SpelMessage.NOT_ASSIGNABLE, this.node.toStringAST()); }
@Override public void setValue(ExpressionState expressionState, @Nullable Object newValue) throws EvaluationException { throw new SpelEvaluationException(getStartPosition(), SpelMessage.SETVALUE_NOT_SUPPORTED, getClass()); }
@Override public void setValue(@Nullable Object newValue) { throw new SpelEvaluationException(this.node.pos, SpelMessage.NOT_ASSIGNABLE, this.node.toStringAST()); }
private void writeProperty( TypedValue contextObject, EvaluationContext evalContext, String name, @Nullable Object newValue) throws EvaluationException { if (contextObject.getValue() == null && this.nullSafe) { return; if (contextObject.getValue() == null) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL, name); if (evalContext.getPropertyAccessors().contains(accessorToUse)) { try { accessorToUse.write(evalContext, contextObject.getValue(), name, newValue); return; throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_PROPERTY_WRITE, name, ex.getMessage()); throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE, name, FormatHelper.formatClassNameForMessage(getObjectClass(contextObject.getValue())));
@Override protected ValueRef getValueRef(ExpressionState state) throws EvaluationException { TypedValue op = state.getActiveContextObject(); Object operand = op.getValue(); boolean operandIsArray = ObjectUtils.isArray(operand); for (Map.Entry<?, ?> entry : mapData.entrySet()) { try { state.pushActiveContextObject(new TypedValue(entry)); state.enterScope(); result.add(this.children[0].getValueInternal(state).getValue()); state.pushActiveContextObject(new TypedValue(element)); state.enterScope("index", idx); Object value = this.children[0].getValueInternal(state).getValue(); if (value != null && operandIsArray) { arrayElementType = determineCommonType(arrayElementType, value.getClass()); return ValueRef.NullValueRef.INSTANCE; throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROJECTION_NOT_SUPPORTED_ON_TYPE, "null"); throw new SpelEvaluationException(getStartPosition(), SpelMessage.PROJECTION_NOT_SUPPORTED_ON_TYPE, operand.getClass().getName());
@Override protected ValueRef getValueRef(ExpressionState state) throws EvaluationException { TypedValue context = state.getActiveContextObject(); Object target = context.getValue(); TypeDescriptor targetDescriptor = context.getTypeDescriptor(); TypedValue indexValue; Object index; PropertyOrFieldReference reference = (PropertyOrFieldReference) this.children[0]; index = reference.getName(); indexValue = new TypedValue(index); state.pushActiveContextObject(state.getRootContextObject()); indexValue = this.children[0].getValueInternal(state); index = indexValue.getValue(); Assert.state(index != null, "No index"); throw new SpelEvaluationException(getStartPosition(), SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE); throw new SpelEvaluationException( getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetDescriptor);
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { BeanResolver beanResolver = state.getEvaluationContext().getBeanResolver(); if (beanResolver == null) { throw new SpelEvaluationException( getStartPosition(), SpelMessage.NO_BEAN_RESOLVER_REGISTERED, this.beanName); } try { return new TypedValue(beanResolver.resolve(state.getEvaluationContext(), this.beanName)); } catch (AccessException ex) { throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.EXCEPTION_DURING_BEAN_RESOLUTION, this.beanName, ex.getMessage()); } }
@Override public TypedValue getValue() { if (this.index >= this.target.length()) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.STRING_INDEX_OUT_OF_BOUNDS, this.target.length(), this.index); } return new TypedValue(String.valueOf(this.target.charAt(this.index))); }
throw new SpelEvaluationException(getChild(0).getStartPosition(), SpelMessage.TYPE_NAME_EXPECTED_FOR_ARRAY_CONSTRUCTION, FormatHelper.formatClassNameForMessage( for (SpelNodeImpl dimension : this.dimensions) { if (dimension == null) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.MISSING_ARRAY_DIMENSION); TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter(); TypedValue o = this.dimensions[d].getTypedValue(state); dims[d] = ExpressionUtils.toInt(typeConverter, o); throw new SpelEvaluationException(getStartPosition(), SpelMessage.MULTIDIM_ARRAY_INITIALIZER_NOT_SUPPORTED); TypeConverter typeConverter = state.getEvaluationContext().getTypeConverter(); InlineList initializer = (InlineList) getChild(1); TypedValue dValue = this.dimensions[0].getTypedValue(state); int i = ExpressionUtils.toInt(typeConverter, dValue); if (i != initializer.getChildCount()) { throw new SpelEvaluationException(getStartPosition(), SpelMessage.INITIALIZER_LENGTH_INCORRECT); return new TypedValue(newArray);
@Override protected ValueRef getValueRef(ExpressionState state) throws EvaluationException { if (getChildCount() == 1) { return this.children[0].getValueRef(state); 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); state.popActiveContextObject(); state.pushActiveContextObject(result); nextNode = this.children[cc - 1]; return nextNode.getValueRef(state); ex.setPosition(nextNode.getStartPosition()); throw ex;
public BooleanTypedValue getValueInternal(ExpressionState state) throws EvaluationException { SpelNodeImpl rightOperand = getRightOperand(); TypedValue left = getLeftOperand().getValueInternal(state); TypedValue right = rightOperand.getValueInternal(state); Object leftValue = left.getValue(); Object rightValue = right.getValue(); BooleanTypedValue result; if (rightValue == null || !(rightValue instanceof Class)) { throw new SpelEvaluationException(getRightOperand().getStartPosition(), SpelMessage.INSTANCEOF_OPERATOR_NEEDS_CLASS_OPERAND, (rightValue == null ? "null" : rightValue.getClass().getName()));