use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement in project yangtools by opendaylight.
the class Bug7038Test method unknownNodeTest.
@Test
public void unknownNodeTest() throws Exception {
final ModuleStatement bar = StmtTestUtils.parseYangSources("/bugs/bug7038").getModuleStatement(QNameModule.create(XMLNamespace.of("bar"))).getDeclared();
final UnrecognizedStatement decimal64 = bar.findFirstDeclaredSubstatement(UnrecognizedStatement.class).orElseThrow();
assertEquals("decimal64", decimal64.argument());
assertEquals(QName.create("foo", "decimal64"), decimal64.statementDefinition().getStatementName());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement 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.ModuleStatement in project yangtools by opendaylight.
the class YinXMLEventReaderFactory method createXMLEventReader.
/**
* Create a new XMLEventReader iterating of the YIN document equivalent of an effective module.
*
* @param module Effective module
* @return A new XMLEventReader.
* @throws NullPointerException if module is null
* @throws IllegalArgumentException if the specified module does not expose declared model
*/
public XMLEventReader createXMLEventReader(final ModuleEffectiveStatement module) {
final ModuleStatement declared = module.getDeclared();
checkArgument(declared != null, "Module %s does not expose declared model", module);
return new YinXMLEventReader(eventFactory, new ModuleNamespaceContext(module), declared);
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement in project yangtools by opendaylight.
the class DeclaredStatementsTest method testDeclaredModule.
@Test
public void testDeclaredModule() throws ReactorException, ParseException {
final StatementStreamSource rootModule = sourceForResource("/declared-statements-test/root-module-declared-test.yang");
final StatementStreamSource importedModule = sourceForResource("/declared-statements-test/imported-module-declared-test.yang");
final SchemaContext schemaContext = StmtTestUtils.parseYangSources(rootModule, importedModule);
assertNotNull(schemaContext);
final Revision revision = Revision.of("2016-09-28");
final Module testModule = schemaContext.findModule("root-module-declared-test", revision).get();
assertNotNull(testModule);
final ModuleStatement moduleStatement = ((ModuleEffectiveStatement) testModule).getDeclared();
assertEquals(1, moduleStatement.getImports().size());
final ImportStatement importStatement = moduleStatement.getImports().iterator().next();
assertEquals("imported-module-declared-test", importStatement.argument());
assertEquals("imdt", importStatement.getPrefix().argument());
assertEquals(revision, importStatement.getRevisionDate().argument());
assertEquals("test description", moduleStatement.getDescription().get().argument());
assertEquals("test reference", moduleStatement.getReference().get().argument());
assertEquals("test organization", moduleStatement.getOrganization().get().argument());
assertEquals("test contact", moduleStatement.getContact().get().argument());
assertEquals(1, moduleStatement.getRevisions().size());
final RevisionStatement revisionStatement = moduleStatement.getRevisions().iterator().next();
assertEquals(revision, revisionStatement.argument());
assertEquals("test description", revisionStatement.getDescription().get().argument());
assertEquals("test reference", revisionStatement.getReference().get().argument());
assertEquals(1, moduleStatement.getExtensions().size());
final ExtensionStatement extensionStatement = moduleStatement.getExtensions().iterator().next();
assertEquals(Status.CURRENT, extensionStatement.getStatus().get().argument());
assertEquals("test description", extensionStatement.getDescription().get().argument());
assertEquals("test reference", extensionStatement.getReference().get().argument());
final ArgumentStatement argumentStatement = extensionStatement.getArgument();
assertEquals("ext-argument", argumentStatement.argument().getLocalName());
assertTrue(argumentStatement.getYinElement().argument());
assertEquals(2, moduleStatement.getFeatures().size());
final FeatureStatement featureStatement = moduleStatement.getFeatures().iterator().next();
assertEquals(Status.CURRENT, featureStatement.getStatus().get().argument());
assertEquals("test description", featureStatement.getDescription().get().argument());
assertEquals("test reference", featureStatement.getReference().get().argument());
assertEquals("test-feature", featureStatement.argument().getLocalName());
assertEquals(1, featureStatement.getIfFeatures().size());
assertEquals(2, moduleStatement.getIdentities().size());
IdentityStatement identityStatement = null;
for (final IdentityStatement identity : moduleStatement.getIdentities()) {
if (identity.argument().getLocalName().equals("test-id")) {
identityStatement = identity;
}
}
assertEquals("test-base-id", identityStatement.getBases().iterator().next().argument().getLocalName());
assertEquals(Status.CURRENT, identityStatement.getStatus().get().argument());
assertEquals("test description", identityStatement.getDescription().get().argument());
assertEquals("test reference", identityStatement.getReference().get().argument());
assertEquals("test-id", identityStatement.argument().getLocalName());
assertEquals(1, moduleStatement.getTypedefs().size());
final TypedefStatement typedefStatement = moduleStatement.getTypedefs().iterator().next();
assertEquals(Status.CURRENT, typedefStatement.getStatus().get().argument());
assertEquals("test description", typedefStatement.getDescription().get().argument());
assertEquals("test reference", typedefStatement.getReference().get().argument());
assertEquals("test-typedef", typedefStatement.argument().getLocalName());
assertEquals("int32", typedefStatement.getType().rawArgument());
assertEquals("meter", typedefStatement.getUnits().get().argument());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement in project yangtools by opendaylight.
the class ModuleStatementSupport method onLinkageDeclared.
@Override
public void onLinkageDeclared(final Mutable<Unqualified, ModuleStatement, ModuleEffectiveStatement> stmt) {
final XMLNamespace moduleNs = SourceException.throwIfNull(firstAttributeOf(stmt.declaredSubstatements(), NamespaceStatement.class), stmt, "Namespace of the module [%s] is missing", stmt.argument());
final Optional<Revision> revisionDate = StmtContextUtils.getLatestRevision(stmt.declaredSubstatements());
final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate.orElse(null)).intern();
final StmtContext<?, ModuleStatement, ModuleEffectiveStatement> possibleDuplicateModule = stmt.getFromNamespace(NamespaceToModule.class, qNameModule);
if (possibleDuplicateModule != null && possibleDuplicateModule != stmt) {
throw new SourceException(stmt, "Module namespace collision: %s. At %s", qNameModule.getNamespace(), possibleDuplicateModule.sourceReference());
}
final String moduleName = stmt.getRawArgument();
final SourceIdentifier moduleIdentifier = RevisionSourceIdentifier.create(moduleName, revisionDate);
stmt.addContext(ModuleNamespace.class, moduleIdentifier, stmt);
stmt.addContext(ModuleNamespaceForBelongsTo.class, moduleIdentifier.getName(), stmt);
stmt.addContext(NamespaceToModule.class, qNameModule, stmt);
final String modulePrefix = SourceException.throwIfNull(firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class), stmt, "Prefix of the module [%s] is missing", stmt.argument());
stmt.addToNs(QNameModuleNamespace.class, Empty.value(), qNameModule);
stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule);
stmt.addToNs(ModuleNameToModuleQName.class, moduleName, qNameModule);
stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
stmt.addToNs(ModuleCtxToSourceIdentifier.class, stmt, moduleIdentifier);
stmt.addToNs(ModuleQNameToModuleName.class, qNameModule, moduleName);
stmt.addToNs(ImportPrefixToModuleCtx.class, modulePrefix, stmt);
if (semanticVersioning) {
addToSemVerModuleNamespace(stmt, moduleIdentifier);
}
}
Aggregations