@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("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(); }
/** * 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") protected void writeChild(final NormalizedNode<?, ?> child) { getCurrent().addChild(child); }
/** * 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") 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; }
static MapEntryNode entityEntryWithCandidateEntry(YangInstanceIdentifier entityId, String candidateName) { return ImmutableNodes.mapEntryBuilder(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).addChild( candidateEntry(candidateName)).build(); }
/** * 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(); }
@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(); }
@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 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; } }
static MapEntryNode entityEntryWithOwner(YangInstanceIdentifier entityId, String owner) { return ImmutableNodes.mapEntryBuilder(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).addChild( ImmutableNodes.leafNode(ENTITY_OWNER_QNAME, owner)).build(); }
/** * 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", "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") @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; } }
static MapNode candidateEntry(String candidateName) { return ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(Candidate.QNAME)). addChild(candidateMapEntry(candidateName)).build(); }
@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; } }