use of org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode in project yangtools by opendaylight.
the class NormalizedNodeXmlTranslationTest method withAttributes.
private static ContainerNode withAttributes() {
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> b = containerBuilder();
b.withNodeIdentifier(getNodeIdentifier("container"));
final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listBuilder = Builders.mapBuilder().withNodeIdentifier(getNodeIdentifier("list"));
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> list1Builder = Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(getNodeIdentifier("list").getNodeType(), getNodeIdentifier("uint32InList").getNodeType(), Uint32.valueOf(3)));
final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> uint32InListBuilder = Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList"));
list1Builder.withChild(uint32InListBuilder.withValue(Uint32.valueOf(3)).build());
listBuilder.withChild(list1Builder.build());
b.withChild(listBuilder.build());
final NormalizedNodeBuilder<NodeIdentifier, Object, LeafNode<Object>> booleanBuilder = Builders.leafBuilder().withNodeIdentifier(getNodeIdentifier("boolean"));
booleanBuilder.withValue(Boolean.FALSE);
b.withChild(booleanBuilder.build());
final ListNodeBuilder<Object, SystemLeafSetNode<Object>> leafListBuilder = Builders.leafSetBuilder().withNodeIdentifier(getNodeIdentifier("leafList"));
final NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafList1Builder = Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue(getNodeIdentifier("leafList").getNodeType(), "a"));
leafList1Builder.withValue("a");
leafListBuilder.withChild(leafList1Builder.build());
b.withChild(leafListBuilder.build());
return b.build();
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode 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.SystemLeafSetNode in project netconf by opendaylight.
the class RestconfImpl method toModuleEntryNode.
private static MapEntryNode toModuleEntryNode(final Module module, final DataSchemaNode moduleSchemaNode) {
checkArgument(moduleSchemaNode instanceof ListSchemaNode, "moduleSchemaNode has to be of type ListSchemaNode");
final ListSchemaNode listModuleSchemaNode = (ListSchemaNode) moduleSchemaNode;
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> moduleNodeValues = SchemaAwareBuilders.mapEntryBuilder(listModuleSchemaNode);
List<DataSchemaNode> instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(listModuleSchemaNode, "name");
final DataSchemaNode nameSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
checkState(nameSchemaNode instanceof LeafSchemaNode);
moduleNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) nameSchemaNode).withValue(module.getName()).build());
final QNameModule qNameModule = module.getQNameModule();
instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(listModuleSchemaNode, "revision");
final DataSchemaNode revisionSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
checkState(revisionSchemaNode instanceof LeafSchemaNode);
final Optional<Revision> revision = qNameModule.getRevision();
moduleNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) revisionSchemaNode).withValue(revision.map(Revision::toString).orElse("")).build());
instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(listModuleSchemaNode, "namespace");
final DataSchemaNode namespaceSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
checkState(namespaceSchemaNode instanceof LeafSchemaNode);
moduleNodeValues.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) namespaceSchemaNode).withValue(qNameModule.getNamespace().toString()).build());
instanceDataChildrenByName = ControllerContext.findInstanceDataChildrenByName(listModuleSchemaNode, "feature");
final DataSchemaNode featureSchemaNode = Iterables.getFirst(instanceDataChildrenByName, null);
checkState(featureSchemaNode instanceof LeafListSchemaNode);
final ListNodeBuilder<Object, SystemLeafSetNode<Object>> featuresBuilder = SchemaAwareBuilders.leafSetBuilder((LeafListSchemaNode) featureSchemaNode);
for (final FeatureDefinition feature : module.getFeatures()) {
featuresBuilder.withChild(SchemaAwareBuilders.leafSetEntryBuilder((LeafListSchemaNode) featureSchemaNode).withValue(feature.getQName().getLocalName()).build());
}
moduleNodeValues.withChild(featuresBuilder.build());
return moduleNodeValues.build();
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode in project netconf by opendaylight.
the class NnInstanceIdentifierToXmlTest method prepareNNCLeafList.
private static NormalizedNodeContext prepareNNCLeafList() throws URISyntaxException {
final QName cont = QName.create("instance:identifier:module", "2014-01-17", "cont");
final QName cont1 = QName.create("instance:identifier:module", "2014-01-17", "cont1");
final QName lflst11 = QName.create("augment:module:leaf:list", "2014-01-17", "lflst11");
final QName lf11 = QName.create("augment:module:leaf:list", "2014-01-17", "lf11");
final YangInstanceIdentifier yII = YangInstanceIdentifier.builder().node(cont).build();
final DataSchemaNode schemaCont = schemaContext.getDataChildByName(cont);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> dataCont = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) schemaCont);
final DataSchemaNode schemaCont1 = ((ContainerSchemaNode) schemaCont).getDataChildByName(cont1);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> dataCont1 = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) schemaCont1);
final List<DataSchemaNode> instanceLfLst11 = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) schemaCont1, lflst11.getLocalName());
final DataSchemaNode lfLst11Schema = Iterables.getFirst(instanceLfLst11, null);
final ListNodeBuilder<Object, SystemLeafSetNode<Object>> lfLst11Data = SchemaAwareBuilders.leafSetBuilder((LeafListSchemaNode) lfLst11Schema);
lfLst11Data.withChild(SchemaAwareBuilders.leafSetEntryBuilder((LeafListSchemaNode) lfLst11Schema).withValue("lflst11 value").build());
dataCont1.withChild(lfLst11Data.build());
final List<DataSchemaNode> instanceLf11 = ControllerContext.findInstanceDataChildrenByName((DataNodeContainer) schemaCont1, lf11.getLocalName());
final DataSchemaNode lf11Schema = Iterables.getFirst(instanceLf11, null);
dataCont1.withChild(SchemaAwareBuilders.leafBuilder((LeafSchemaNode) lf11Schema).withValue("/instanceidentifier/").build());
dataCont.withChild(dataCont1.build());
final NormalizedNodeContext testNormalizedNodeContext = new NormalizedNodeContext(new InstanceIdentifierContext<>(yII, schemaCont, null, schemaContext), dataCont.build());
return testNormalizedNodeContext;
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode in project netconf by opendaylight.
the class ReadDataTransactionUtil method prepareData.
/**
* Prepare and map all data from DS.
*
* @param configDataNode data node of config data
* @param stateDataNode data node of state data
* @return {@link NormalizedNode}
*/
@SuppressWarnings("unchecked")
@NonNull
private static NormalizedNode prepareData(@NonNull final NormalizedNode configDataNode, @NonNull final NormalizedNode stateDataNode) {
if (configDataNode instanceof UserMapNode) {
final CollectionNodeBuilder<MapEntryNode, UserMapNode> builder = Builders.orderedMapBuilder().withNodeIdentifier(((MapNode) configDataNode).getIdentifier());
mapValueToBuilder(((UserMapNode) configDataNode).body(), ((UserMapNode) stateDataNode).body(), builder);
return builder.build();
} else if (configDataNode instanceof MapNode) {
final CollectionNodeBuilder<MapEntryNode, SystemMapNode> builder = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(((MapNode) configDataNode).getIdentifier());
mapValueToBuilder(((MapNode) configDataNode).body(), ((MapNode) stateDataNode).body(), builder);
return builder.build();
} else if (configDataNode instanceof MapEntryNode) {
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> builder = ImmutableNodes.mapEntryBuilder().withNodeIdentifier(((MapEntryNode) configDataNode).getIdentifier());
mapValueToBuilder(((MapEntryNode) configDataNode).body(), ((MapEntryNode) stateDataNode).body(), builder);
return builder.build();
} else if (configDataNode instanceof ContainerNode) {
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> builder = Builders.containerBuilder().withNodeIdentifier(((ContainerNode) configDataNode).getIdentifier());
mapValueToBuilder(((ContainerNode) configDataNode).body(), ((ContainerNode) stateDataNode).body(), builder);
return builder.build();
} else if (configDataNode instanceof AugmentationNode) {
final DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> builder = Builders.augmentationBuilder().withNodeIdentifier(((AugmentationNode) configDataNode).getIdentifier());
mapValueToBuilder(((AugmentationNode) configDataNode).body(), ((AugmentationNode) stateDataNode).body(), builder);
return builder.build();
} else if (configDataNode instanceof ChoiceNode) {
final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> builder = Builders.choiceBuilder().withNodeIdentifier(((ChoiceNode) configDataNode).getIdentifier());
mapValueToBuilder(((ChoiceNode) configDataNode).body(), ((ChoiceNode) stateDataNode).body(), builder);
return builder.build();
} else if (configDataNode instanceof LeafNode) {
return ImmutableNodes.leafNode(configDataNode.getIdentifier().getNodeType(), configDataNode.body());
} else if (configDataNode instanceof UserLeafSetNode) {
final ListNodeBuilder<Object, UserLeafSetNode<Object>> builder = Builders.orderedLeafSetBuilder().withNodeIdentifier(((UserLeafSetNode<?>) configDataNode).getIdentifier());
mapValueToBuilder(((UserLeafSetNode<Object>) configDataNode).body(), ((UserLeafSetNode<Object>) stateDataNode).body(), builder);
return builder.build();
} else if (configDataNode instanceof LeafSetNode) {
final ListNodeBuilder<Object, SystemLeafSetNode<Object>> builder = Builders.leafSetBuilder().withNodeIdentifier(((LeafSetNode<?>) configDataNode).getIdentifier());
mapValueToBuilder(((LeafSetNode<Object>) configDataNode).body(), ((LeafSetNode<Object>) stateDataNode).body(), builder);
return builder.build();
} else if (configDataNode instanceof LeafSetEntryNode) {
return Builders.leafSetEntryBuilder().withNodeIdentifier(((LeafSetEntryNode<?>) configDataNode).getIdentifier()).withValue(configDataNode.body()).build();
} else if (configDataNode instanceof UnkeyedListNode) {
final CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> builder = Builders.unkeyedListBuilder().withNodeIdentifier(((UnkeyedListNode) configDataNode).getIdentifier());
mapValueToBuilder(((UnkeyedListNode) configDataNode).body(), ((UnkeyedListNode) stateDataNode).body(), builder);
return builder.build();
} else if (configDataNode instanceof UnkeyedListEntryNode) {
final DataContainerNodeBuilder<NodeIdentifier, UnkeyedListEntryNode> builder = Builders.unkeyedListEntryBuilder().withNodeIdentifier(((UnkeyedListEntryNode) configDataNode).getIdentifier());
mapValueToBuilder(((UnkeyedListEntryNode) configDataNode).body(), ((UnkeyedListEntryNode) stateDataNode).body(), builder);
return builder.build();
} else {
throw new RestconfDocumentedException("Unexpected node type: " + configDataNode.getClass().getName());
}
}
Aggregations