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