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

The following examples show how to use org.opendaylight.yangtools.yang.model.api.Module#getRevision() . 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: ModuleDependencySort.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Extract dependencies from modules to fill dependency graph.
 */
private static void processModules(final Table<String, Optional<Revision>, ModuleNodeImpl> moduleGraph,
        final Iterable<? extends Module> modules) {

    // Process nodes
    for (final Module momb : modules) {

        final String name = momb.getName();
        final Optional<Revision> rev = momb.getRevision();
        final Map<Optional<Revision>, ModuleNodeImpl> revs = moduleGraph.row(name);
        if (revs.containsKey(rev)) {
            throw new IllegalArgumentException(String.format("Module:%s with revision:%s declared twice", name,
                formatRevDate(rev)));
        }

        revs.put(rev, new ModuleNodeImpl(name, rev.orElse(null), momb));
    }
}
 
Example 2
Source File: YinExportTestUtils.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
public static Document loadDocument(final String prefix, final Module module) throws IOException, SAXException {
    final Optional<Revision> rev = module.getRevision();
    final String fileName = !rev.isPresent() ? module.getName() : module.getName() + '@' + rev.get().toString();
    return loadDocument(prefix + '/' + fileName + YangConstants.RFC6020_YIN_FILE_EXTENSION);
}
 
Example 3
Source File: ModuleDependencySort.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Extract module:revision from modules.
 */
private static void processDependencies(final Table<String, Optional<Revision>, ModuleNodeImpl> moduleGraph,
        final Collection<? extends Module> mmbs) {
    final Map<URI, Module> allNS = new HashMap<>();

    // Create edges in graph
    for (final Module module : mmbs) {
        final Map<String, Optional<Revision>> imported = new HashMap<>();
        final String fromName = module.getName();
        final URI ns = module.getNamespace();
        final Optional<Revision> fromRevision = module.getRevision();

        // check for existence of module with same namespace
        final Module prev = allNS.putIfAbsent(ns, module);
        if (prev != null) {
            final String name = prev.getName();
            if (!fromName.equals(name)) {
                LOG.warn("Error while sorting module [{}, {}]: module with same namespace ({}) already loaded:"
                    + " [{}, {}]", fromName, fromRevision, ns, name, prev.getRevision());
            }
        }

        // no need to check if other Type of object, check is performed in process modules
        for (final ModuleImport imprt : allImports(module)) {
            final String toName = imprt.getModuleName();
            final Optional<Revision> toRevision = imprt.getRevision();

            final ModuleNodeImpl from = moduleGraph.get(fromName, fromRevision);
            final ModuleNodeImpl to = getModuleByNameAndRevision(moduleGraph, fromName, fromRevision, toName,
                toRevision);

            /*
             * If it is an yang 1 module, check imports: If module is imported twice with different
             * revisions then throw exception
             */
            if (module.getYangVersion() == YangVersion.VERSION_1) {
                final Optional<Revision> impRevision = imported.get(toName);
                if (impRevision != null && impRevision.isPresent() && !impRevision.equals(toRevision)
                        && toRevision.isPresent()) {
                    throw new IllegalArgumentException(String.format(
                        "Module:%s imported twice with different revisions:%s, %s", toName,
                        formatRevDate(impRevision), formatRevDate(toRevision)));
                }
            }

            imported.put(toName, toRevision);

            from.addEdge(to);
        }
    }
}