private NormalizedNode<?, ?> buildListNode( final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder, final NormalizedNodeMessages.Node node) { builder.withNodeIdentifier(toNodeIdentifier(node.getPathArgument())); for(NormalizedNodeMessages.Node child : node.getChildList()){ builder.withChild((LeafSetEntryNode<Object>) deSerialize(child)); } return builder.build(); }
private static void addOtherClusterEntries(final Optional<NormalizedNode<?, ?>> maybeClusterList, final ListNodeBuilder<Object, LeafSetEntryNode<Object>> clb) { final NormalizedNode<?, ?> clusterList = maybeClusterList.get(); if (clusterList instanceof LeafSetNode) { for (final LeafSetEntryNode<?> n : ((LeafSetNode<?>) clusterList).getValue()) { // There's no way we can safely avoid this cast @SuppressWarnings("unchecked") final LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>) n; clb.addChild(child); } } else { LOG.warn("Ignoring malformed CLUSTER_LIST {}", clusterList); } }
@Override public void leafSetEntryNode(final QName name, final Object value) { if (getCurrent() instanceof ImmutableOrderedLeafSetNodeBuilder) { @SuppressWarnings("unchecked") ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = (ImmutableOrderedLeafSetNodeBuilder<Object>) getCurrent(); builder.withChildValue(value); } else if (getCurrent() instanceof ImmutableLeafSetNodeBuilder) { @SuppressWarnings("unchecked") ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = (ImmutableLeafSetNodeBuilder<Object>) getCurrent(); builder.withChildValue(value); } else { throw new IllegalArgumentException("LeafSetEntryNode is not valid for parent " + getCurrent()); } nextSchema = null; }
private Optional<LeafSetNode<?>> build(LeafListSchemaNode schemaNode, List<LeafSetEntryNode<?>> resultNodes) { if(resultNodes.isEmpty()) { return Optional.absent(); } ListNodeBuilder<Object, LeafSetEntryNode<Object>> b = Builders.leafSetBuilder(schemaNode); for (LeafSetEntryNode<?> resultNode : resultNodes) { // FIXME: can we do something about this SuppressWarnings? @SuppressWarnings("unchecked") final LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>) resultNode; b.withChild(child); } return Optional.<LeafSetNode<?>>of(b.build()); }
@Override protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) { checkArgument(original instanceof LeafSetNode<?>); return ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(((LeafSetNode<?>) original).getIdentifier()) .build(); } }
asSequenceBuilder.withNodeIdentifier(this.asPathSequence).addChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue(this.asNumberQname, localAs)).withValue(localAs).build()); asSequenceBuilder.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue(this.asNumberQname, child.getValue())).withValue(child.getValue()).build()); segmentsBuilder.withChild(Builders.unkeyedListEntryBuilder().withNodeIdentifier(this.asPathSegments).withChild(asSequenceBuilder.build()).build()); Builders.orderedLeafSetBuilder().withNodeIdentifier(this.asPathSequence).addChild( Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue(this.asNumberQname, localAs)).withValue(localAs).build()).build()).build());
@Override ListNodeBuilder<?, ?> createBuilder(final PathArgument compositeNode) { return Builders.leafSetBuilder().withNodeIdentifier(getIdentifier()); }
private MapEntryNode toMapEntryNode(TestResult testResult) { YangInstanceIdentifier testResultId = YangInstanceIdentifier.builder().node(TEST_RESULTS_QNAME).node(TEST_RESULT_QNAME).build(); // Construct results list LinkedList<LeafSetEntryNode<Object>> entryList = new LinkedList<>(); for (String result : testResult.getResults()) { LeafSetEntryNode<Object> leafSetEntryNode = ImmutableLeafSetEntryNodeBuilder.create() .withNodeIdentifier(new NodeWithValue(RESULTS_QNAME, result)) .withValue(result) .build(); entryList.add(leafSetEntryNode); } // Construct results LeafSetNode LeafSetNode<?> resultsNode = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(RESULTS_QNAME)).withValue(entryList).build(); // Construct test result ContainerNode with 2 children - test-identifier leaf and results leaf-set MapEntryNode testResultNode = ImmutableNodes.mapEntryBuilder() .withNodeIdentifier(new NodeIdentifierWithPredicates(TEST_RESULT_QNAME, TEST_ID_QNAME, testResult.getTestIdentifier())) .withChild(ImmutableNodes.leafNode(TEST_ID_QNAME, testResult.getTestIdentifier())) .withChild(resultsNode) .build(); return(testResultNode); }
@SuppressWarnings("unchecked") private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(final QName nodeType, final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder) throws IOException { LOG.trace("Reading children of leaf set"); lastLeafSetQName = nodeType; LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); while (child != null) { builder.withChild(child); child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); } return builder; }
@Override protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) { checkArgument(original instanceof OrderedLeafSetNode<?>); return ImmutableOrderedLeafSetNodeBuilder.create() .withNodeIdentifier(((OrderedLeafSetNode<?>) original).getIdentifier()).build(); }
@Override ListNodeBuilder<?, ?> createBuilder(final PathArgument compositeNode) { return Builders.leafSetBuilder().withNodeIdentifier(getIdentifier()); }
.leafSetBuilder((LeafListSchemaNode) featureSchemaNode); for (final FeatureDefinition feature : module.getFeatures()) { featuresBuilder.withChild(Builders.leafSetEntryBuilder(((LeafListSchemaNode) featureSchemaNode)) .withValue(feature.getQName().getLocalName()).build()); moduleNodeValues.withChild(featuresBuilder.build());
@SuppressWarnings("unchecked") private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(final QName nodeType, final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder) throws IOException { LOG.debug("Reading children of leaf set"); lastLeafSetQName = nodeType; LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); while(child != null) { builder.withChild(child); child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal(); } return builder; }
ContainerNode reflectedAttributes(final ContainerNode attributes, final Ipv4Address originatorId, final ClusterIdentifier clusterId) { final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> attributesContainer = Builders.containerBuilder(attributes); // Create a new CLUSTER_LIST builder final ListNodeBuilder<Object, LeafSetEntryNode<Object>> clusterBuilder = Builders.orderedLeafSetBuilder(); clusterBuilder.withNodeIdentifier(this.clusterListLeaf); // prepend local CLUSTER_ID clusterBuilder.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(new NodeWithValue(this.clusterQname, clusterId.getValue())). withValue(clusterId.getValue()).build()); // if there was a CLUSTER_LIST attribute, add all other entries final Optional<NormalizedNode<?, ?>> maybeClusterList = NormalizedNodes.findNode(attributes, this.clusterListPath); if (maybeClusterList.isPresent()) { AttributeOperations.addOtherClusterEntries(maybeClusterList, clusterBuilder); } else { LOG.debug("Creating fresh CLUSTER_LIST attribute"); } // Now wrap it in a container and add it to attributes final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> clusterListCont = Builders.containerBuilder(); clusterListCont.withNodeIdentifier(this.clusterListContainer); clusterListCont.withChild(clusterBuilder.build()); attributesContainer.withChild(clusterListCont.build()); // add ORIGINATOR_ID if not present final Optional<NormalizedNode<?, ?>> maybeOriginatorId = NormalizedNodes.findNode(attributes, this.originatorIdPath); if (!maybeOriginatorId.isPresent()) { final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> originatorIDBuilder = Builders.containerBuilder(); originatorIDBuilder.withNodeIdentifier(this.originatorIdContainer); originatorIDBuilder.withChild(ImmutableNodes.leafNode(this.originatorIdLeaf, originatorId.getValue())); attributesContainer.withChild(originatorIDBuilder.build()); } return attributesContainer.build(); }
@Override public NormalizedNode<?, ?> createDefault(final PathArgument currentArg) { return Builders.leafSetBuilder().withNodeIdentifier(getIdentifier()).build(); }
@Override ListNodeBuilder<?, ?> createBuilder(final PathArgument compositeNode) { return Builders.orderedLeafSetBuilder().withNodeIdentifier(getIdentifier()); } }
@Override public void leafSetEntryNode(final QName name, final Object value) { if (getCurrent() instanceof ImmutableOrderedLeafSetNodeBuilder) { @SuppressWarnings("unchecked") ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = (ImmutableOrderedLeafSetNodeBuilder<Object>) getCurrent(); builder.withChildValue(value); } else if (getCurrent() instanceof ImmutableLeafSetNodeBuilder) { @SuppressWarnings("unchecked") ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder = (ImmutableLeafSetNodeBuilder<Object>) getCurrent(); builder.withChildValue(value); } else { throw new IllegalArgumentException("LeafSetEntryNode is not valid for parent " + getCurrent()); } nextSchema = null; }
@Test public void testLeafSetEntryNodeNotPrunedWhenHasParent() throws IOException { NormalizedNodePruner pruner = prunerFullSchema(TestModel.TEST_PATH.node(TestModel.SHOE_QNAME)); LeafSetEntryNode<Object> child = Builders.leafSetEntryBuilder().withValue("puma").withNodeIdentifier( new NodeWithValue<>(TestModel.SHOE_QNAME, "puma")).build(); NormalizedNode<?, ?> input = Builders.leafSetBuilder().withNodeIdentifier( new NodeIdentifier(TestModel.SHOE_QNAME)).withChild(child).build(); NormalizedNodeWriter.forStreamWriter(pruner).write(input); NormalizedNode<?, ?> actual = pruner.normalizedNode(); assertEquals("normalizedNode", input, actual); }
@Override protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) { checkArgument(original instanceof OrderedLeafSetNode<?>); return ImmutableOrderedLeafSetNodeBuilder.create() .withNodeIdentifier(((OrderedLeafSetNode<?>) original).getIdentifier()).build(); } }
@Override ListNodeBuilder<?, ?> createBuilder(final PathArgument compositeNode) { return Builders.orderedLeafSetBuilder().withNodeIdentifier(getIdentifier()); } }