@Override public boolean isList() { return getType().isListType(); }
/** * This method should be the only one to create {@link ConstraintViolation}. * * @since 7.1 */ private List<ConstraintViolation> validateSimpleTypeField(Schema schema, List<PathNode> path, Field field, Object value) { Type type = field.getType(); assert type.isSimpleType() || type.isListType(); // list type to manage ArrayProperty List<ConstraintViolation> violations = new ArrayList<>(); Set<Constraint> constraints; if (type.isListType()) { // ArrayProperty constraints = ((ListType) type).getFieldType().getConstraints(); } else { constraints = field.getConstraints(); } for (Constraint constraint : constraints) { if (!constraint.validate(value)) { ConstraintViolation violation = new ConstraintViolation(schema, path, constraint, value); violations.add(violation); } } return violations; }
if (field != null && field.getType().isListType()) {
clone = value; } else if (type.isListType()) { ListType ltype = (ListType) type; Field lfield = ltype.getField();
assert field.getType().isListType(); List<ConstraintViolation> violations = new ArrayList<>(); Collection<?> castedValue = null;
/** * @since 7.1 */ @SuppressWarnings("rawtypes") private List<ConstraintViolation> validateAnyTypeField(Schema schema, List<PathNode> path, Field field, Object value, boolean validateSubProperties) { if (field.getType().isSimpleType()) { return validateSimpleTypeField(schema, path, field, value); } else if (field.getType().isComplexType()) { List<ConstraintViolation> res = new ArrayList<>(); if (!field.isNillable() && (value == null || (value instanceof Map && ((Map) value).isEmpty()))) { addNotNullViolation(res, schema, path); } if (validateSubProperties) { List<ConstraintViolation> subs = validateComplexTypeField(schema, path, field, value); if (subs != null) { res.addAll(subs); } } return res; } else if (field.getType().isListType()) { // maybe validate the list type here if (validateSubProperties) { return validateListTypeField(schema, path, field, value); } } // unrecognized type : ignored return Collections.emptyList(); }
boolean dirtyOnly) { Field field = prop.getField(); assert field.getType().isListType(); List<ConstraintViolation> violations = new ArrayList<>(); Serializable value = prop.getValue();
protected boolean compatibleTypes(Type targetType, Type sourceType) { if (!sourceType.getName().equals(targetType.getName())) { return false; } if (sourceType.isComplexType()) { for (Field field : ((ComplexType) sourceType).getFields()) { Field targetField = ((ComplexType) targetType).getField(field.getName()); if (targetField == null || !field.getType().equals(targetField.getType())) { return false; } } } if (sourceType.isListType()) { if (!((ListType) sourceType).getFieldType().equals(((ListType) targetType).getFieldType())) { return false; } if (((ListType) sourceType).getFieldType().isComplexType()) { return compatibleTypes(((ListType) targetType).getFieldType(), ((ListType) sourceType).getFieldType()); } } return true; } }
/** * @since 7.1 */ private List<ConstraintViolation> validateAnyTypeProperty(Schema schema, List<PathNode> path, Property prop, boolean dirtyOnly, boolean validateSubProperties) { Field field = prop.getField(); if (!dirtyOnly || prop.isDirty()) { if (field.getType().isSimpleType()) { return validateSimpleTypeProperty(schema, path, prop, dirtyOnly); } else if (field.getType().isComplexType()) { // ignore for now the case when the complex property is null with a null contraints because it's // currently impossible if (validateSubProperties) { return validateComplexTypeProperty(schema, path, prop, dirtyOnly); } } else if (field.getType().isListType()) { if (validateSubProperties) { return validateListTypeProperty(schema, path, prop, dirtyOnly); } } } // unrecognized type : ignored return Collections.emptyList(); }
if (type.isSimpleType()) { continue; // not binary text } else if (type.isListType()) { Type fieldType = ((ListType) type).getFieldType(); if (fieldType.isComplexType()) {
} else if (type.isComplexType()) { return new MapProperty(parent, field, flags); } else if (type.isListType()) { if (((ListType) type).isArray()) { return new ArrayProperty(parent, field, flags);
@Override public Map<String, Object> newInstance() { if (TypeConstants.isContentType(this)) { // NXP-912: should return null for a blob. Since there is no // pluggable adapter mechanism on types, and since document model // properties consider that every complex property named "content" // should be dealt with a BlobProperty, this is hardcoded here. return null; } Map<String, Object> map = new HashMap<String, Object>(); for (Field field : fields.values()) { Object value; Type type = field.getType(); if (type.isComplexType()) { value = type.newInstance(); } else if (type.isListType()) { value = new ArrayList<Object>(); } else { value = field.getDefaultValue(); } map.put(field.getName().getLocalName(), value); } return map; }
/** * Check if the given field type store a list of values and if the given value is compatible with the given type. We * assume the Type store a list of scalar values, not complex types. */ protected void checkFieldType(Type type, Object value) throws OperationException { if (!type.isListType()) { throw new OperationException("Only multivalued types can be set using this operation"); } ListType listType = (ListType) type; Type itemType = listType.getFieldType(); if (itemType.isComplexType()) { throw new UnsupportedOperationException("Manage only lists of scalar items"); } try { if (itemType.convert(value) == null) { String exceptionReason = String.format("Given type \"%s\" value is not a %s type", value, itemType.getName()); throw new UnsupportedOperationException(exceptionReason); } } catch (TypeException | ClassCastException e) { String exceptionReason = String.format("Given type \"%s\" value is not a %s type", value, itemType.getName()); throw new OperationException(exceptionReason, e); } } }
/** * Checks if a field is a primitive type or array. */ private static boolean isScalarField(Field field) { Type fieldType = field.getType(); if (fieldType.isComplexType()) { // complex type return false; } if (!fieldType.isListType()) { // primitive type return true; } // array or complex list? return ((ListType) fieldType).getFieldType().isSimpleType(); }
protected Field getField(Field parent, String subFieldName, boolean finalCall) { if (parent != null) { Type type = parent.getType(); if (type.isListType()) { ListType listType = (ListType) type; // remove indexes in case of multiple values if ("*".equals(subFieldName)) { if (!finalCall) { return parent; } else { return resolveSubField(listType, null, true); } } try { Integer.valueOf(subFieldName); if (!finalCall) { return parent; } else { return resolveSubField(listType, null, true); } } catch (NumberFormatException e) { return resolveSubField(listType, subFieldName, false); } } else if (type.isComplexType()) { return ((ComplexType) type).getField(subFieldName); } } return null; }
readComplex(element, ctype, (Map) value, inlineBlobs); } else if (type.isListType()) { if (value instanceof List) { readList(element, (ListType) type, (List) value, inlineBlobs);
protected void writeField(JsonGenerator jg, Field field) throws IOException { if (!field.getType().isComplexType()) { if (field.getType().isListType()) { ListType lt = (ListType) field.getType(); if (lt.getFieldType().isComplexType()) {
protected void walkType(Type type, String path, String addPrefix) { if (type.isSimpleType()) { walkSimpleType(type, path, addPrefix); } else if (type.isListType()) { String listPath = path + "/*"; Type ftype = ((ListType) type).getField().getType(); if (ftype.isComplexType()) { // complex list walkComplexType((ComplexType) ftype, listPath, addPrefix); } else { // array walkSimpleType(ftype, listPath, addPrefix); } } else { // complex type ComplexType ctype = (ComplexType) type; walkComplexType(ctype, path, addPrefix); } }
if (type.isListType()) { ListType ltype = (ListType) type; if (ltype.isScalarList() && !decodeStringListAsJSON) {
return new LogicalType(getName(input)).addToSchema(createSchema(input.getSuperType())); } else if (input.isListType()) { Schema array = Schema.createArray(context.createSchema(((ListType) input).getFieldType())); String logicalType = ((ListType) input).isArray() ? "array" : "list";