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
9 package org.opendaylight.netconf.sal.rest.impl;
11 import com.google.common.base.Preconditions;
13 import javax.annotation.Nonnull;
14 import javax.annotation.Nullable;
15 import org.opendaylight.yangtools.yang.data.util.AbstractModuleStringInstanceIdentifierCodec;
16 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 * Codec for module instance identifiers.
23 * @deprecated This class will be replaced by StringModuleInstanceIdentifierCodec from restconf-nb-rfc8040
26 public final class StringModuleInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec {
28 private final DataSchemaContextTree dataContextTree;
29 private final SchemaContext context;
30 private final String defaultPrefix;
32 public StringModuleInstanceIdentifierCodec(final SchemaContext context) {
33 this.context = Preconditions.checkNotNull(context);
34 this.dataContextTree = DataSchemaContextTree.from(context);
35 this.defaultPrefix = "";
38 StringModuleInstanceIdentifierCodec(final SchemaContext context, @Nonnull final String defaultPrefix) {
39 this.context = Preconditions.checkNotNull(context);
40 this.dataContextTree = DataSchemaContextTree.from(context);
41 this.defaultPrefix = defaultPrefix;
45 protected Module moduleForPrefix(@Nonnull final String prefix) {
46 if (prefix.isEmpty() && !this.defaultPrefix.isEmpty()) {
47 return this.context.findModuleByName(this.defaultPrefix, null);
49 return this.context.findModuleByName(prefix, null);
55 protected DataSchemaContextTree getDataContextTree() {
56 return this.dataContextTree;
61 protected String prefixForNamespace(@Nonnull final URI namespace) {
62 final Module module = this.context.findModuleByNamespaceAndRevision(namespace, null);
63 return module == null ? null : module.getName();