Bug 1441: Implement XML Stream Reader to Normalized Node Writer
[yangtools.git] / yang / yang-data-util / src / main / java / org / opendaylight / yangtools / yang / data / util / ChoiceNodeDataWithSchema.java
1 /*
2  * Copyright (c) 2016 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.util;
9
10 import java.io.IOException;
11 import org.opendaylight.yangtools.yang.data.api.schema.stream.SchemaAwareNormalizedNodeStreamWriter;
12 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
13 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
15
16 /**
17  *
18  * childs - empty augment - only one element can be
19  *
20  */
21 class ChoiceNodeDataWithSchema extends CompositeNodeDataWithSchema {
22
23     private CaseNodeDataWithSchema caseNodeDataWithSchema;
24
25     ChoiceNodeDataWithSchema(final ChoiceSchemaNode schema) {
26         super(schema);
27     }
28
29     @Override
30     protected CompositeNodeDataWithSchema addCompositeChild(final DataSchemaNode schema) {
31         CaseNodeDataWithSchema newChild = new CaseNodeDataWithSchema((ChoiceCaseNode) schema);
32         caseNodeDataWithSchema = newChild;
33         addCompositeChild(newChild);
34         return newChild;
35     }
36
37     public CaseNodeDataWithSchema getCase() {
38         return caseNodeDataWithSchema;
39     }
40
41     @Override
42     public void write(final SchemaAwareNormalizedNodeStreamWriter writer) throws IOException {
43         writer.nextDataSchemaNode(getSchema());
44         writer.startChoiceNode(provideNodeIdentifier(), childSizeHint());
45         super.write(writer);
46         writer.endNode();
47     }
48
49 }