@Override public boolean isScalar() { return getType().isSimpleType(); }
if (type.isSimpleType()) {
/** * @since 7.1 */ private List<ConstraintViolation> validateSimpleTypeProperty(Schema schema, List<PathNode> path, Property prop, boolean dirtyOnly) { Field field = prop.getField(); assert field.getType().isSimpleType() || prop.isScalar(); List<ConstraintViolation> violations = new ArrayList<>(); Serializable value = prop.getValue(); Object defaultValue = field.getDefaultValue(); // check nullity constraint only if field doesn't have a default value (phantom case) if (prop.isPhantom() && defaultValue == null || value == null) { if (!field.isNillable()) { addNotNullViolation(violations, schema, path); } } else { violations.addAll(validateSimpleTypeField(schema, path, field, value)); } return violations; }
/** * @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(); }
/** * 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; }
/** * @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()) {
@Override public boolean isScalarList() { return field.getType().isSimpleType(); } }
return new ExternalBlobProperty(parent, field, flags); if (type.isSimpleType()) { return new ScalarProperty(parent, field, flags); } else if (type.isComplexType()) {
public static Class<?> getClass(Type type) { if (type.isSimpleType() && !((SimpleType) type).isPrimitive()) { return getClass(((SimpleType) type).getPrimitiveType()); } return types2Class.get(type); }
if (fieldType.isSimpleType()) { Object value; if (fieldType == DateType.INSTANCE && nodeEntry.getValue().isIntegralNumber()) {
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); }
/** * 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(); }
if (type.isSimpleType()) { if (fieldType.isSimpleType()) {
String name = field.getName().getPrefixedName(); name = internalName(name); if (type.isSimpleType()) { if (fieldType.isSimpleType()) {
if (type.isSimpleType()) {
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws OperationException { Property p = doc.getProperty(xpath); Type type = p.getField().getType(); if (!type.isSimpleType()) { throw new OperationException("Only scalar types can be set using update operation"); } if (value == null) { p.setValue(null); } else if (value.getClass() == String.class) { p.setValue(((SimpleType) type).getPrimitiveType().decode((String) value)); } else { p.setValue(value); } if (save) { doc = session.saveDocument(doc); } return doc; }
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); } }
@Override public Schema createSchema(Type input) { if (input.isSimpleType()) { if (input == IntegerType.INSTANCE) { return Schema.create(org.apache.avro.Schema.Type.INT); } else if (input == DateType.INSTANCE) { return LogicalTypes.timestampMillis().addToSchema(Schema.create(org.apache.avro.Schema.Type.LONG)); } else if (input.getSuperType() != null && input.getSuperType().isSimpleType()) { return new LogicalType(getName(input)).addToSchema(createSchema(input.getSuperType()));
if (!type.isSimpleType()) { if (type.isListType()) { ListType ltype = (ListType) type;