- @Override
- public void startLeafNode(final NodeIdentifier name) throws IOException {
- LOG.trace("Starting a new leaf node");
- startNode(name, NodeTypes.LEAF_NODE);
- inSimple = true;
- }
-
- @Override
- public void startLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException {
- LOG.trace("Starting a new leaf set");
- commonStartLeafSet(name, NodeTypes.LEAF_SET);
- }
-
- @Override
- public void startOrderedLeafSet(final NodeIdentifier name, final int childSizeHint) throws IOException {
- LOG.trace("Starting a new ordered leaf set");
- commonStartLeafSet(name, NodeTypes.ORDERED_LEAF_SET);
- }
-
- private void commonStartLeafSet(final NodeIdentifier name, final byte nodeType) throws IOException {
- startNode(name, nodeType);
- lastLeafSetQName = name.getNodeType();
- }
-
- @Override
- public void startLeafSetEntryNode(final NodeWithValue<?> name) throws IOException {
- LOG.trace("Starting a new leaf set entry node");
-
- output.writeByte(NodeTypes.LEAF_SET_ENTRY_NODE);
-
- // lastLeafSetQName is set if the parent LeafSetNode was previously written. Otherwise this is a
- // stand alone LeafSetEntryNode so write out it's name here.
- if (lastLeafSetQName == null) {
- writeQNameInternal(name.getNodeType());
- }
- inSimple = true;
- }
-
- @Override
- public void startContainerNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
- LOG.trace("Starting a new container node");
- startNode(name, NodeTypes.CONTAINER_NODE);
- }
-
- @Override
- public void startYangModeledAnyXmlNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
- LOG.trace("Starting a new yang modeled anyXml node");
- startNode(name, NodeTypes.YANG_MODELED_ANY_XML_NODE);
- }
-
- @Override
- public void startUnkeyedList(final NodeIdentifier name, final int childSizeHint) throws IOException {
- LOG.trace("Starting a new unkeyed list");
- startNode(name, NodeTypes.UNKEYED_LIST);
- }
-
- @Override
- public void startUnkeyedListItem(final NodeIdentifier name, final int childSizeHint) throws IOException {
- LOG.trace("Starting a new unkeyed list item");
- startNode(name, NodeTypes.UNKEYED_LIST_ITEM);
- }
-
- @Override
- public void startMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
- LOG.trace("Starting a new map node");
- startNode(name, NodeTypes.MAP_NODE);
- }
-
- @Override
- public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint)
- throws IOException {
- LOG.trace("Starting a new map entry node");
- startNode(identifier, NodeTypes.MAP_ENTRY_NODE);
- writeKeyValueMap(identifier.entrySet());
- }
-
- @Override
- public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
- LOG.trace("Starting a new ordered map node");
- startNode(name, NodeTypes.ORDERED_MAP_NODE);
- }
-
- @Override
- public void startChoiceNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
- LOG.trace("Starting a new choice node");
- startNode(name, NodeTypes.CHOICE_NODE);
- }
-
- @Override
- public void startAugmentationNode(final AugmentationIdentifier identifier) throws IOException {
- requireNonNull(identifier, "Node identifier should not be null");
- LOG.trace("Starting a new augmentation node");
-
- output.writeByte(NodeTypes.AUGMENTATION_NODE);
- writeAugmentationIdentifier(identifier);
- }
-
- @Override
- public void startAnyxmlNode(final NodeIdentifier name) throws IOException {
- LOG.trace("Starting any xml node");
- startNode(name, NodeTypes.ANY_XML_NODE);
- inSimple = true;
- }
-
- @Override
- public void scalarValue(final Object value) throws IOException {
- writeObject(value);
- }
-
- @Override
- public void domSourceValue(final DOMSource value) throws IOException {
- try {
- StreamResult xmlOutput = new StreamResult(new StringWriter());
- TransformerFactory.newInstance().newTransformer().transform(value, xmlOutput);
- writeObject(xmlOutput.getWriter().toString());
- } catch (TransformerException | TransformerFactoryConfigurationError e) {
- throw new IOException("Error writing anyXml", e);
- }
- }
-
- @Override
- public void endNode() throws IOException {
- LOG.trace("Ending the node");
- if (!inSimple) {
- lastLeafSetQName = null;
- output.writeByte(NodeTypes.END_NODE);
- }
- inSimple = false;
- }
-