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;
14 import java.util.Iterator;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.yang.common.QNameModule;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
22 * Base class for implementing identityref codecs on based on module names.
25 public abstract class ModuleStringIdentityrefCodec extends AbstractModuleStringIdentityrefCodec
26 implements SchemaContextProvider {
27 private final SchemaContext context;
28 private final QNameModule parentModule;
30 protected ModuleStringIdentityrefCodec(final @NonNull SchemaContext context,
31 final @NonNull QNameModule parentModule) {
32 this.context = requireNonNull(context);
33 this.parentModule = requireNonNull(parentModule);
37 public final SchemaContext getSchemaContext() {
41 protected final QNameModule getParentModule() {
46 protected String prefixForNamespace(final URI namespace) {
47 final Iterator<? extends Module> modules = context.findModules(namespace).iterator();
48 return modules.hasNext() ? modules.next().getName() : null;