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.restconf.nb.rfc8040.utils.parser;
10 import static java.util.Objects.requireNonNull;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.common.XMLNamespace;
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.EffectiveModelContext;
17 import org.opendaylight.yangtools.yang.model.api.Module;
19 final class StringModuleInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec {
20 private final @NonNull EffectiveModelContext context;
22 private volatile DataSchemaContextTree dataContextTree;
24 StringModuleInstanceIdentifierCodec(final @NonNull EffectiveModelContext context) {
25 this.context = requireNonNull(context);
29 protected Module moduleForPrefix(final String prefix) {
30 return context.findModules(prefix).stream().findFirst().orElse(null);
34 protected DataSchemaContextTree getDataContextTree() {
35 DataSchemaContextTree local = dataContextTree;
37 dataContextTree = local = DataSchemaContextTree.from(context);
43 protected String prefixForNamespace(final XMLNamespace namespace) {
44 return context.findModules(namespace).stream().findFirst().map(Module::getName).orElse(null);