Search in sources :

Example 11 with Submodule

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

the class AbstractYinExportTest method exportYinModules.

final void exportYinModules(final String yangDir, final String yinDir) throws IOException, SAXException, XMLStreamException {
    final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResourceDirectory(yangDir);
    final Collection<? extends Module> modules = schemaContext.getModules();
    assertNotEquals(0, modules.size());
    for (Module module : modules) {
        readAndValidateModule(schemaContext, module, yinDir);
        for (Submodule submodule : module.getSubmodules()) {
            readAndValidateSubmodule(schemaContext, module, submodule, yinDir);
        }
    }
}
Also used : Submodule(org.opendaylight.yangtools.yang.model.api.Submodule) Module(org.opendaylight.yangtools.yang.model.api.Module) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)

Example 12 with Submodule

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

the class Bug9005Test method test.

@Test
public void test() throws Exception {
    final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug9005");
    assertNotNull(context);
    final Module foo = context.findModule("foo", Revision.of("2017-07-07")).get();
    final Collection<? extends ModuleImport> imports = foo.getImports();
    assertEquals(1, imports.size());
    final ModuleImport imp1 = imports.iterator().next();
    assertEquals("bar-2", imp1.getModuleName());
    assertEquals("bar", imp1.getPrefix());
    assertEquals(Revision.ofNullable("2000-01-02"), imp1.getRevision());
    final Collection<? extends Submodule> submodules = foo.getSubmodules();
    assertEquals(1, submodules.size());
    final Submodule submodule = submodules.iterator().next();
    final Collection<? extends ModuleImport> subImports = submodule.getImports();
    assertEquals(1, subImports.size());
    final ModuleImport subImp1 = subImports.iterator().next();
    assertEquals("bar-1", subImp1.getModuleName());
    assertEquals("bar", subImp1.getPrefix());
    assertEquals(Revision.ofNullable("2000-01-01"), subImp1.getRevision());
}
Also used : ModuleImport(org.opendaylight.yangtools.yang.model.api.ModuleImport) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Submodule(org.opendaylight.yangtools.yang.model.api.Submodule) Module(org.opendaylight.yangtools.yang.model.api.Module) Test(org.junit.Test)

Example 13 with Submodule

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

the class ProcessorModuleReactor method toContext.

ContextHolder toContext() throws IOException, YangParserException {
    checkState(parser != null, "Context has already been assembled");
    for (YangTextSchemaSource source : toUniqueSources(dependencies)) {
        // This source is coming from a dependency:
        // - its identifier should be accurate, as it should have been processed into a file with accurate name
        // - it is not required to be parsed, hence we add it just as a library source
        parser.addLibSource(source);
    }
    final EffectiveModelContext schemaContext = verifyNotNull(parser.buildEffectiveModel());
    parser = null;
    final Set<Module> modules = new HashSet<>();
    for (Module module : schemaContext.getModules()) {
        final SourceIdentifier modId = Util.moduleToIdentifier(module);
        LOG.debug("Looking for source {}", modId);
        if (modelsInProject.containsKey(modId)) {
            LOG.debug("Module {} belongs to current project", module);
            modules.add(module);
            for (Submodule sub : module.getSubmodules()) {
                final SourceIdentifier subId = Util.moduleToIdentifier(sub);
                if (!modelsInProject.containsKey(subId)) {
                    LOG.warn("Submodule {} not found in input files", sub);
                }
            }
        }
    }
    return new ContextHolder(schemaContext, modules, modelsInProject.keySet());
}
Also used : YangTextSchemaSource(org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) Submodule(org.opendaylight.yangtools.yang.model.api.Submodule) Module(org.opendaylight.yangtools.yang.model.api.Module) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) HashSet(java.util.HashSet)

Example 14 with Submodule

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

the class ModuleStatementSupport method createEffective.

@Override
protected ModuleEffectiveStatement createEffective(final Current<Unqualified, ModuleStatement> stmt, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
    if (substatements.isEmpty()) {
        throw noNamespace(stmt);
    }
    final List<Submodule> submodules = new ArrayList<>();
    for (StmtContext<?, ?, ?> submoduleCtx : submoduleContexts(stmt)) {
        final EffectiveStatement<?, ?> submodule = submoduleCtx.buildEffective();
        verify(submodule instanceof Submodule, "Submodule statement %s is not a Submodule", submodule);
        submodules.add((Submodule) submodule);
    }
    final QNameModule qnameModule = verifyNotNull(stmt.namespaceItem(QNameModuleNamespace.class, Empty.value()));
    try {
        return new ModuleEffectiveStatementImpl(stmt, substatements, submodules, qnameModule);
    } catch (SubstatementIndexingException e) {
        throw new SourceException(e.getMessage(), stmt, e);
    }
}
Also used : SubstatementIndexingException(org.opendaylight.yangtools.yang.model.spi.meta.SubstatementIndexingException) ArrayList(java.util.ArrayList) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Submodule(org.opendaylight.yangtools.yang.model.api.Submodule) SourceException(org.opendaylight.yangtools.yang.parser.spi.source.SourceException)

Aggregations

Submodule (org.opendaylight.yangtools.yang.model.api.Submodule)14 Module (org.opendaylight.yangtools.yang.model.api.Module)9 Test (org.junit.Test)7 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)5 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)3 HashSet (java.util.HashSet)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 ModuleImport (org.opendaylight.yangtools.yang.model.api.ModuleImport)2 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)2 YangTextSchemaSource (org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 BasicCapability (org.opendaylight.netconf.api.capability.BasicCapability)1 Capability (org.opendaylight.netconf.api.capability.Capability)1 YangModuleCapability (org.opendaylight.netconf.api.capability.YangModuleCapability)1 SchemaSourceCache (org.opendaylight.netconf.test.tool.schemacache.SchemaSourceCache)1 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)1 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)1 NotificationDefinition (org.opendaylight.yangtools.yang.model.api.NotificationDefinition)1