2 * Copyright (c) 2016 Brocade Communications 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.codec.xml;
10 import java.io.IOException;
11 import java.util.ArrayDeque;
12 import java.util.Collections;
13 import java.util.Deque;
15 import javax.xml.stream.XMLStreamException;
16 import javax.xml.stream.XMLStreamWriter;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
22 final class SchemalessXMLStreamNormalizedNodeStreamWriter extends XMLStreamNormalizedNodeStreamWriter<Object> {
23 private enum ContainerType {
33 private final Deque<ContainerType> containerTypeStack = new ArrayDeque<>();
35 SchemalessXMLStreamNormalizedNodeStreamWriter(final XMLStreamWriter writer) {
40 public void leafNode(final NodeIdentifier name, final Object value, final Map<QName, String> attributes)
42 writeElement(name.getNodeType(), value, attributes, null);
46 public void leafNode(final NodeIdentifier name, final Object value) throws IOException {
47 writeElement(name.getNodeType(), value, Collections.emptyMap(), null);
51 public void leafSetEntryNode(final QName name, final Object value, final Map<QName, String> attributes)
53 writeElement(name, value, attributes, null);
57 public void leafSetEntryNode(final QName name, final Object value) throws IOException {
58 writeElement(name, value, Collections.emptyMap(), null);
62 public void startLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException {
63 containerTypeStack.push(ContainerType.LEAF_SET);
67 public void startOrderedLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException {
68 containerTypeStack.push(ContainerType.LEAF_SET);
72 public void startContainerNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
73 containerTypeStack.push(ContainerType.CONTAINER);
74 startElement(name.getNodeType());
78 public void startChoiceNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
79 containerTypeStack.push(ContainerType.CHOICE);
83 public void startAugmentationNode(final AugmentationIdentifier identifier) throws IOException {
84 containerTypeStack.push(ContainerType.AUGMENTATION);
88 public void anyxmlNode(final NodeIdentifier name, final Object value) throws IOException {
89 anyxmlNode(name.getNodeType(), value);
93 public void startYangModeledAnyXmlNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
94 containerTypeStack.push(ContainerType.ANY_XML);
95 startElement(name.getNodeType());
99 void writeValue(final XMLStreamWriter xmlWriter, final QName qname, final Object value, final Object context)
100 throws XMLStreamException {
101 xmlWriter.writeCharacters(value.toString());
105 void startList(final NodeIdentifier name) {
106 containerTypeStack.push(ContainerType.LIST);
110 void startListItem(final PathArgument name) throws IOException {
111 containerTypeStack.push(ContainerType.LIST_ITEM);
112 startElement(name.getNodeType());
116 public void endNode() throws IOException {
117 ContainerType type = containerTypeStack.pop();