@SuppressWarnings("unchecked") protected void writeChild(final NormalizedNode<?, ?> child) { getCurrent().addChild(child); }
@SuppressWarnings("unchecked") protected void writeChild(final NormalizedNode<?, ?> child) { getCurrent().addChild(child); }
@Override @SuppressWarnings({"rawtypes","unchecked"}) public void endNode() { final NormalizedNodeContainerBuilder finishedBuilder = builders.poll(); checkState(finishedBuilder != null, "Node which should be closed does not exists."); final NormalizedNodeContainerBuilder current = getCurrent(); checkState(current != null, "Reached top level node, which could not be closed in this writer."); final NormalizedNode<PathArgument, ?> product = finishedBuilder.build(); current.addChild(product); nextSchema = null; }
@Override @SuppressWarnings({"rawtypes","unchecked"}) public void endNode() { final NormalizedNodeContainerBuilder finishedBuilder = builders.poll(); checkState(finishedBuilder != null, "Node which should be closed does not exists."); final NormalizedNodeContainerBuilder current = getCurrent(); checkState(current != null, "Reached top level node, which could not be closed in this writer."); final NormalizedNode<PathArgument, ?> product = finishedBuilder.build(); current.addChild(product); nextSchema = null; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private NormalizedNodeContainerBuilder addDataContainerChildren( final NormalizedNodeContainerBuilder builder) throws IOException { LOG.trace("Reading data container (leaf nodes) nodes"); NormalizedNode<?, ?> child = readNormalizedNodeInternal(); while (child != null) { builder.addChild(child); child = readNormalizedNodeInternal(); } return builder; }
@SuppressWarnings({ "unchecked", "rawtypes" }) private NormalizedNodeContainerBuilder addDataContainerChildren( final NormalizedNodeContainerBuilder builder) throws IOException { LOG.debug("Reading data container (leaf nodes) nodes"); NormalizedNode<?, ?> child = readNormalizedNodeInternal(); while(child != null) { builder.addChild(child); child = readNormalizedNodeInternal(); } return builder; }
@Override @SuppressWarnings("unchecked") final NormalizedNode<?, ?> create(final PathArgument first, final Iterator<PathArgument> others, final Optional<NormalizedNode<?, ?>> lastChild, final Optional<Entry<QName, ModifyAction>> operation) { if (!isMixin()) { final QName type = getIdentifier().getNodeType(); if (type != null) { final QName firstType = first.getNodeType(); checkArgument(type.equals(firstType), "Node QName must be %s was %s", type, firstType); } } @SuppressWarnings("rawtypes") final NormalizedNodeContainerBuilder builder = createBuilder(first); if (others.hasNext()) { final PathArgument childPath = others.next(); final InstanceIdToNodes<?> childOp = getChildOperation(childPath); builder.addChild(childOp.create(childPath, others, lastChild, operation)); } else { if (lastChild.isPresent()) { builder.withValue(ImmutableList.copyOf((Collection<?>) lastChild.get().getValue())); } if (operation.isPresent()) { checkArgument(builder instanceof AttributesBuilder<?>); addModifyOpIfPresent(operation, (AttributesBuilder<?>) builder); } } return builder.build(); }
@Override @SuppressWarnings("unchecked") final NormalizedNode<?, ?> create(final PathArgument first, final Iterator<PathArgument> others, final Optional<NormalizedNode<?, ?>> lastChild, final Optional<Entry<QName, ModifyAction>> operation) { if (!isMixin()) { final QName type = getIdentifier().getNodeType(); if (type != null) { final QName firstType = first.getNodeType(); checkArgument(type.equals(firstType), "Node QName must be %s was %s", type, firstType); } } @SuppressWarnings("rawtypes") final NormalizedNodeContainerBuilder builder = createBuilder(first); if (others.hasNext()) { final PathArgument childPath = others.next(); final InstanceIdToNodes<?> childOp = getChildOperation(childPath); builder.addChild(childOp.create(childPath, others, lastChild, operation)); } else { if (lastChild.isPresent()) { builder.withValue(ImmutableList.copyOf((Collection<?>) lastChild.get().getValue())); } if (operation.isPresent()) { checkArgument(builder instanceof AttributesBuilder<?>); addModifyOpIfPresent(operation, (AttributesBuilder<?>) builder); } } return builder.build(); }
@Override public void endNode() throws IOException, IllegalStateException { checkNotSealed(); NormalizedNodeBuilderWrapper child = stack.pop(); Preconditions.checkState(child != null, "endNode called on an empty stack"); if(!child.getSchema().isPresent()) { LOG.debug("Schema not found for {}", child.identifier()); return; } NormalizedNode<?,?> normalizedNode = child.builder().build(); if(stack.size() > 0) { NormalizedNodeBuilderWrapper parent = stack.peek(); parent.builder().addChild(normalizedNode); } else { this.normalizedNode = normalizedNode; sealed = true; } }
@SuppressWarnings("unchecked") @Override public void endNode() throws IllegalStateException { checkNotSealed(); NormalizedNodeBuilderWrapper child = stack.pop(); Preconditions.checkState(child != null, "endNode called on an empty stack"); if (!child.getSchema().isPresent()) { LOG.debug("Schema not found for {}", child.identifier()); return; } NormalizedNode<?,?> newNode = child.builder().build(); if (stack.size() > 0) { NormalizedNodeBuilderWrapper parent = stack.peek(); parent.builder().addChild(newNode); } else { this.normalizedNode = newNode; sealed = true; } }
/** * Applies write/remove diff operation for each modification child in modification subtree. * Operation also sets the Data tree references for each Tree Node (Index Node) in meta (MutableTreeNode) structure. * * @param meta MutableTreeNode (IndexTreeNode) * @param data DataBuilder * @param nodeVersion Version of TreeNode * @param modifications modification operations to apply * @return Sealed immutable copy of TreeNode structure with all Data Node references set. */ @SuppressWarnings({ "rawtypes", "unchecked" }) private TreeNode mutateChildren(final MutableTreeNode meta, final NormalizedNodeContainerBuilder data, final Version nodeVersion, final Iterable<ModifiedNode> modifications) { for (final ModifiedNode mod : modifications) { final PathArgument id = mod.getIdentifier(); final Optional<TreeNode> cm = meta.getChild(id); final Optional<TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion); if (result.isPresent()) { final TreeNode tn = result.get(); meta.addChild(tn); data.addChild(tn.getData()); } else { meta.removeChild(id); data.removeChild(id); } } meta.setData(data.build()); return meta.seal(); }
/** * Applies write/remove diff operation for each modification child in modification subtree. * Operation also sets the Data tree references for each Tree Node (Index Node) in meta (MutableTreeNode) structure. * * @param meta MutableTreeNode (IndexTreeNode) * @param data DataBuilder * @param nodeVersion Version of TreeNode * @param modifications modification operations to apply * @return Sealed immutable copy of TreeNode structure with all Data Node references set. */ @SuppressWarnings({ "rawtypes", "unchecked" }) private TreeNode mutateChildren(final MutableTreeNode meta, final NormalizedNodeContainerBuilder data, final Version nodeVersion, final Iterable<ModifiedNode> modifications) { for (final ModifiedNode mod : modifications) { final PathArgument id = mod.getIdentifier(); final Optional<TreeNode> cm = meta.getChild(id); final Optional<TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion); if (result.isPresent()) { final TreeNode tn = result.get(); meta.addChild(tn); data.addChild(tn.getData()); } else { meta.removeChild(id); data.removeChild(id); } } meta.setData(data.build()); return meta.seal(); }
/** * Applies write/remove diff operation for each modification child in modification subtree. * Operation also sets the Data tree references for each Tree Node (Index Node) in meta (MutableTreeNode) structure. * * @param meta MutableTreeNode (IndexTreeNode) * @param data DataBuilder * @param nodeVersion Version of TreeNode * @param modifications modification operations to apply * @return Sealed immutable copy of TreeNode structure with all Data Node references set. */ @SuppressWarnings({ "rawtypes", "unchecked" }) private TreeNode mutateChildren(final MutableTreeNode meta, final NormalizedNodeContainerBuilder data, final Version nodeVersion, final Iterable<ModifiedNode> modifications) { for (final ModifiedNode mod : modifications) { final PathArgument id = mod.getIdentifier(); final Optional<TreeNode> cm = meta.getChild(id); final Optional<TreeNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion); if (result.isPresent()) { final TreeNode tn = result.get(); meta.addChild(tn); data.addChild(tn.getData()); } else { meta.removeChild(id); data.removeChild(id); } } meta.setData(data.build()); return meta.seal(); }
@SuppressWarnings("unchecked") @Override public void leafNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object o) throws IOException, IllegalArgumentException { checkNotSealed(); NormalizedNodeBuilderWrapper parent = stack.peek(); LeafNode<Object> leafNode = Builders.leafBuilder().withNodeIdentifier(nodeIdentifier).withValue(o).build(); if(parent != null) { if(hasValidSchema(nodeIdentifier.getNodeType(), parent)) { parent.builder().addChild(leafNode); } } else { // If there's no parent node then this is a stand alone LeafNode. if(nodePathSchemaNode != null) { this.normalizedNode = leafNode; } sealed = true; } }
@SuppressWarnings("unchecked") @Override public void leafNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object value) throws IllegalArgumentException { checkNotSealed(); NormalizedNodeBuilderWrapper parent = stack.peek(); LeafNode<Object> leafNode = Builders.leafBuilder().withNodeIdentifier(nodeIdentifier).withValue(value).build(); if (parent != null) { if (hasValidSchema(nodeIdentifier.getNodeType(), parent)) { parent.builder().addChild(leafNode); } } else { // If there's no parent node then this is a stand alone LeafNode. if (nodePathSchemaNode != null) { this.normalizedNode = leafNode; } sealed = true; } }
@SuppressWarnings("unchecked") @Override public void anyxmlNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object o) throws IOException, IllegalArgumentException { checkNotSealed(); NormalizedNodeBuilderWrapper parent = stack.peek(); AnyXmlNode anyXmlNode = Builders.anyXmlBuilder().withNodeIdentifier(nodeIdentifier). withValue((DOMSource) o).build(); if(parent != null) { if(hasValidSchema(nodeIdentifier.getNodeType(), parent)) { parent.builder().addChild(anyXmlNode); } } else { // If there's no parent node then this is a stand alone AnyXmlNode. if(nodePathSchemaNode != null) { this.normalizedNode = anyXmlNode; } sealed = true; } }
@SuppressWarnings("unchecked") @Override public void anyxmlNode(YangInstanceIdentifier.NodeIdentifier nodeIdentifier, Object value) throws IllegalArgumentException { checkNotSealed(); NormalizedNodeBuilderWrapper parent = stack.peek(); AnyXmlNode anyXmlNode = Builders.anyXmlBuilder().withNodeIdentifier(nodeIdentifier).withValue((DOMSource) value) .build(); if (parent != null) { if (hasValidSchema(nodeIdentifier.getNodeType(), parent)) { parent.builder().addChild(anyXmlNode); } } else { // If there's no parent node then this is a stand alone AnyXmlNode. if (nodePathSchemaNode != null) { this.normalizedNode = anyXmlNode; } sealed = true; } }
private void createEmptyMonitor() { final DOMDataWriteTransaction wTx = this.domDataBroker.newWriteOnlyTransaction(); ensureParentExists(wTx, YangInstanceIdentifier.of(BmpMonitor.QNAME)); wTx.put(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.builder().node(BmpMonitor.QNAME).node(Monitor.QNAME) .nodeWithKey(Monitor.QNAME, MONITOR_ID_QNAME, this.monitorId.getValue()).build(), ImmutableNodes.mapEntryBuilder(Monitor.QNAME, MONITOR_ID_QNAME, this.monitorId.getValue()) .addChild(ImmutableNodes.leafNode(MONITOR_ID_QNAME, this.monitorId.getValue())) .addChild(ImmutableNodes.mapNodeBuilder(Router.QNAME).build()) .build()); try { wTx.submit().checkedGet(); } catch (final TransactionCommitFailedException e) { LOG.error("Failed to initiate BMP Monitor {}.", this.monitorId.getValue(), e); } }
@SuppressWarnings({ "unchecked" }) @Override public void leafSetEntryNode(QName name, Object o) throws IOException, IllegalArgumentException { checkNotSealed(); NormalizedNodeBuilderWrapper parent = stack.peek(); if(parent != null) { if(hasValidSchema(name, parent)) { parent.builder().addChild(Builders.leafSetEntryBuilder().withValue(o).withNodeIdentifier( new YangInstanceIdentifier.NodeWithValue<>(parent.nodeType(), o)).build()); } } else { // If there's no parent LeafSetNode then this is a stand alone LeafSetEntryNode. if(nodePathSchemaNode != null) { this.normalizedNode = Builders.leafSetEntryBuilder().withValue(o).withNodeIdentifier( new YangInstanceIdentifier.NodeWithValue<>(name, o)).build(); } sealed = true; } }
@SuppressWarnings({ "unchecked" }) @Override public void leafSetEntryNode(QName name, Object value) throws IllegalArgumentException { checkNotSealed(); NormalizedNodeBuilderWrapper parent = stack.peek(); if (parent != null) { if (hasValidSchema(name, parent)) { parent.builder().addChild(Builders.leafSetEntryBuilder().withValue(value) .withNodeIdentifier(new YangInstanceIdentifier.NodeWithValue<>(parent.nodeType(), value)) .build()); } } else { // If there's no parent LeafSetNode then this is a stand alone // LeafSetEntryNode. if (nodePathSchemaNode != null) { this.normalizedNode = Builders.leafSetEntryBuilder().withValue(value).withNodeIdentifier( new YangInstanceIdentifier.NodeWithValue<>(name, value)).build(); } sealed = true; } }