if (type instanceof SimpleTypeImpl) { type = type.getSuperType(); switch (type.getName()) { case StringType.ID: return new StringProperty(parent, field, flags); return new ExternalBlobProperty(parent, field, flags); if (type.isSimpleType()) { return new ScalarProperty(parent, field, flags); } else if (type.isComplexType()) { return new MapProperty(parent, field, flags); } else if (type.isListType()) { if (((ListType) type).isArray()) { return new ArrayProperty(parent, field, flags); throw new IllegalArgumentException("Unsupported field type: " + field.getType().getName());
@Override public Serializable normalize(Object value) throws PropertyConversionException { if (isNormalized(value)) { return (Serializable) value; } if (value.getClass() == Date.class) { Calendar cal = Calendar.getInstance(); cal.setTime((Date) value); return cal; } if (value instanceof String) { String string = (String) value; if (string.length() == 0) { return null; } return (Calendar) field.getType().decode(value.toString()); } throw new PropertyConversionException(value.getClass(), Calendar.class); }
/** * 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; }
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 */ @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(); }
@Override public String toString() { return name + " [" + type.getName() + ']'; }
protected boolean isDomain(DocumentModel documentModel) { Type type = documentModel.getDocumentType(); while (type != null) { if ("Domain".equals(type.getName())) { return true; } type = type.getSuperType(); } return false; }
if (type instanceof SimpleTypeImpl) { type = type.getSuperType(); String typeName = type.getName(); if (attribute == null) { return defaultValue; return defaultValue; } else if (type.isListType()) { List<String> parsedItems = new LinkedList<>(); NamingEnumeration<Object> values = null;
if (type.isSimpleType()) { String encodedValue = type.encode(value); if (encodedValue != null) { } else if (type.isComplexType()) { ComplexType ctype = (ComplexType) type; if (TypeConstants.isContentType(ctype)) { readComplex(element, ctype, (Map) value, inlineBlobs); } else if (type.isListType()) { if (value instanceof List) { readList(element, (ListType) type, (List) value, inlineBlobs);
@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())); } else if (input.isListType()) { Schema array = Schema.createArray(context.createSchema(((ListType) input).getFieldType())); String logicalType = ((ListType) input).isArray() ? "array" : "list"; new LogicalType(logicalType).addToSchema(array); return array; } else if (input.isComplexType()) { return complexTypeFactory.createSchema((ComplexType) input); } else if (input.isCompositeType()) { throw new NotImplementedException("Composite types are not supported yet");
String typeValue; Set<Constraint> itemConstraints = null; if (field.getType().isListType()) { ListType lt = (ListType) field.getType(); Type type = lt.getFieldType(); itemConstraints = type.getConstraints(); while (!(type instanceof PrimitiveType)) { type = type.getSuperType(); typeValue = type.getName() + "[]"; } else { Type type = field.getType(); while (!(type instanceof PrimitiveType)) { type = type.getSuperType(); typeValue = type.getName();
/** * 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); } } }
if (type.isSimpleType()) { } else if (type.isComplexType()) { if (fieldType.isSimpleType()) {
return null; if (type.isSimpleType()) { return type.decode(element.getText()); } else if (type.isListType()) { ListType ltype = (ListType) type; List<Object> list = new ArrayList<>(); if (ftype.isSimpleType()) { // these are stored as arrays Class klass = getFieldClass(ftype); if (klass.isPrimitive()) {
protected Serializable getFieldValue(Field field, String stringValue, ZipFile zip) { Serializable fieldValue = null; Type type = field.getType(); if (type.isSimpleType()) { if (type instanceof SimpleTypeImpl) { type = type.getSuperType(); return null; } else if (type.isComplexType() && TypeConstants.CONTENT.equals(field.getName().getLocalName())) { ZipEntry blobIndex = zip.getEntry(stringValue); if (blobIndex != null) {
@Override public boolean isSuperTypeOf(Type type) { Type t = type; do { if (this == t) { return true; } t = t.getSuperType(); } while (t != null); return false; }
} else { Type elType = ((ListType) p.getType()).getFieldType(); if (elType.isSimpleType()) { p.setValue(ar); } else if ("content".equals(elType.getName())) {
@Override public boolean isComplex() { return getType().isComplexType(); }
@Override public boolean isScalar() { return getType().isSimpleType(); }
@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; }