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;
10 import com.google.gson.stream.JsonWriter;
11 import java.io.IOException;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15 import org.opendaylight.yangtools.yang.data.util.ModuleStringIdentityrefCodec;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 final class JSONStringIdentityrefCodec extends ModuleStringIdentityrefCodec implements JSONCodec<QName> {
20 JSONStringIdentityrefCodec(final SchemaContext context, final QNameModule parentModule) {
21 super(context, parentModule);
25 protected Module moduleForPrefix(@Nonnull final String prefix) {
26 if (prefix.isEmpty()) {
27 return context.findModuleByNamespaceAndRevision(parentModuleQname.getNamespace(),
28 parentModuleQname.getRevision());
31 return context.findModuleByName(prefix, null);
35 public Class<QName> getDataType() {
40 public QName parseValue(final Object ctx, final String str) {
41 return deserialize(str);
45 public void writeValue(final JsonWriter ctx, final QName value) throws IOException {
46 ctx.value(serialize(value));