Refactor ListEntryNodeDataWithSchema
[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.NormalizedNodeStreamWriter;
12 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
13 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
15
16 /**
17  * childs - empty augment - only one element can be.
18  */
19 class ChoiceNodeDataWithSchema extends CompositeNodeDataWithSchema<ChoiceSchemaNode> {
20     private CaseNodeDataWithSchema caseNodeDataWithSchema;
21
22     ChoiceNodeDataWithSchema(final ChoiceSchemaNode schema) {
23         super(schema);
24     }
25
26     @Override
27     protected CaseNodeDataWithSchema addCompositeChild(final DataSchemaNode schema) {
28         CaseNodeDataWithSchema newChild = new CaseNodeDataWithSchema((CaseSchemaNode) schema);
29         caseNodeDataWithSchema = newChild;
30         addCompositeChild(newChild);
31         return newChild;
32     }
33
34     public CaseNodeDataWithSchema getCase() {
35         return caseNodeDataWithSchema;
36     }
37
38     @Override
39     public void write(final NormalizedNodeStreamWriter writer) throws IOException {
40         writer.nextDataSchemaNode(getSchema());
41         writer.startChoiceNode(provideNodeIdentifier(), childSizeHint());
42         super.write(writer);
43         writer.endNode();
44     }
45 }