use of org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder in project yangtools by opendaylight.
the class ImmutableNormalizedNodeStreamWriter method currentScalar.
@SuppressWarnings("rawtypes")
private NormalizedNodeBuilder currentScalar() {
final NormalizedNodeBuilder current = current();
checkState(!(current instanceof NormalizedNodeContainerBuilder), "Unexpected node container %s", current);
return current;
}
use of org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder in project yangtools by opendaylight.
the class AbstractNodeContainerModificationStrategy method applyTouch.
@Override
protected TreeNode applyTouch(final ModifiedNode modification, final TreeNode currentMeta, final Version version) {
/*
* The user may have issued an empty merge operation. In this case we:
* - do not perform a data tree mutation
* - do not pass GO, and
* - do not collect useless garbage.
* It also means the ModificationType is UNMODIFIED.
*/
final Collection<ModifiedNode> children = modification.getChildren();
if (!children.isEmpty()) {
@SuppressWarnings("rawtypes") final NormalizedNodeContainerBuilder dataBuilder = support.createBuilder(currentMeta.getData());
final MutableTreeNode newMeta = currentMeta.mutable();
newMeta.setSubtreeVersion(version);
final TreeNode ret = mutateChildren(newMeta, dataBuilder, version, children);
/*
* It is possible that the only modifications under this node were empty merges, which were turned into
* UNMODIFIED. If that is the case, we can turn this operation into UNMODIFIED, too, potentially cascading
* it up to root. This has the benefit of speeding up any users, who can skip processing child nodes.
*
* In order to do that, though, we have to check all child operations are UNMODIFIED.
*
* Let's do precisely that, stopping as soon we find a different result.
*/
for (final ModifiedNode child : children) {
if (child.getModificationType() != ModificationType.UNMODIFIED) {
modification.resolveModificationType(ModificationType.SUBTREE_MODIFIED);
return ret;
}
}
}
// The merge operation did not have any children, or all of them turned out to be UNMODIFIED, hence do not
// replace the metadata node.
modification.resolveModificationType(ModificationType.UNMODIFIED);
return currentMeta;
}
use of org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder in project yangtools by opendaylight.
the class ImmutableNormalizedNodeStreamWriter method currentContainer.
@SuppressWarnings("rawtypes")
private NormalizedNodeContainerBuilder currentContainer() {
final NormalizedNodeBuilder current = current();
if (current == null) {
return null;
}
checkState(current instanceof NormalizedNodeContainerBuilder, "%s is not a node container", current);
return (NormalizedNodeContainerBuilder) current;
}
use of org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder in project yangtools by opendaylight.
the class ImmutableNormalizedNodeStreamWriter method writeChild.
/**
* Add a child not to the currently-open builder.
*
* @param child A new child
* @throws NullPointerException if {@code child} is null
* @throws IllegalStateException if there is no open builder
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
protected final void writeChild(final NormalizedNode child) {
final NormalizedNodeContainerBuilder current = currentContainer();
checkState(current != null, "Reached top level node, which could not be closed in this writer.");
current.addChild(requireNonNull(child));
}
use of org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder in project yangtools by opendaylight.
the class InstanceIdToCompositeNodes method create.
@Override
@SuppressWarnings("unchecked")
final NormalizedNode create(final PathArgument first, final Iterator<PathArgument> others) {
if (!isMixin()) {
final QName type = getIdentifier().getNodeType();
if (type != null) {
final QName firstType = first.getNodeType();
checkArgument(type.equals(firstType), "Node QName must be %s was %s", type, firstType);
}
}
@SuppressWarnings("rawtypes") final NormalizedNodeContainerBuilder builder = createBuilder(first);
if (others.hasNext()) {
final PathArgument childPath = others.next();
final InstanceIdToNodes<?> childOp = getChildOperation(childPath);
builder.addChild(childOp.create(childPath, others));
}
return builder.build();
}
Aggregations