2 * Copyright (c) 2016 Intel Corporation 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.yangtools.yang.data.util;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15 import org.opendaylight.yangtools.yang.common.XMLNamespace;
16 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
20 * Base class for implementing identityref codecs on based on module names.
23 public abstract class ModuleStringIdentityrefCodec extends AbstractModuleStringIdentityrefCodec
24 implements EffectiveModelContextProvider {
25 private final @NonNull EffectiveModelContext context;
26 private final @NonNull QNameModule parentModule;
28 protected ModuleStringIdentityrefCodec(final @NonNull EffectiveModelContext context,
29 final @NonNull QNameModule parentModule) {
30 this.context = requireNonNull(context);
31 this.parentModule = requireNonNull(parentModule);
35 public final EffectiveModelContext getEffectiveModelContext() {
39 protected final QNameModule getParentModule() {
44 protected String prefixForNamespace(final XMLNamespace namespace) {
45 final var modules = context.findModuleStatements(namespace).iterator();
46 return modules.hasNext() ? modules.next().argument().getLocalName() : null;