BUG-1704: rework state tracking
[yangtools.git] / yang / yang-data-codec-gson / src / main / java / org / opendaylight / yangtools / yang / data / codec / gson / JSONStreamWriterQNameContext.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.codec.gson;
9
10 import com.google.common.base.Preconditions;
11
12 import java.net.URI;
13
14 import org.opendaylight.yangtools.yang.common.QName;
15
16 /**
17  * Abstract base class for {@link JSONNormalizedNodeStreamWriter} recursion
18  * levels which emit a QName-identified node.
19  */
20 abstract class JSONStreamWriterQNameContext extends JSONStreamWriterContext {
21     private final QName qname;
22
23     protected JSONStreamWriterQNameContext(final JSONStreamWriterContext parent, final QName qname, final boolean mandatory) {
24         super(parent, mandatory);
25         this.qname = Preconditions.checkNotNull(qname);
26     }
27
28     /**
29      * Returns the node's identifier as a QName.
30      *
31      * @return QName identifier
32      */
33     protected final QName getQName() {
34         return qname;
35     }
36
37     @Override
38     protected final URI getNamespace() {
39         return qname.getNamespace();
40     }
41 }