/** * 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; }
public ListTypeImpl(String schema, String name, Type type, String fieldName, String defaultValue, int flags, Set<Constraint> constraints, int minOccurs, int maxOccurs) { super(null, schema, name); if (fieldName == null) { isArray = true; fieldName = "item"; } this.type = type; // if the list is an array, there's no field constraint (notnull) Collection<Constraint> computedConstraints = isArray ? type.getConstraints() : constraints; field = new FieldImpl(QName.valueOf(fieldName), this, type, defaultValue, flags, computedConstraints); this.minOccurs = minOccurs; this.maxOccurs = maxOccurs; this.defaultValue = defaultValue; }
protected static Field createField(ComplexType type, XSAttributeDecl element, Type fieldType, boolean isNillable) { String elementName = element.getName(); XmlString dv = element.getDefaultValue(); String defValue = null; if (dv != null) { defValue = dv.value; } int flags = 0; if (defValue == null) { dv = element.getFixedValue(); if (dv != null) { defValue = dv.value; flags |= Field.CONSTANT; } } Set<Constraint> constraints = new HashSet<>(); if (!isNillable) { constraints.add(NotNullConstraint.get()); } if (fieldType.isSimpleType()) { constraints.addAll(fieldType.getConstraints()); } return type.addField(elementName, fieldType, defValue, flags, constraints); }
ListType lt = (ListType) field.getType(); Type type = lt.getFieldType(); itemConstraints = type.getConstraints(); while (!(type instanceof PrimitiveType)) { type = type.getSuperType();