Bug 5730 - Delete subset of list items using PATCH?
[netconf.git] / restconf / sal-rest-connector / src / main / java / org / opendaylight / netconf / sal / rest / impl / StringModuleInstanceIdentifierCodec.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.netconf.sal.rest.impl;
10
11 import com.google.common.base.Preconditions;
12 import java.net.URI;
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;
19
20 final class StringModuleInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec {
21
22     private final DataSchemaContextTree dataContextTree;
23     private final SchemaContext context;
24
25     StringModuleInstanceIdentifierCodec(SchemaContext context) {
26         this.context = Preconditions.checkNotNull(context);
27         this.dataContextTree = DataSchemaContextTree.from(context);
28     }
29
30     @Override
31     protected Module moduleForPrefix(@Nonnull String prefix) {
32         return context.findModuleByName(prefix, null);
33     }
34
35     @Nonnull
36     @Override
37     protected DataSchemaContextTree getDataContextTree() {
38         return dataContextTree;
39     }
40
41     @Nullable
42     @Override
43     protected String prefixForNamespace(@Nonnull URI namespace) {
44         final Module module = context.findModuleByNamespaceAndRevision(namespace, null);
45         return module == null ? null : module.getName();
46     }
47 }