@Override public Property get(String name) throws PropertyNotFoundException { Field field = getType().getField(name); if (field == null) { return computeRemovedProperty(name); } return getChild(field); }
/** * Validates sub fields for given complex field. * * @since 7.1 */ @SuppressWarnings("unchecked") private List<ConstraintViolation> validateComplexTypeField(Schema schema, List<PathNode> path, Field field, Object value) { assert field.getType().isComplexType(); List<ConstraintViolation> violations = new ArrayList<>(); ComplexType complexType = (ComplexType) field.getType(); // this code does not support other type than Map as value if (!(value instanceof Map)) { return violations; } Map<String, Object> map = (Map<String, Object>) value; for (Field child : complexType.getFields()) { Object item = map.get(child.getName().getLocalName()); List<PathNode> subPath = new ArrayList<>(path); subPath.add(new PathNode(child)); violations.addAll(validateAnyTypeField(schema, subPath, child, item, true)); } return violations; }
private static String typeFragmentName(ComplexType type) { return type.getName(); }
public final Collection<Property> getNonPhantomChildren() { ComplexType type = getType(); if (children.size() < type.getFieldsCount()) { // populate with // unloaded props only // if needed for (Field field : type.getFields()) { getNonPhantomChild(field); // force loading non phantom props } } return Collections.unmodifiableCollection(children.values()); }
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; } }
done = new LinkedHashSet<>(); String typeName = complexType.getName(); if (done.contains(typeName)) { log.warn("Complex type " + typeName + " refers to itself recursively: " + done); for (Field field : complexType.getFields()) { String propertyName = field.getName().getPrefixedName(); String path = prefix + propertyName;
String fieldName = ct.getName() + "#anonymousList"; ct.addField(fieldName, listType, null, 0, null); } else { processModelGroup(schema, superType, name, ct, term.asModelGroup(), abstractType); maxOccur); ct.addField(element.getName(), listType, null, 0, null); if (superType != null && superType.isComplexType()) { for (Field parentField : superType.getFields()) { ct.addField(parentField.getName().getLocalName(), parentField.getType(), (String) parentField.getDefaultValue(), 0, null);
protected final void readComplex(Element element, ComplexType ctype, Map map, boolean inlineBlobs) throws IOException { Iterator<Map.Entry> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = it.next(); readProperty(element, ctype.getNamespace(), ctype.getField(entry.getKey().toString()), entry.getValue(), inlineBlobs); } }
@Override public Schema createSchema(ComplexType input) { Schema schema = Schema.createRecord(getName(input), null, input.getNamespace().prefix, false); List<Field> fields = new ArrayList<>(input.getFields().size()); for (org.nuxeo.ecm.core.schema.types.Field f : context.sort(input.getFields())) { String fieldName = context.getService().encodeName(f.getName().getLocalName()); Schema fieldSchema = context.createSchema(f.getType()); if (f.isNillable()) { fieldSchema = nullable(fieldSchema); } fields.add(new Field(fieldName, fieldSchema, null, (Object) null)); } schema.setFields(fields); return schema; }
/** * Given a document property, updates its value with the given blob. The property can be a blob list or a blob. If a * blob list the blob is appended to the list, if a blob then it will be set as the property value. Both blob list * formats are supported: the file list (blob holder list) and simple blob list. */ public static void addBlob(Property p, Blob blob) throws PropertyException { if (p.isList()) { // detect if a list of simple blobs or a list of files (blob // holder) Type ft = ((ListProperty) p).getType().getFieldType(); if (ft.isComplexType() && ((ComplexType) ft).getFieldsCount() == 1) { p.addValue(createBlobHolderMap(blob)); } else { p.addValue(blob); } } else { p.setValue(blob); } }
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); }
@Override public Collection<Property> getChildren() { ComplexType type = getType(); if (children.size() < type.getFieldsCount()) { // populate with // phantoms if needed for (Field field : type.getFields()) { getChild(field); // force loading all props including // phantoms } } return Collections.unmodifiableCollection(children.values()); }
constraints.addAll(st.getConstraints()); Field field = type.addField(elementName, fieldType, defValue, flags, constraints);
continue; clonedMap.put(k, cloneField(ctype.getField(k), k, v));
public void visitChildren(PropertyVisitor visitor, Object arg) throws PropertyException { boolean includePhantoms = visitor.acceptPhantoms(); if (includePhantoms) { for (Property property : getChildren()) { property.accept(visitor, arg); } } else { for (Field field : getType().getFields()) { Property property = getNonPhantomChild(field); if (property == null) { continue; // a phantom property not yet initialized } else if (property.isPhantom()) { continue; // a phantom property } else { property.accept(visitor, arg); } } } }
/** * Records info about one property from a complex type or schema. */ private void addPropertyInfo(ComplexType complexType, String propertyName, PropertyType propertyType, String fragmentName, String fragmentKey, boolean readonly, Type coreType, ColumnType type) { String typeName = complexType.getName(); boolean isSchema = complexType instanceof Schema; addPropertyInfo(typeName, isSchema, propertyName, propertyType, fragmentName, fragmentKey, readonly, coreType, type); }
private void fillComplexProperty(Property property, JsonNode jn) throws IOException { Entry<String, JsonNode> elNode; Iterator<Entry<String, JsonNode>> it = jn.fields(); ComplexProperty complexProperty = (ComplexProperty) property; ComplexType type = complexProperty.getType(); while (it.hasNext()) { elNode = it.next(); String elName = elNode.getKey(); Field field = type.getField(elName); if (field != null) { Property child = readProperty(property, field, elNode.getValue()); property.setValue(elName, child.getValue()); } } }
protected void findBlobPaths(ComplexType complexType, String path, Schema schema, List<String> paths) { for (Field field : complexType.getFields()) { String fieldPath = field.getName().getPrefixedName(); if (path == null) {