@Override public FieldPath buildFieldPath(String remainFieldName) { if (remainFieldName.length() == 0) { return new FieldPath(); } String currFieldName = remainFieldName; String subFieldName = ""; for (int i = 0; i < remainFieldName.length(); i++) { if (remainFieldName.charAt(i) == '.') { currFieldName = remainFieldName.substring(0, i); subFieldName = remainFieldName.substring(i + 1); break; } else if (remainFieldName.charAt(i) == '{' || remainFieldName.charAt(i) == '[') { currFieldName = remainFieldName.substring(0, i); subFieldName = remainFieldName.substring(i); break; } } Field f = getField(currFieldName); if (f != null) { FieldPath fieldPath = f.getDataType().buildFieldPath(subFieldName); List<FieldPathEntry> tmpPath = new ArrayList<FieldPathEntry>(fieldPath.getList()); tmpPath.add(0, FieldPathEntry.newStructFieldEntry(f)); return new FieldPath(tmpPath); } else { throw new IllegalArgumentException("Field '" + currFieldName + "' not found in type " + this); } }
@Override protected void checkCompatibility(DataType fieldType) { if (fieldType instanceof ArrayDataType) { if (!(value instanceof IntegerFieldValue)) { throw new IllegalArgumentException("Expected integer, got " + value.getClass().getName() + "."); } update.checkCompatibility(((ArrayDataType)fieldType).getNestedType()); } else if (fieldType instanceof WeightedSetDataType) { ((WeightedSetDataType)fieldType).getNestedType().createFieldValue().assign(value); update.checkCompatibility(DataType.INT); } else if (fieldType instanceof StructuredDataType) { if (!(value instanceof StringFieldValue)) { throw new IllegalArgumentException("Expected string, got " + value.getClass().getName() + "."); } Field field = ((StructuredDataType)fieldType).getField(((StringFieldValue)value).getString()); if (field == null) { throw new IllegalArgumentException("Field '" + value + "' not found."); } update.checkCompatibility(field.getDataType()); } else { throw new UnsupportedOperationException("Field type " + fieldType.getName() + " not supported."); } }
public static boolean isComplete(Field field, ValueUpdate update) { if (update instanceof AssignValueUpdate) { return true; } if (!(update instanceof MapValueUpdate)) { return false; } DataType fieldType = field.getDataType(); if (!(fieldType instanceof StructuredDataType)) { return false; } field = ((StructuredDataType)fieldType).getField(String.valueOf(update.getValue())); if (field == null) { return false; } return isComplete(field, ((MapValueUpdate)update).getUpdate()); }
@Override protected void doVerify(VerificationContext context) { DataType input = context.getValue(); if (!(input instanceof StructuredDataType)) { throw new VerificationException(this, "Expected structured input, got " + input.getName() + "."); } Field field = ((StructuredDataType)input).getField(fieldName); if (field == null) { throw new VerificationException(this, "Field '" + fieldName + "' not found in struct type '" + input.getName() + "'"); } context.setValue(field.getDataType()); }