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);
}
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;
}
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());
}
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());
}
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());
}
Aggregations