private void validateArrayElement( ArrayElement element, FieldTreeNode refMd, RValueExpression rvalue, Path refPath) { if (element instanceof ObjectArrayElement) { if (refMd != null && !refMd.getType().equals(element.getType())) { throw new EvaluationError( CrudConstants.ERR_INVALID_ASSIGNMENT + arrayField + " <- " + refPath); } else { if (rvalue.getType() == RValueExpression.RValueType._value) { Value v = rvalue.getValue(); if (!(v.getValue() instanceof ObjectNode) && !(v.getValue() instanceof ArrayNode)) throw new EvaluationError(CrudConstants.ERR_EXPECTED_OBJECT_VALUE + arrayField); } } } else { if (refMd != null && !refMd.getType().equals(element.getType())) { throw new EvaluationError( CrudConstants.ERR_INVALID_ASSIGNMENT + arrayField + "<-" + refPath); } else { if (rvalue.getType() == RValueExpression.RValueType._value) { Value v = rvalue.getValue(); if (v.getValue() instanceof ObjectNode || v.getValue() instanceof ArrayNode) throw new EvaluationError(CrudConstants.ERR_EXPECTED_VALUE + arrayField); } } } }
private void initializeArrayField(FieldTreeNode context, ArrayAddExpression expr) { for (RValueExpression rvalue : expr.getValues()) { Path refPath = null; FieldTreeNode refMd = null; if (rvalue.getType() == RValueExpression.RValueType._dereference) { refPath = rvalue.getPath(); refMd = context.resolve(refPath); if (refMd == null) { throw new EvaluationError(CrudConstants.ERR_INVALID_DEREFERENCE + refPath); } } ArrayElement element = fieldMd.getElement(); validateArrayElement(element, refMd, rvalue, refPath); values.add( new RValueData( refPath, refMd == null ? null : refMd.getType(), rvalue.getValue(), rvalue.getType())); } }