Search in sources :

Example 1 with NormalizedNodeContainerBuilder

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;
}
Also used : NormalizedNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder) NormalizedNodeContainerBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder)

Example 2 with NormalizedNodeContainerBuilder

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;
}
Also used : NormalizedNodeContainerBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder) TreeNode(org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode) MutableTreeNode(org.opendaylight.yangtools.yang.data.tree.impl.node.MutableTreeNode) MutableTreeNode(org.opendaylight.yangtools.yang.data.tree.impl.node.MutableTreeNode)

Example 3 with NormalizedNodeContainerBuilder

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;
}
Also used : NormalizedNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder) NormalizedNodeContainerBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder)

Example 4 with NormalizedNodeContainerBuilder

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));
}
Also used : NormalizedNodeContainerBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder)

Example 5 with NormalizedNodeContainerBuilder

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();
}
Also used : NormalizedNodeContainerBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder) QName(org.opendaylight.yangtools.yang.common.QName) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Aggregations

NormalizedNodeContainerBuilder (org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeContainerBuilder)6 NormalizedNodeBuilder (org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder)2 MutableTreeNode (org.opendaylight.yangtools.yang.data.tree.impl.node.MutableTreeNode)2 TreeNode (org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode)2 QName (org.opendaylight.yangtools.yang.common.QName)1 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)1