Search in sources :

Example 1 with SubmoduleStatement

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

the class YinXMLEventReaderFactory method createXMLEventReader.

/**
 * Create a new XMLEventReader iterating of the YIN document equivalent of an effective submodule.
 *
 * @param module Effective module
 * @param submodule Effective submodule
 * @return A new XMLEventReader.
 * @throws NullPointerException if any argument is null
 * @throws IllegalArgumentException if the specified submodule does not expose declared model
 */
public XMLEventReader createXMLEventReader(final ModuleEffectiveStatement module, final SubmoduleEffectiveStatement submodule) {
    final SubmoduleStatement declared = submodule.getDeclared();
    checkArgument(declared != null, "Submodule %s does not expose declared model", submodule);
    return new YinXMLEventReader(eventFactory, new ModuleNamespaceContext(module), declared);
}
Also used : SubmoduleStatement(org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement)

Example 2 with SubmoduleStatement

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

the class DeclaredStatementsTest method testDeclaredModuleAndSubmodule.

@Test
public void testDeclaredModuleAndSubmodule() throws ReactorException {
    final StatementStreamSource parentModule = sourceForResource("/declared-statements-test/parent-module-declared-test.yang");
    final StatementStreamSource childModule = sourceForResource("/declared-statements-test/child-module-declared-test.yang");
    final SchemaContext schemaContext = StmtTestUtils.parseYangSources(parentModule, childModule);
    assertNotNull(schemaContext);
    final Module testModule = schemaContext.findModules("parent-module-declared-test").iterator().next();
    assertNotNull(testModule);
    final ModuleStatement moduleStatement = ((ModuleEffectiveStatement) testModule).getDeclared();
    assertNotNull(moduleStatement.argument());
    final YangVersionStatement moduleStatementYangVersion = moduleStatement.getYangVersion();
    assertNotNull(moduleStatementYangVersion);
    assertNotNull(moduleStatementYangVersion.argument());
    final NamespaceStatement moduleStatementNamspace = moduleStatement.getNamespace();
    assertNotNull(moduleStatementNamspace);
    assertNotNull(moduleStatementNamspace.argument());
    final PrefixStatement moduleStatementPrefix = moduleStatement.getPrefix();
    assertNotNull(moduleStatementPrefix);
    assertNotNull(moduleStatementPrefix.argument());
    assertEquals(1, moduleStatement.getIncludes().size());
    final IncludeStatement includeStatement = moduleStatement.getIncludes().iterator().next();
    assertEquals("child-module-declared-test", includeStatement.argument());
    final Collection<? extends Submodule> submodules = testModule.getSubmodules();
    assertNotNull(submodules);
    assertEquals(1, submodules.size());
    final Submodule submodule = submodules.iterator().next();
    final SubmoduleStatement submoduleStatement = ((SubmoduleEffectiveStatement) submodule).getDeclared();
    assertNotNull(submoduleStatement.argument());
    final YangVersionStatement submoduleStatementYangVersion = submoduleStatement.getYangVersion();
    assertNotNull(submoduleStatementYangVersion);
    final BelongsToStatement belongsToStatement = submoduleStatement.getBelongsTo();
    assertNotNull(belongsToStatement);
    assertNotNull(belongsToStatement.argument());
    assertNotNull(belongsToStatement.getPrefix());
}
Also used : NamespaceStatement(org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement) StatementStreamSource(org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource) ModuleStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement) Submodule(org.opendaylight.yangtools.yang.model.api.Submodule) BelongsToStatement(org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) PrefixStatement(org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement) YangVersionStatement(org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement) SubmoduleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement) IncludeStatement(org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement) SubmoduleStatement(org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) Module(org.opendaylight.yangtools.yang.model.api.Module) Test(org.junit.Test)

Example 3 with SubmoduleStatement

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

the class SubmoduleStatementSupport method onLinkageDeclared.

@Override
public void onLinkageDeclared(final Mutable<Unqualified, SubmoduleStatement, SubmoduleEffectiveStatement> stmt) {
    final SourceIdentifier submoduleIdentifier = RevisionSourceIdentifier.create(stmt.getRawArgument(), StmtContextUtils.getLatestRevision(stmt.declaredSubstatements()));
    final StmtContext<?, SubmoduleStatement, SubmoduleEffectiveStatement> possibleDuplicateSubmodule = stmt.getFromNamespace(SubmoduleNamespace.class, submoduleIdentifier);
    if (possibleDuplicateSubmodule != null && possibleDuplicateSubmodule != stmt) {
        throw new SourceException(stmt, "Submodule name collision: %s. At %s", stmt.rawArgument(), possibleDuplicateSubmodule.sourceReference());
    }
    stmt.addContext(SubmoduleNamespace.class, submoduleIdentifier, stmt);
    final String belongsToModuleName = firstAttributeOf(stmt.declaredSubstatements(), BelongsToStatement.class);
    final StmtContext<?, ?, ?> prefixSubStmtCtx = SourceException.throwIfNull(findFirstDeclaredSubstatement(stmt, 0, BelongsToStatement.class, PrefixStatement.class), stmt, "Prefix of belongsTo statement is missing in submodule [%s]", stmt.rawArgument());
    final String prefix = prefixSubStmtCtx.rawArgument();
    stmt.addToNs(BelongsToPrefixToModuleName.class, prefix, belongsToModuleName);
}
Also used : SubmoduleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement) SourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier) RevisionSourceIdentifier(org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier) SubmoduleStatement(org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement) BelongsToStatement(org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement) SourceException(org.opendaylight.yangtools.yang.parser.spi.source.SourceException) PrefixStatement(org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement)

Aggregations

SubmoduleStatement (org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement)3 BelongsToStatement (org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement)2 PrefixStatement (org.opendaylight.yangtools.yang.model.api.stmt.PrefixStatement)2 SubmoduleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleEffectiveStatement)2 Test (org.junit.Test)1 Module (org.opendaylight.yangtools.yang.model.api.Module)1 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)1 Submodule (org.opendaylight.yangtools.yang.model.api.Submodule)1 IncludeStatement (org.opendaylight.yangtools.yang.model.api.stmt.IncludeStatement)1 ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)1 ModuleStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement)1 NamespaceStatement (org.opendaylight.yangtools.yang.model.api.stmt.NamespaceStatement)1 YangVersionStatement (org.opendaylight.yangtools.yang.model.api.stmt.YangVersionStatement)1 RevisionSourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier)1 SourceIdentifier (org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier)1 SourceException (org.opendaylight.yangtools.yang.parser.spi.source.SourceException)1 StatementStreamSource (org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource)1