Search in sources :

Example 1 with FeatureDefinition

use of org.opendaylight.yangtools.yang.model.api.FeatureDefinition 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 2 with FeatureDefinition

use of org.opendaylight.yangtools.yang.model.api.FeatureDefinition in project yangtools by opendaylight.

the class YinFileFeatureStmtTest method testFeature.

@Test
public void testFeature() {
    Module testModule = context.findModules("yang-with-features").iterator().next();
    assertNotNull(testModule);
    Collection<? extends FeatureDefinition> features = testModule.getFeatures();
    assertEquals(2, features.size());
    Iterator<? extends FeatureDefinition> featuresIterator = features.iterator();
    FeatureDefinition feature = featuresIterator.next();
    assertThat(feature.getQName().getLocalName(), anyOf(is("arbitrary-names"), is("pre-provisioning")));
    feature = featuresIterator.next();
    assertThat(feature.getQName().getLocalName(), anyOf(is("arbitrary-names"), is("pre-provisioning")));
}
Also used : Module(org.opendaylight.yangtools.yang.model.api.Module) FeatureDefinition(org.opendaylight.yangtools.yang.model.api.FeatureDefinition) Test(org.junit.Test)

Example 3 with FeatureDefinition

use of org.opendaylight.yangtools.yang.model.api.FeatureDefinition in project yangtools by opendaylight.

the class EffectiveModuleTest method effectiveBuildTest.

@Test
public void effectiveBuildTest() throws Exception {
    final Module rootModule = TestUtils.parseYangSource("/semantic-statement-parser/effective-module/root.yang", "/semantic-statement-parser/effective-module/imported.yang", "/semantic-statement-parser/effective-module/submod.yang").findModules("root").iterator().next();
    assertNotNull(rootModule);
    assertEquals("root-pref", rootModule.getPrefix());
    assertEquals(YangVersion.VERSION_1, rootModule.getYangVersion());
    assertEquals(Optional.of("cisco"), rootModule.getOrganization());
    assertEquals(Optional.of("cisco email"), rootModule.getContact());
    final ContainerSchemaNode contSchemaNode = (ContainerSchemaNode) rootModule.getDataChildByName(CONT);
    assertNotNull(contSchemaNode);
    final Collection<? extends AugmentationSchemaNode> augmentations = rootModule.getAugmentations();
    assertEquals(1, augmentations.size());
    assertEquals(Absolute.of(CONT), augmentations.iterator().next().getTargetPath());
    final Collection<? extends ModuleImport> imports = rootModule.getImports();
    assertEquals(1, imports.size());
    final ModuleImport importStmt = imports.iterator().next();
    assertNotNull(importStmt);
    assertEquals("imported", importStmt.getModuleName());
    assertEquals(Optional.of(REVISION), importStmt.getRevision());
    assertEquals("imp-pref", importStmt.getPrefix());
    final Collection<? extends Submodule> submodules = rootModule.getSubmodules();
    assertEquals(1, submodules.size());
    assertEquals("submod", submodules.iterator().next().getName());
    final Collection<? extends NotificationDefinition> notifications = rootModule.getNotifications();
    assertEquals(1, notifications.size());
    assertEquals("notif1", notifications.iterator().next().getQName().getLocalName());
    final Collection<? extends RpcDefinition> rpcs = rootModule.getRpcs();
    assertEquals(1, rpcs.size());
    assertEquals("rpc1", rpcs.iterator().next().getQName().getLocalName());
    final Collection<? extends Deviation> deviations = rootModule.getDeviations();
    assertEquals(1, deviations.size());
    final Deviation deviationStmt = deviations.iterator().next();
    assertNotNull(deviationStmt);
    final QNameModule importedModuleQName = QNameModule.create(XMLNamespace.of("imported"), REVISION);
    final QName importedContQName = QName.create(importedModuleQName, "cont");
    assertEquals(Absolute.of(importedContQName), deviationStmt.getTargetPath());
    assertEquals(DeviateKind.ADD, deviationStmt.getDeviates().iterator().next().getDeviateType());
    assertEquals(Optional.of("deviate reference"), deviationStmt.getReference());
    final Collection<? extends IdentitySchemaNode> identities = rootModule.getIdentities();
    assertEquals(1, identities.size());
    assertEquals("identity1", identities.iterator().next().getQName().getLocalName());
    final Collection<? extends FeatureDefinition> features = rootModule.getFeatures();
    assertEquals(1, features.size());
    final FeatureDefinition featureStmt = features.iterator().next();
    assertNotNull(featureStmt);
    assertEquals(FEATURE1, featureStmt.getQName());
    assertEquals(Optional.of("feature1 description"), featureStmt.getDescription());
    assertEquals(Optional.of("feature1 reference"), featureStmt.getReference());
    assertEquals(Status.CURRENT, featureStmt.getStatus());
    final Collection<? extends ExtensionDefinition> extensionSchemaNodes = rootModule.getExtensionSchemaNodes();
    assertEquals(1, extensionSchemaNodes.size());
    assertEquals("ext1", extensionSchemaNodes.iterator().next().getQName().getLocalName());
}
Also used : QName(org.opendaylight.yangtools.yang.common.QName) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) ModuleImport(org.opendaylight.yangtools.yang.model.api.ModuleImport) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Deviation(org.opendaylight.yangtools.yang.model.api.Deviation) FeatureDefinition(org.opendaylight.yangtools.yang.model.api.FeatureDefinition) Test(org.junit.Test)

Example 4 with FeatureDefinition

use of org.opendaylight.yangtools.yang.model.api.FeatureDefinition in project yangtools by opendaylight.

the class IncludedStmtsTest method includedFeaturesTest.

@Test
public void includedFeaturesTest() {
    final Module testModule = result.findModules("root-module").iterator().next();
    assertNotNull(testModule);
    final Collection<? extends FeatureDefinition> features = testModule.getFeatures();
    assertEquals(2, features.size());
    final Iterator<? extends FeatureDefinition> featuresIterator = features.iterator();
    FeatureDefinition feature = featuresIterator.next();
    assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
    feature = featuresIterator.next();
    assertThat(feature.getQName().getLocalName(), anyOf(is("new-feature1"), is("new-feature2")));
}
Also used : Module(org.opendaylight.yangtools.yang.model.api.Module) FeatureDefinition(org.opendaylight.yangtools.yang.model.api.FeatureDefinition) Test(org.junit.Test)

Example 5 with FeatureDefinition

use of org.opendaylight.yangtools.yang.model.api.FeatureDefinition in project netconf by opendaylight.

the class SchemaContextHandler method addFeatureLeafList.

/**
 * Mapping features of specific module.
 *
 * @param mapEntryBuilder mapEntryBuilder of parent for mapping children
 * @param features features of specific module
 */
private static void addFeatureLeafList(final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder, final Collection<? extends FeatureDefinition> features) {
    final ListNodeBuilder<String, SystemLeafSetNode<String>> leafSetBuilder = Builders.<String>leafSetBuilder().withNodeIdentifier(MODULE_FEATURE_NODEID);
    for (final FeatureDefinition feature : features) {
        leafSetBuilder.withChildValue(feature.getQName().getLocalName());
    }
    mapEntryBuilder.withChild(leafSetBuilder.build());
}
Also used : SystemLeafSetNode(org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode) FeatureDefinition(org.opendaylight.yangtools.yang.model.api.FeatureDefinition)

Aggregations

FeatureDefinition (org.opendaylight.yangtools.yang.model.api.FeatureDefinition)5 Test (org.junit.Test)3 Module (org.opendaylight.yangtools.yang.model.api.Module)3 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)2 SystemLeafSetNode (org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode)2 QName (org.opendaylight.yangtools.yang.common.QName)1 Revision (org.opendaylight.yangtools.yang.common.Revision)1 NodeIdentifierWithPredicates (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates)1 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)1 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)1 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)1 Deviation (org.opendaylight.yangtools.yang.model.api.Deviation)1 LeafListSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode)1 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)1 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)1 ModuleImport (org.opendaylight.yangtools.yang.model.api.ModuleImport)1