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);
}
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());
}
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);
}
Aggregations