2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Ericsson
4 * Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 package org.oran.smo.yangtools.parser.model.schema;
23 import java.util.HashMap;
25 import java.util.Objects;
28 * Holds mappings between module names and namespaces.
30 * @author Mark Hollmann
32 public class ModuleAndNamespaceResolver {
34 private final Map<String, String> moduleNameToNamespace = new HashMap<>();
35 private final Map<String, String> namespaceToModuleName = new HashMap<>();
38 * Records a mapping between a module or submodule name, and its namespace (in the case of
39 * submodule, the namespace of the owning module).
41 public void recordModuleMapping(final String moduleName, final String namespace) {
42 moduleNameToNamespace.put(Objects.requireNonNull(moduleName), Objects.requireNonNull(namespace));
46 * Records a mapping between a namespace and the module defining it.
48 public void recordNamespaceMapping(final String namespace, final String moduleName) {
49 namespaceToModuleName.put(Objects.requireNonNull(namespace), Objects.requireNonNull(moduleName));
53 * Returns the namespace for the supplied module name. If the module name refers to a submodule, will
54 * return the namespace of the module owning the submodule. Returns null if the module is unknown.
56 public String getNamespaceForModule(final String moduleName) {
57 return moduleNameToNamespace.get(moduleName);
61 * Returns the module name for the supplied namespace. Returns null if the namespace is unknown.
63 public String getModuleForNamespace(final String namespace) {
64 return namespaceToModuleName.get(namespace);
68 public String toString() {
69 return "Mappings: " + moduleNameToNamespace.toString();