Do not pretty-print body class
[yangtools.git] / data / yang-data-util / src / main / java / org / opendaylight / yangtools / yang / data / util / ModuleStringIdentityrefCodec.java
1 /*
2  * Copyright (c) 2016 Intel Corporation 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 package org.opendaylight.yangtools.yang.data.util;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import java.util.Iterator;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.common.XMLNamespace;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
18 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20
21 /**
22  * Base class for implementing identityref codecs on based on module names.
23  */
24 @Beta
25 public abstract class ModuleStringIdentityrefCodec extends AbstractModuleStringIdentityrefCodec
26         implements EffectiveModelContextProvider {
27     private final EffectiveModelContext context;
28     private final QNameModule parentModule;
29
30     protected ModuleStringIdentityrefCodec(final @NonNull EffectiveModelContext context,
31             final @NonNull QNameModule parentModule) {
32         this.context = requireNonNull(context);
33         this.parentModule = requireNonNull(parentModule);
34     }
35
36     @Override
37     public final EffectiveModelContext getEffectiveModelContext() {
38         return context;
39     }
40
41     protected final QNameModule getParentModule() {
42         return parentModule;
43     }
44
45     @Override
46     protected String prefixForNamespace(final XMLNamespace namespace) {
47         final Iterator<? extends Module> modules = context.findModules(namespace).iterator();
48         return modules.hasNext() ? modules.next().getName() : null;
49     }
50 }