2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.util;
10 import static com.google.common.base.Verify.verify;
12 import java.io.IOException;
13 import org.opendaylight.yangtools.rfc7952.data.api.StreamWriterMetadataExtension;
14 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
15 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
16 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
17 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
20 * childs - empty augment - only one element can be.
22 final class ChoiceNodeDataWithSchema extends CompositeNodeDataWithSchema<ChoiceSchemaNode> {
23 private CaseNodeDataWithSchema caseNodeDataWithSchema;
25 ChoiceNodeDataWithSchema(final ChoiceSchemaNode schema) {
29 // FIXME: 6.0.0: this should be impossible to hit
31 CaseNodeDataWithSchema addCompositeChild(final DataSchemaNode schema, final ChildReusePolicy policy) {
32 verify(schema instanceof CaseSchemaNode, "Unexpected schema %s", schema);
33 return addCompositeChild((CaseSchemaNode) schema, policy);
36 CaseNodeDataWithSchema addCompositeChild(final CaseSchemaNode schema, final ChildReusePolicy policy) {
37 CaseNodeDataWithSchema newChild = new CaseNodeDataWithSchema(schema);
38 caseNodeDataWithSchema = newChild;
39 addCompositeChild(newChild, policy);
43 CaseNodeDataWithSchema getCase() {
44 return caseNodeDataWithSchema;
48 public void write(final NormalizedNodeStreamWriter writer, final StreamWriterMetadataExtension metaWriter)
50 writer.nextDataSchemaNode(getSchema());
51 writer.startChoiceNode(provideNodeIdentifier(), childSizeHint());
52 super.write(writer, metaWriter);