Java Code Examples for org.opendaylight.yangtools.yang.model.api.Module#getSubmodules()

The following examples show how to use org.opendaylight.yangtools.yang.model.api.Module#getSubmodules() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug9005Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@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 Module> submodules = foo.getSubmodules();
    assertEquals(1, submodules.size());
    final Module 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());
}
 
Example 2
Source File: FilteringSchemaContextProxy.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private boolean checkModuleDependency(final Module module, final Collection<ModuleId> rootModules) {
    for (ModuleId rootModule : rootModules) {
        if (rootModule.equals(new ModuleId(module.getName(), module.getRevision()))) {
            return true;
        }

        //handling/checking imports regarding root modules
        for (ModuleImport moduleImport : module.getImports()) {
            if (moduleImport.getModuleName().equals(rootModule.getName())) {
                return moduleImport.getRevision().isEmpty()
                        || moduleImport.getRevision().equals(rootModule.getRev());
            }
        }

        //submodules handling
        for (Module moduleSub : module.getSubmodules()) {
            return checkModuleDependency(moduleSub, rootModules);
        }
    }

    return false;
}
 
Example 3
Source File: AbstractYinExportTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
final void exportYinModules(final String yangDir, final String yinDir) throws IOException, SAXException,
        XMLStreamException {
    final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory(yangDir);
    final Collection<? extends Module> modules = schemaContext.getModules();
    assertNotEquals(0, modules.size());

    for (Module module : modules) {
        readAndValidateModule(schemaContext, module, yinDir);

        for (Module submodule : module.getSubmodules()) {
            readAndValidateSubmodule(schemaContext, module, submodule, yinDir);
        }
    }
}
 
Example 4
Source File: StmtTestUtils.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
public static void printReferences(final Module module, final boolean isSubmodule, final String indent) {
    LOG.debug("{}{} {}", indent, isSubmodule ? "Submodule" : "Module", module.getName());
    for (final Module submodule : module.getSubmodules()) {
        printReferences(submodule, true, indent + "      ");
        printChilds(submodule.getChildNodes(), indent + "            ");
    }
}
 
Example 5
Source File: Bug3799Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void test() throws Exception {
    SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug3799");
    assertNotNull(schema);

    Collection<? extends Module> modules = schema.getModules();
    assertNotNull(modules);
    assertEquals(1, modules.size());

    Module testModule = modules.iterator().next();
    Collection<? extends Module> subModules = testModule.getSubmodules();
    assertNotNull(subModules);
    assertEquals(1, subModules.size());

    Module testSubmodule = subModules.iterator().next();

    Collection<? extends NotificationDefinition> notifications = testSubmodule.getNotifications();
    assertNotNull(notifications);
    assertEquals(1, notifications.size());

    NotificationDefinition bazNotification = notifications.iterator().next();
    Collection<? extends DataSchemaNode> childNodes = bazNotification.getChildNodes();
    assertNotNull(childNodes);
    assertEquals(1, childNodes.size());

    DataSchemaNode child = childNodes.iterator().next();
    assertTrue(child instanceof LeafSchemaNode);

    LeafSchemaNode leafBar = (LeafSchemaNode) child;
    String bar = leafBar.getQName().getLocalName();
    assertEquals("bar", bar);
}
 
Example 6
Source File: ProcessorModuleReactor.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
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 (Module 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());
}
 
Example 7
Source File: ModuleDependencySort.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static Collection<? extends ModuleImport> allImports(final Module mod) {
    if (mod.getSubmodules().isEmpty()) {
        return mod.getImports();
    }

    final Collection<ModuleImport> concat = new LinkedHashSet<>();
    concat.addAll(mod.getImports());
    for (Module sub : mod.getSubmodules()) {
        concat.addAll(sub.getImports());
    }
    return concat;
}
 
Example 8
Source File: SchemaContextUtil.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Extract the identifiers of all modules and submodules which were used to create a particular SchemaContext.
 *
 * @param context SchemaContext to be examined
 * @return Set of ModuleIdentifiers.
 */
public static Set<SourceIdentifier> getConstituentModuleIdentifiers(final SchemaContext context) {
    final Set<SourceIdentifier> ret = new HashSet<>();

    for (Module module : context.getModules()) {
        ret.add(moduleToIdentifier(module));

        for (Module submodule : module.getSubmodules()) {
            ret.add(moduleToIdentifier(submodule));
        }
    }

    return ret;
}
 
Example 9
Source File: DeclaredStatementsTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@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();

    final String moduleStatementName = moduleStatement.getName();
    assertNotNull(moduleStatementName);

    final YangVersionStatement moduleStatementYangVersion = moduleStatement.getYangVersion();
    assertNotNull(moduleStatementYangVersion);
    assertNotNull(moduleStatementYangVersion.getValue());

    final NamespaceStatement moduleStatementNamspace = moduleStatement.getNamespace();
    assertNotNull(moduleStatementNamspace);
    assertNotNull(moduleStatementNamspace.getUri());

    final PrefixStatement moduleStatementPrefix = moduleStatement.getPrefix();
    assertNotNull(moduleStatementPrefix);
    assertNotNull(moduleStatementPrefix.getValue());

    assertEquals(1, moduleStatement.getIncludes().size());
    final IncludeStatement includeStatement = moduleStatement.getIncludes().iterator().next();
    assertEquals("child-module-declared-test", includeStatement.getModule());

    final Collection<? extends Module> submodules = testModule.getSubmodules();
    assertNotNull(submodules);
    assertEquals(1, submodules.size());

    final Module submodule = submodules.iterator().next();
    final SubmoduleStatement submoduleStatement = ((SubmoduleEffectiveStatement) submodule).getDeclared();

    final String submoduleStatementName = submoduleStatement.getName();
    assertNotNull(submoduleStatementName);

    final YangVersionStatement submoduleStatementYangVersion = submoduleStatement.getYangVersion();
    assertNotNull(submoduleStatementYangVersion);

    final BelongsToStatement belongsToStatement = submoduleStatement.getBelongsTo();
    assertNotNull(belongsToStatement);
    assertNotNull(belongsToStatement.getModule());
    assertNotNull(belongsToStatement.getPrefix());
}
 
Example 10
Source File: EffectiveModuleTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void effectiveBuildTest() throws SourceException, ReactorException {
    SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(ROOT_MODULE, IMPORTED_MODULE, SUBMODULE)
            .buildEffective();

    assertNotNull(result);

    Module rootModule = result.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 Module> 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(URI.create("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(FEATURE1_SCHEMA_PATH, featureStmt.getPath());
    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());
}