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

The following examples show how to use org.opendaylight.yangtools.yang.model.api.Module#getName() . 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: WrappedYangNode.java    From anx with Apache License 2.0 5 votes vote down vote up
WrappedYangNode(Module module) {
    this.module = module;
    this.namespace = module.getNamespace().toString();
    this.name = module.getName();
    this.description = module.getDescription().orElse("");
    prefixes.put(namespace, module.getPrefix());
}
 
Example 3
Source File: LeafRefUtils.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static Deque<QNameWithPredicate> schemaPathToXPathQNames(final SchemaPath nodePath, final Module module) {
    final Deque<QNameWithPredicate> xpath = new LinkedList<>();
    final Iterator<QName> nodePathIterator = nodePath.getPathFromRoot().iterator();

    DataNodeContainer currenDataNodeContainer = module;
    while (nodePathIterator.hasNext()) {
        final QName qname = nodePathIterator.next();
        final DataSchemaNode child = currenDataNodeContainer.getDataChildByName(qname);

        if (child instanceof DataNodeContainer) {
            if (!(child instanceof CaseSchemaNode)) {
                xpath.add(new SimpleQNameWithPredicate(qname));
            }
            currenDataNodeContainer = (DataNodeContainer) child;
        } else if (child instanceof ChoiceSchemaNode) {
            if (nodePathIterator.hasNext()) {
                currenDataNodeContainer = ((ChoiceSchemaNode) child).findCase(nodePathIterator.next()).orElse(null);
            } else {
                break;
            }
        } else if (child instanceof LeafSchemaNode || child instanceof LeafListSchemaNode) {
            xpath.add(new SimpleQNameWithPredicate(qname));
            break;
        } else if (child == null) {
            throw new IllegalArgumentException("No child " + qname + " found in node container "
                    + currenDataNodeContainer + " in module " + module.getName());
        } else {
            throw new IllegalStateException("Illegal schema node type in the path: " + child.getClass());
        }
    }

    return xpath;
}
 
Example 4
Source File: AbstractDataObjectBuilder.java    From yang2swagger with Eclipse Public License 1.0 4 votes vote down vote up
private String moduleName(DataSchemaNode node) {
    Module module = ctx.findModuleByNamespaceAndRevision(node.getQName().getNamespace(), node.getQName().getRevision());
    return module.getName();
}
 
Example 5
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 6
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);
        }
    }
}