private void writeRootElement(final XMLStreamWriter xmlWriter, final OrderedNormalizedNodeWriter nnWriter, final ContainerNode data) { try { Collection<DataContainerChild<?, ?>> value = (Collection) data.getValue(); nnWriter.write(value); nnWriter.flush(); xmlWriter.flush(); } catch (XMLStreamException | IOException e) { Throwables.propagate(e); } }
public OrderedNormalizedNodeWriter(NormalizedNodeStreamWriter writer, SchemaContext schemaContext, SchemaPath path) { this.writer = writer; this.schemaContext = schemaContext; this.root = findParentSchemaOnPath(schemaContext, path); }
private void writeNormalizedRpc(final ContainerNode normalized, final DOMResult result, final SchemaPath schemaPath, final SchemaContext baseNetconfCtx) throws IOException, XMLStreamException { final OrderedNormalizedNodeWriter normalizedNodeWriter; NormalizedNodeStreamWriter normalizedNodeStreamWriter = null; XMLStreamWriter writer = null; try { writer = NetconfMessageTransformUtil.XML_FACTORY.createXMLStreamWriter(result); normalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(writer, baseNetconfCtx, schemaPath); normalizedNodeWriter = new OrderedNormalizedNodeWriter(normalizedNodeStreamWriter, baseNetconfCtx, schemaPath); Collection<DataContainerChild<?, ?>> value = (Collection) normalized.getValue(); normalizedNodeWriter.write(value); normalizedNodeWriter.flush(); } finally { try { if(normalizedNodeStreamWriter != null) { normalizedNodeStreamWriter.close(); } if(writer != null) { writer.close(); } } catch (final Exception e) { LOG.warn("Unable to close resource properly", e); } } }
for (NormalizedNode<?, ?> child : children) { if (child instanceof AugmentationNode) { qNameToNodes.putAll(resolveAugmentations(child)); } else { qNameToNodes.put(child.getNodeType(), child); write(qNameToNodes.get(parentSchemaNode.getQName()), parentSchemaNode); } else { for (DataSchemaNode schemaNode : ((DataNodeContainer) parentSchemaNode).getChildNodes()) { write(qNameToNodes.get(schemaNode.getQName()), schemaNode); for (DataSchemaNode dsn : ccNode.getChildNodes()) { if (qNameToNodes.containsKey(dsn.getQName())) { write(qNameToNodes.get(dsn.getQName()), dsn); writeLeaf(child);
private void write(List<NormalizedNode<?, ?>> nodes, SchemaNode dataSchemaNode) throws IOException { for (NormalizedNode<?, ?> node : nodes) { write(node, dataSchemaNode); } }
child = tryFindGroupings((SchemaContext) current, qname).orNull(); child = tryFindNotification((SchemaContext) current, qname) .or(tryFindRpc(((SchemaContext) current), qname)).orNull();
final ContainerNode n = (ContainerNode) node; if(writer instanceof NormalizedNodeStreamAttributeWriter) { ((NormalizedNodeStreamAttributeWriter) writer).startContainerNode(n.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(n.getValue()), n.getAttributes()); } else { writer.startContainerNode(n.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(n.getValue())); return writeChildren(n.getValue(), dataSchemaNode, true); return writeMapEntryNode((MapEntryNode) node, dataSchemaNode); writer.startUnkeyedListItem(n.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(n.getValue())); return writeChildren(n.getValue(), dataSchemaNode, true); writer.startChoiceNode(n.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(n.getValue())); return writeChildren(n.getValue(), dataSchemaNode, true); return writeChildren(n.getValue(), dataSchemaNode, true); writer.startUnkeyedList(n.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(n.getValue())); return writeChildren(n.getValue(), dataSchemaNode, true); writer.startOrderedMapNode(n.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(n.getValue())); return writeChildren(n.getValue(), dataSchemaNode, true); writer.startMapNode(n.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(n.getValue())); return writeChildren(n.getValue(), dataSchemaNode, true); writer.startLeafSet(n.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(n.getValue())); return writeChildren(n.getValue(), dataSchemaNode, true);
private boolean writeMapEntryNode(final MapEntryNode node, final SchemaNode dataSchemaNode) throws IOException { if(writer instanceof NormalizedNodeStreamAttributeWriter) { ((NormalizedNodeStreamAttributeWriter) writer) .startMapEntryNode(node.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(node.getValue()), node.getAttributes()); } else { writer.startMapEntryNode(node.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(node.getValue())); } return writeChildren(node.getValue(), dataSchemaNode, true); }
private Node transformNormalizedNode(final Document document, final NormalizedNode<?, ?> data, final SchemaPath rpcOutputPath) { final DOMResult result = new DOMResult(document.createElement(XmlNetconfConstants.RPC_REPLY_KEY)); final XMLStreamWriter xmlWriter = getXmlStreamWriter(result); final NormalizedNodeStreamWriter nnStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, schemaContext.getCurrentContext(), rpcOutputPath); final OrderedNormalizedNodeWriter nnWriter = new OrderedNormalizedNodeWriter(nnStreamWriter, schemaContext.getCurrentContext(), rpcOutputPath); writeRootElement(xmlWriter, nnWriter, (ContainerNode) data); try { nnStreamWriter.close(); xmlWriter.close(); } catch (IOException | XMLStreamException e) { LOG.warn("Error while closing streams", e); } return result.getNode(); }
private ArrayListMultimap<QName, NormalizedNode<?, ?>> resolveAugmentations(NormalizedNode<?, ?> child) { final ArrayListMultimap<QName, NormalizedNode<?, ?>> resolvedAugs = ArrayListMultimap.create(); for (NormalizedNode<?, ?> node : ((AugmentationNode) child).getValue()) { if (node instanceof AugmentationNode) { resolvedAugs.putAll(resolveAugmentations(node)); } else { resolvedAugs.put(node.getNodeType(), node); } } return resolvedAugs; }