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 org.opendaylight.yangtools.yang.common.QName;
11 import org.opendaylight.yangtools.yang.data.api.codec.IdentityrefCodec;
12 import org.opendaylight.yangtools.yang.data.codec.gson.helpers.IdentityValuesDTO.IdentityValue;
13 import org.opendaylight.yangtools.yang.model.api.Module;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 class IdentityrefCodecImpl extends AbstractCodecImpl implements IdentityrefCodec<IdentityValuesDTO> {
18 private static final Logger LOG = LoggerFactory.getLogger(IdentityrefCodecImpl.class);
20 IdentityrefCodecImpl(final SchemaContextUtils schema) {
25 public IdentityValuesDTO serialize(final QName data) {
26 return new IdentityValuesDTO(data.getNamespace().toString(), data.getLocalName(), data.getPrefix(), null);
30 public QName deserialize(final IdentityValuesDTO data) {
31 IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0);
32 Module module = getModuleByNamespace(valueWithNamespace.getNamespace());
34 LOG.info("Module was not found for namespace {}", valueWithNamespace.getNamespace());
35 LOG.info("Idenetityref will be translated as NULL for data - {}", String.valueOf(valueWithNamespace));
39 return QName.create(module.getNamespace(), module.getRevision(), valueWithNamespace.getValue());