2 * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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 static com.google.common.base.Preconditions.checkArgument;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18 final class RFC7951JSONInstanceIdentifierCodec extends JSONInstanceIdentifierCodec {
19 RFC7951JSONInstanceIdentifierCodec(final SchemaContext context, final JSONCodecFactory jsonCodecFactory) {
20 super(context, jsonCodecFactory);
24 protected StringBuilder appendQName(final StringBuilder sb, final QName qname,
25 final @Nullable QNameModule lastModule) {
26 if (qname.getModule().equals(lastModule)) {
27 return sb.append(qname.getLocalName());
30 return super.appendQName(sb, qname, lastModule);
34 protected QName createQName(final @Nonnull QNameModule lastModule, final String localName) {
35 checkArgument(lastModule != null, "Unprefixed leading name %s", localName);
36 return QName.create(lastModule, localName);