2 * Copyright (c) 2014 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.yangtools.yang.data.codec.gson.helpers;
10 import com.google.common.base.Preconditions;
14 import org.opendaylight.yangtools.yang.model.api.Module;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 abstract class AbstractCodecImpl {
19 private static final Logger LOG = LoggerFactory.getLogger(AbstractCodecImpl.class);
20 private final SchemaContextUtils schema;
22 protected AbstractCodecImpl(final SchemaContextUtils schema) {
23 this.schema = Preconditions.checkNotNull(schema);
26 protected final SchemaContextUtils getSchema() {
30 protected final Module getModuleByNamespace(final String namespace) {
31 URI validNamespace = resolveValidNamespace(namespace);
33 Module module = schema.findModuleByNamespace(validNamespace);
35 LOG.info("Module for namespace " + validNamespace + " wasn't found.");
41 protected final URI resolveValidNamespace(final String namespace) {
42 URI validNamespace = schema.findNamespaceByModuleName(namespace);
43 if (validNamespace == null) {
44 validNamespace = URI.create(namespace);
47 return validNamespace;