public List<List<T>> pathsToValue(final boolean includeValue, final Function<T, Boolean> pred) { final List<List<T>> paths = new ArrayList<>(); if (!isRoot() && pred.apply(this.value)) { List<T> path = new ArrayList<>(); if (includeValue) { path.add(this.value); } paths.add(path); } this.children().forEach(c -> { final List<List<T>> childPaths = c.pathsToValue(includeValue, pred); if (!childPaths.isEmpty() && !isRoot()) { childPaths.forEach(p -> p.add(0, this.value)); } paths.addAll(childPaths); }); return paths; }
public Set<SchemaElement> elementsForElement(final List<SchemaElement> path) { Tree<SchemaElement> tree = schemaTree(); final Deque<SchemaElement> pathStack = new ArrayDeque<>(path); while (tree != null && !pathStack.isEmpty()) { final SchemaElement cur = pathStack.pop(); tree = tree.children().stream() .filter(t -> t.value().qname().equals(cur.qname())) .findFirst() .orElse(null); } final Set<SchemaElement> ret = new HashSet<>(); if (tree != null && !tree.isRoot()) { ret.addAll(tree.children().stream() .map(Tree::value) .collect(Collectors.toList())); } return ret; }
private void applyBaseToTypes() { // FIXME: this will fail if there are multiple levels of inheritance this.types.values().stream() .filter(type -> type.base() != null) .forEach(type -> { final ComplexType baseType = this.types.get(type.base()); if (baseType != null) { baseType.elements().children().forEach(t -> type.elements().addChild(t)); baseType.attributes().forEach(type::addAttribute); } }); }
public Set<String> attributesForElement(final List<SchemaElement> path) { Tree<SchemaElement> tree = schemaTree(); final Deque<SchemaElement> pathStack = new ArrayDeque<>(path); while (tree != null && !pathStack.isEmpty()) { final SchemaElement cur = pathStack.pop(); tree = tree.children().stream() .filter(t -> t.value().qname().equals(cur.qname())) .findFirst() .orElse(null); } final Set<String> ret = new HashSet<>(); if (tree != null && !tree.isRoot()) { ret.addAll(tree.value().attributes()); } return ret; }
private void resolveElementReferences(final Tree<SchemaElement> tree) { final SchemaElement el = tree.value(); if (el != null && el.isReference()) { final SchemaElement realEl = this.elements.get(el.qname()); el.delegate(realEl); //FIXME: what about child elements? we can't capture that currently } tree.children().forEach(this::resolveElementReferences); }
private void applyTypesToElement(final Tree<SchemaElement> tree) { final SchemaElement el = tree.value(); if (el != null) { if (el.base() != null) { applyTypeToElement(this.types.get(el.base()), tree); } if (el.type() != null) { applyTypeToElement(this.types.get(el.type()), tree); } } tree.children().forEach(this::applyTypesToElement); }
private void applyTypeToElement(final ComplexType type, final Tree<SchemaElement> tree) { if (type != null && !tree.value().isTypeApplied(type.name())) { tree.value().addAppliedType(type.name()); tree.value().addAttributes(type.attributes()); type.elements().children().forEach(tree::addChild); } }