Merge "Added tests for yang.model.util"
[yangtools.git] / yang / yang-data-codec-gson / src / main / java / org / opendaylight / yangtools / yang / data / codec / gson / ChoiceNodeDataWithSchema.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 java.io.IOException;
11
12 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
13 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
14 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
15 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
16
17 /**
18  *
19  * childs - empty augment - only one element can be
20  *
21  */
22 class ChoiceNodeDataWithSchema extends CompositeNodeDataWithSchema {
23
24     private CaseNodeDataWithSchema caseNodeDataWithSchema;
25
26     public ChoiceNodeDataWithSchema(final ChoiceNode schema) {
27         super(schema);
28     }
29
30     @Override
31     protected CompositeNodeDataWithSchema addCompositeChild(final DataSchemaNode schema) {
32         CaseNodeDataWithSchema newChild = new CaseNodeDataWithSchema((ChoiceCaseNode) schema);
33         caseNodeDataWithSchema = newChild;
34         addCompositeChild(newChild);
35         return newChild;
36     }
37
38     public CaseNodeDataWithSchema getCase() {
39         return caseNodeDataWithSchema;
40     }
41
42     @Override
43     public void write(final NormalizedNodeStreamWriter writer) throws IOException {
44         writer.startChoiceNode(provideNodeIdentifier(), childSizeHint());
45         super.write(writer);
46         writer.endNode();
47     }
48
49 }