Search in sources :

Example 1 with SystemLeafSetNode

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();
}
Also used : SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) LeafSetEntryNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) NodeWithValue(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue)

Example 2 with SystemLeafSetNode

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;
}
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 SystemLeafSetNode

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();
}
Also used : SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) Revision(org.opendaylight.yangtools.yang.common.Revision) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) FeatureDefinition(org.opendaylight.yangtools.yang.model.api.FeatureDefinition)

Example 4 with SystemLeafSetNode

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;
}
Also used : SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) LeafListSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) QName(org.opendaylight.yangtools.yang.common.QName) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NormalizedNodeContext(org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)

Example 5 with SystemLeafSetNode

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());
    }
}
Also used : AugmentationIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier) SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) UnkeyedListEntryNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) SystemMapNode(org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode) UserMapNode(org.opendaylight.yangtools.yang.data.api.schema.UserMapNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode) ListNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.ListNodeBuilder) LeafNode(org.opendaylight.yangtools.yang.data.api.schema.LeafNode) 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) UnkeyedListNode(org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode) LeafSetEntryNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) NodeIdentifierWithPredicates(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates) SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) LeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode) UserLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode) CollectionNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.CollectionNodeBuilder) DataContainerNodeBuilder(org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder) AugmentationNode(org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

SystemLeafSetNode (org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode)6 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)4 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)3 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)3 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)2 AugmentationNode (org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode)2 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)2 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)2 LeafSetEntryNode (org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode)2 UnkeyedListEntryNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode)2 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)2 UserLeafSetNode (org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode)2 UserMapNode (org.opendaylight.yangtools.yang.data.api.schema.UserMapNode)2 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)2 FeatureDefinition (org.opendaylight.yangtools.yang.model.api.FeatureDefinition)2 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)2 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)2 NonNull (org.eclipse.jdt.annotation.NonNull)1 NormalizedNodeContext (org.opendaylight.netconf.sal.rest.impl.NormalizedNodeContext)1