private void write(List<NormalizedNode<?, ?>> nodes, SchemaNode dataSchemaNode) throws IOException { for (NormalizedNode<?, ?> node : nodes) { write(node, dataSchemaNode); } }
public OrderedNormalizedNodeWriter(NormalizedNodeStreamWriter writer, SchemaContext schemaContext, SchemaPath path) { this.writer = writer; this.schemaContext = schemaContext; this.root = findParentSchemaOnPath(schemaContext, path); }
private OrderedNormalizedNodeWriter write(NormalizedNode<?, ?> node, SchemaNode dataSchemaNode) throws IOException { if (node == null) { return this; } if (wasProcessedAsCompositeNode(node, dataSchemaNode)) { return this; } if (wasProcessAsSimpleNode(node)) { return this; } throw new IllegalStateException("It wasn't possible to serialize node " + node); }
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); } } }
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); } }
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);
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 Optional<SchemaNode> tryFindRpc(final SchemaContext ctx, final QName qname) { return Optional.<SchemaNode>fromNullable(Iterables.find(ctx.getOperations(), new SchemaNodePredicate(qname), null)); }
@Override public void close() { try { CloseableUtil.closeAll(services); } catch (final Exception e) { throw new IllegalStateException("Unable to properly close all aggregated services", e); } } }
public OrderedNormalizedNodeWriter write(final Collection<DataContainerChild<?,?>> nodes) throws IOException { if (writeChildren(nodes, root, false)) { return this; } throw new IllegalStateException("It wasn't possible to serialize nodes " + nodes); }
private OrderedNormalizedNodeWriter writeLeaf(final NormalizedNode<?, ?> node) throws IOException { if (wasProcessAsSimpleNode(node)) { return this; } throw new IllegalStateException("It wasn't possible to serialize node " + node); }
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; }
private Optional<SchemaNode> tryFindGroupings(final SchemaContext ctx, final QName qname) { return Optional.<SchemaNode> fromNullable(Iterables.find(ctx.getGroupings(), new SchemaNodePredicate(qname), null)); }
@Override public void close() throws Exception { synchronized (AggregatedNetconfOperationServiceFactory.this) { listeners.remove(listener); CloseableUtil.closeAll(regs.values()); for (final Map.Entry<NetconfOperationServiceFactory, AutoCloseable> reg : regs.entrySet()) { registrations.remove(reg.getKey(), reg.getValue()); } } } };
private Optional<SchemaNode> tryFindNotification(final SchemaContext ctx, final QName qname) { return Optional.<SchemaNode>fromNullable(Iterables.find(ctx.getNotifications(), new SchemaNodePredicate(qname), null)); }