Search in sources :

Example 1 with UserMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.UserMapNode in project yangtools by opendaylight.

the class SchemaOrderedNormalizedNodeWriterTest method testWrite.

@Test
public void testWrite() throws XMLStreamException, IOException, SAXException {
    final StringWriter stringWriter = new StringWriter();
    final XMLStreamWriter xmlStreamWriter = factory.createXMLStreamWriter(stringWriter);
    EffectiveModelContext schemaContext = getSchemaContext("/bug1848/foo.yang");
    NormalizedNodeStreamWriter writer = XMLStreamNormalizedNodeStreamWriter.create(xmlStreamWriter, schemaContext);
    try (SchemaOrderedNormalizedNodeWriter nnw = new SchemaOrderedNormalizedNodeWriter(writer, schemaContext)) {
        List<MapEntryNode> rule1Names = new ArrayList<>();
        rule1Names.add(ImmutableNodes.mapEntry(createQName(FOO_NAMESPACE, RULE_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "rule1"));
        rule1Names.add(ImmutableNodes.mapEntry(createQName(FOO_NAMESPACE, RULE_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "rule2"));
        List<MapEntryNode> rule2Names = new ArrayList<>();
        rule1Names.add(ImmutableNodes.mapEntry(createQName(FOO_NAMESPACE, RULE_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "rule3"));
        rule1Names.add(ImmutableNodes.mapEntry(createQName(FOO_NAMESPACE, RULE_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "rule4"));
        UserMapNode rules1 = Builders.orderedMapBuilder().withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, RULE_NODE)).withValue(rule1Names).build();
        UserMapNode rules2 = Builders.orderedMapBuilder().withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, RULE_NODE)).withValue(rule2Names).build();
        List<MapEntryNode> policyNodes = new ArrayList<>();
        final MapEntryNode pn1 = ImmutableNodes.mapEntryBuilder(createQName(FOO_NAMESPACE, POLICY_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "policy1").withChild(rules1).build();
        final MapEntryNode pn2 = ImmutableNodes.mapEntryBuilder(createQName(FOO_NAMESPACE, POLICY_NODE), createQName(FOO_NAMESPACE, NAME_NODE), "policy2").withChild(rules2).build();
        policyNodes.add(pn1);
        policyNodes.add(pn2);
        UserMapNode policy = Builders.orderedMapBuilder().withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, POLICY_NODE)).withValue(policyNodes).build();
        ContainerNode root = Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, "root")).withChild(policy).build();
        nnw.write(root);
    }
    XMLAssert.assertXMLIdentical(new Diff(EXPECTED_1, stringWriter.toString()), true);
}
Also used : StringWriter(java.io.StringWriter) SchemaOrderedNormalizedNodeWriter(org.opendaylight.yangtools.yang.data.impl.schema.SchemaOrderedNormalizedNodeWriter) Diff(org.custommonkey.xmlunit.Diff) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ArrayList(java.util.ArrayList) NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 2 with UserMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.UserMapNode in project yangtools by opendaylight.

the class NormalizedNodeWriter method wasProcessedAsCompositeNode.

protected boolean wasProcessedAsCompositeNode(final NormalizedNode node) throws IOException {
    if (node instanceof ContainerNode) {
        final ContainerNode n = (ContainerNode) node;
        writer.startContainerNode(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof MapEntryNode) {
        return writeMapEntryNode((MapEntryNode) node);
    }
    if (node instanceof UnkeyedListEntryNode) {
        final UnkeyedListEntryNode n = (UnkeyedListEntryNode) node;
        writer.startUnkeyedListItem(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof ChoiceNode) {
        final ChoiceNode n = (ChoiceNode) node;
        writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof AugmentationNode) {
        final AugmentationNode n = (AugmentationNode) node;
        writer.startAugmentationNode(n.getIdentifier());
        return writeChildren(n.body());
    }
    if (node instanceof UnkeyedListNode) {
        final UnkeyedListNode n = (UnkeyedListNode) node;
        writer.startUnkeyedList(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof UserMapNode) {
        final UserMapNode n = (UserMapNode) node;
        writer.startOrderedMapNode(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof SystemMapNode) {
        final SystemMapNode n = (SystemMapNode) node;
        writer.startMapNode(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof UserLeafSetNode) {
        final UserLeafSetNode<?> n = (UserLeafSetNode<?>) node;
        writer.startOrderedLeafSet(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    if (node instanceof SystemLeafSetNode) {
        final SystemLeafSetNode<?> n = (SystemLeafSetNode<?>) node;
        writer.startLeafSet(n.getIdentifier(), childSizeHint(n.body()));
        return writeChildren(n.body());
    }
    return false;
}
Also used : SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) ChoiceNode(org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode)

Example 3 with UserMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.UserMapNode in project yangtools by opendaylight.

the class OrderedListTest method modification2.

public void modification2() throws DataValidationFailedException {
    UserMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval3", "plfval3updated")).withChild(createParentOrderedListEntry("pkval4", "plfval4")).withChild(createParentOrderedListEntry("pkval5", "plfval5")).build();
    ContainerNode parentContainerNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode).build()).build();
    DataTreeModification treeModification = inMemoryDataTree.takeSnapshot().newModification();
    YangInstanceIdentifier path1 = YangInstanceIdentifier.of(parentContainer);
    treeModification.merge(path1, parentContainerNode);
    UserMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(childOrderedList)).withChild(createChildOrderedListEntry("chkval1", "chlfval1updated")).withChild(createChildOrderedListEntry("chkval2", "chlfval2updated")).withChild(createChildOrderedListEntry("chkval3", "chlfval3")).build();
    YangInstanceIdentifier path2 = YangInstanceIdentifier.of(parentContainer).node(childContainer).node(parentOrderedList).node(createParentOrderedListEntryPath("pkval2")).node(childOrderedList);
    treeModification.merge(path2, childOrderedListNode);
    treeModification.ready();
    inMemoryDataTree.validate(treeModification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification));
    DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    Optional<NormalizedNode> readNode = snapshotAfterCommits.readNode(path1);
    assertTrue(readNode.isPresent());
    readNode = snapshotAfterCommits.readNode(path2);
    assertTrue(readNode.isPresent());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 4 with UserMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.UserMapNode in project yangtools by opendaylight.

the class OrderedListTest method modification1.

public void modification1() throws DataValidationFailedException {
    UserMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval1", "plfval1")).withChild(createParentOrderedListEntry("pkval2", "plfval2")).withChild(createParentOrderedListEntry("pkval3", "plfval3")).build();
    ContainerNode parentContainerNode = Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode).build()).build();
    YangInstanceIdentifier path1 = YangInstanceIdentifier.of(parentContainer);
    DataTreeModification treeModification = inMemoryDataTree.takeSnapshot().newModification();
    treeModification.write(path1, parentContainerNode);
    UserMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(childOrderedList)).withChild(createChildOrderedListEntry("chkval1", "chlfval1")).withChild(createChildOrderedListEntry("chkval2", "chlfval2")).build();
    YangInstanceIdentifier path2 = YangInstanceIdentifier.of(parentContainer).node(childContainer).node(parentOrderedList).node(createParentOrderedListEntryPath("pkval2")).node(childOrderedList);
    treeModification.write(path2, childOrderedListNode);
    treeModification.ready();
    inMemoryDataTree.validate(treeModification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification));
    DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    Optional<NormalizedNode> readNode = snapshotAfterCommits.readNode(path1);
    assertTrue(readNode.isPresent());
    readNode = snapshotAfterCommits.readNode(path2);
    assertTrue(readNode.isPresent());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) DataTreeSnapshot(org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)

Example 5 with UserMapNode

use of org.opendaylight.yangtools.yang.data.api.schema.UserMapNode in project netconf by opendaylight.

the class SchemaContextHandler method addSubmodules.

/**
 * Mapping submodules of specific module.
 *
 * @param module module with submodules
 * @param mapEntryBuilder mapEntryBuilder of parent for mapping children
 * @param ietfYangLibraryModule ietf-yang-library module
 * @param context schema context
 */
private static void addSubmodules(final ModuleLike module, final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder, final SchemaContext context) {
    final CollectionNodeBuilder<MapEntryNode, UserMapNode> mapBuilder = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(Submodule.QNAME));
    for (final var submodule : module.getSubmodules()) {
        fillMapByModules(mapBuilder, Submodule.QNAME, true, submodule, context);
    }
    mapEntryBuilder.withChild(mapBuilder.build());
}
Also used : NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)

Aggregations

UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)18 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)11 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)8 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)8 AugmentationNode (org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode)7 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)7 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)7 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)7 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)6 UserLeafSetNode (org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 Test (org.junit.Test)4 QName (org.opendaylight.yangtools.yang.common.QName)4 AugmentationIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier)4 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)4 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)4 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3