2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.util;
10 import java.util.HashSet;
12 import org.opendaylight.yangtools.yang.model.api.Module;
13 import org.opendaylight.yangtools.yang.model.api.ModuleLike;
14 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
15 import org.opendaylight.yangtools.yang.model.api.Submodule;
16 import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
17 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
20 * The Schema Context Util contains support methods for searching through Schema Context modules for specified schema
21 * nodes via Schema Path or Revision Aware XPath. The Schema Context Util is designed as mixin, so it is not
24 public final class SchemaContextUtil {
25 private SchemaContextUtil() {
30 * Extract the identifiers of all modules and submodules which were used to create a particular SchemaContext.
32 * @param context SchemaContext to be examined
33 * @return Set of ModuleIdentifiers.
35 // FIXME: rehost to yang-repo-spi (or -api?)
36 public static Set<SourceIdentifier> getConstituentModuleIdentifiers(final SchemaContext context) {
37 final Set<SourceIdentifier> ret = new HashSet<>();
39 for (Module module : context.getModules()) {
40 ret.add(moduleToIdentifier(module));
42 for (Submodule submodule : module.getSubmodules()) {
43 ret.add(moduleToIdentifier(submodule));
50 private static SourceIdentifier moduleToIdentifier(final ModuleLike module) {
51 return RevisionSourceIdentifier.create(module.getName(), module.getRevision());