2 * Copyright (c) 2016 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.netconf.sal.rest.impl;
10 import static java.util.Objects.requireNonNull;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.data.util.AbstractModuleStringInstanceIdentifierCodec;
15 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 * Codec for module instance identifiers.
22 * @deprecated This class will be replaced by StringModuleInstanceIdentifierCodec from restconf-nb-rfc8040
25 public final class StringModuleInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec {
27 private final DataSchemaContextTree dataContextTree;
28 private final SchemaContext context;
29 private final String defaultPrefix;
31 public StringModuleInstanceIdentifierCodec(final SchemaContext context) {
32 this.context = requireNonNull(context);
33 this.dataContextTree = DataSchemaContextTree.from(context);
34 this.defaultPrefix = "";
37 StringModuleInstanceIdentifierCodec(final SchemaContext context, final @NonNull String defaultPrefix) {
38 this.context = requireNonNull(context);
39 this.dataContextTree = DataSchemaContextTree.from(context);
40 this.defaultPrefix = defaultPrefix;
44 protected Module moduleForPrefix(final String prefix) {
45 if (prefix.isEmpty() && !this.defaultPrefix.isEmpty()) {
46 return this.context.findModules(this.defaultPrefix).stream().findFirst().orElse(null);
48 return this.context.findModules(prefix).stream().findFirst().orElse(null);
53 protected DataSchemaContextTree getDataContextTree() {
54 return this.dataContextTree;
58 protected String prefixForNamespace(final URI namespace) {
59 return this.context.findModules(namespace).stream().findFirst().map(Module::getName).orElse(null);