private Optional<? extends DataContainerChild<?, ?>> modifyContainerNode(final OperationStack operationStack, final N actual, final N modification, final YangInstanceIdentifier.PathArgument childToProcess, final Object schemaChild) throws DataModificationException { Optional<DataContainerChild<?, ?>> storedChildren = actual.getChild(childToProcess); Optional<DataContainerChild<?, ?>> modifiedChildren = modification.getChild(childToProcess); return NodeDispatcher.dispatchChildModification(schemaChild, storedChildren, modifiedChildren, operationStack); }
Optional<NormalizedNodeContext> findChild(final PathArgument arg) { return node instanceof DataContainerNode ? ((DataContainerNode<?>)node).getChild(arg).map(this::createChild) : Optional.empty(); }
Optional<NormalizedNodeContext> findChild(final PathArgument arg) { return node instanceof DataContainerNode ? ((DataContainerNode<?>)node).getChild(arg).map(this::createChild) : Optional.empty(); }
private static Optional<? extends NormalizedNode<?, ?>> findSchemasNode(final NormalizedNode<?, ?> result) { if(result == null) { return Optional.absent(); } final Optional<DataContainerChild<?, ?>> dataNode = ((DataContainerNode<?>) result).getChild(toId(NETCONF_DATA_QNAME)); if(dataNode.isPresent() == false) { return Optional.absent(); } final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> nStateNode = ((DataContainerNode<?>) dataNode.get()).getChild(toId(NetconfState.QNAME)); if(nStateNode.isPresent() == false) { return Optional.absent(); } return ((DataContainerNode<?>) nStateNode.get()).getChild(toId(Schemas.QNAME)); }
private static Optional<String> getSingleChildNodeValue(final DataContainerNode<?> schemaNode, final QName childNode) { final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> node = schemaNode.getChild(toId(childNode)); Preconditions.checkArgument(node.isPresent(), "Child node %s not present", childNode); return getValueOfSimpleNode(node.get()); }
/** * Extracts all values of a leaf-list node as a set of strings */ private static Set<String> getAllChildNodeValues(final DataContainerNode<?> schemaNode, final QName childNodeQName) { final Set<String> extractedValues = Sets.newHashSet(); final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> child = schemaNode.getChild(toId(childNodeQName)); Preconditions.checkArgument(child.isPresent(), "Child nodes %s not present", childNodeQName); Preconditions.checkArgument(child.get() instanceof LeafSetNode<?>, "Child nodes %s not present", childNodeQName); for (final LeafSetEntryNode<?> childNode : ((LeafSetNode<?>) child.get()).getValue()) { extractedValues.add(getValueOfSimpleNode(childNode).get()); } return extractedValues; }
@SuppressWarnings({ "unchecked", "rawtypes" }) public static Optional<NormalizedNode<?, ?>> getDirectChild(final NormalizedNode<?, ?> node, final PathArgument pathArg) { if (node instanceof LeafNode<?> || node instanceof LeafSetEntryNode<?>) { return Optional.empty(); } else if (node instanceof DataContainerNode<?>) { return (Optional) ((DataContainerNode<?>) node).getChild(pathArg); } else if (node instanceof MapNode && pathArg instanceof NodeIdentifierWithPredicates) { return (Optional) ((MapNode) node).getChild((NodeIdentifierWithPredicates) pathArg); } else if (node instanceof LeafSetNode<?> && pathArg instanceof NodeWithValue) { return (Optional) ((LeafSetNode<?>) node).getChild((NodeWithValue) pathArg); } return Optional.empty(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public static Optional<NormalizedNode<?, ?>> getDirectChild(final NormalizedNode<?, ?> node, final PathArgument pathArg) { if (node instanceof LeafNode<?> || node instanceof LeafSetEntryNode<?>) { return Optional.empty(); } else if (node instanceof DataContainerNode<?>) { return (Optional) ((DataContainerNode<?>) node).getChild(pathArg); } else if (node instanceof MapNode && pathArg instanceof NodeIdentifierWithPredicates) { return (Optional) ((MapNode) node).getChild((NodeIdentifierWithPredicates) pathArg); } else if (node instanceof LeafSetNode<?> && pathArg instanceof NodeWithValue) { return (Optional) ((LeafSetNode<?>) node).getChild((NodeWithValue) pathArg); } return Optional.empty(); }
static RouteDistinguisher extractRouteDistinguisher(final DataContainerNode<? extends PathArgument> evpn) { return RouteDistinguisherBuilder.getDefaultInstance((String) evpn.getChild(RD_NID).get().getValue()); }
static IpAddress extractOrigRouteIp(final DataContainerNode<? extends PathArgument> evpn) { return IpAddressBuilder.getDefaultInstance((String) evpn.getChild(ORI_NID).get().getValue()); }
static MacAddress extractMAC(final DataContainerNode<? extends PathArgument> evpn) { return new MacAddress((String) evpn.getChild(MAC_NID).get().getValue()); }
Optional<NormalizedNodeContext> findDescendant(final YangInstanceIdentifier path) { if (path.isEmpty()) { return Optional.of(this); } NormalizedNodeContext ctxWalk = this; NormalizedNode<?, ?> dataWalk = node; for (PathArgument arg : path.getPathArguments()) { checkArgument(dataWalk instanceof DataContainerNode, "Path %s refers beyond node %s", path, dataWalk); final Optional<DataContainerChild<? extends @Nullable PathArgument, ?>> optChild = ((DataContainerNode)dataWalk).getChild(arg); if (!optChild.isPresent()) { return Optional.empty(); } dataWalk = optChild.get(); ctxWalk = createChild(dataWalk); } return Optional.of(ctxWalk.createChild(dataWalk)); }
public final List<Flowspec> extractFlowspec(final DataContainerNode<?> route) { Preconditions.checkNotNull(route, "Cannot extract flowspec from null route."); final List<Flowspec> fsList = new ArrayList<>(); final Optional<DataContainerChild<? extends PathArgument, ?>> flowspecs = route.getChild(FLOWSPEC_NID); if (flowspecs.isPresent()) { for (final UnkeyedListEntryNode flowspec : ((UnkeyedListNode) flowspecs.get()).getValue()) { final FlowspecBuilder fsBuilder = new FlowspecBuilder(); final Optional<DataContainerChild<?, ?>> flowspecType = flowspec.getChild(FLOWSPEC_TYPE_NID); if (flowspecType.isPresent()) { final ChoiceNode fsType = (ChoiceNode) flowspecType.get(); processFlowspecType(fsType, fsBuilder); } fsList.add(fsBuilder.build()); } } return fsList; }
private void processChildNode(final Set<Object> values, final DataContainerNode<?> parent, final PathArgument arg, final List<QNamePredicate> nodePredicates, final Deque<QNameWithPredicate> path, final YangInstanceIdentifier current) { final Optional<DataContainerChild<?, ?>> child = parent.getChild(arg); if (!child.isPresent()) { // FIXME: YANGTOOLS-901. We have SchemaContext nearby, hence we should be able to cache how to get // to the leaf with with specified QName, without having to iterate through Choices/Augmentations. // That perhaps means we should not have QNameWithPredicates, but NodeIdentifierWithPredicates as // the path specification. for (final DataContainerChild<?, ?> mixin : parent.getValue()) { if (mixin instanceof AugmentationNode || mixin instanceof ChoiceNode) { addValues(values, mixin, nodePredicates, path, current); } } } else { addNextValues(values, child.get(), nodePredicates, path, current); } }
@Nullable Iterator<NormalizedNodeContext> iterateChildrenNamed(final DataContainerNode<?> data, final QName qname) { final NodeIdentifier arg = new NodeIdentifier(qname); final Optional<DataContainerChild<? extends @Nullable PathArgument, ?>> maybeChild = data.getChild(arg); if (!maybeChild.isPresent()) { return null; } final NormalizedNode<?, ?> child = maybeChild.get(); final Collection<? extends NormalizedNode<?, ?>> collection; // The child may be a structural node if (child instanceof MapNode) { collection = ((MapNode)child).getValue(); } else if (child instanceof LeafSetNode) { collection = ((LeafSetNode<?>)child).getValue(); } else { return Iterators.singletonIterator(createChild(child)); } return Iterators.transform(collection.iterator(), this::createChild); }
private static void serializeCommonParts(final CLinkstateDestinationBuilder builder, final DataContainerNode<? extends PathArgument> linkstate) { // serialize common parts final Optional<DataContainerChild<? extends PathArgument, ?>> distinguisher = linkstate.getChild(DISTINGUISHER_NID); if (distinguisher.isPresent()) { builder.setDistinguisher(new RouteDistinguisher((BigInteger) distinguisher.get().getValue())); } final Optional<DataContainerChild<? extends PathArgument, ?>> protocolId = linkstate.getChild(PROTOCOL_ID_NID); // DOM representation contains values as are in the model, not as are in generated enum if (protocolId.isPresent()) { builder.setProtocolId(ProtocolId.forValue(domProtocolIdValue((String) protocolId.get().getValue()))); } final Optional<DataContainerChild<? extends PathArgument, ?>> identifier = linkstate.getChild(IDENTIFIER_NID); if (identifier.isPresent()) { builder.setIdentifier(new Identifier((BigInteger) identifier.get().getValue())); } } }
private static EvpnDestination extractDestination(final DataContainerNode<? extends PathArgument> evpnChoice, final ExtractionInterface extract) { final EvpnRegistry reg = SimpleEvpnNlriRegistry.getInstance(); final ChoiceNode cont = (ChoiceNode) evpnChoice.getChild(EVPN_CHOICE_NID).get(); final EvpnChoice evpnValue = extract.check(reg, cont); if (evpnValue == null) { LOG.warn("Unrecognized Nlri {}", cont); return null; } return new EvpnDestinationBuilder().setRouteDistinguisher(extractRouteDistinguisher(evpnChoice)).setEvpnChoice(evpnValue).build(); }
public static CLinkstateDestination extractLinkstateDestination(final DataContainerNode<? extends PathArgument> linkstate) { final CLinkstateDestinationBuilder builder = new CLinkstateDestinationBuilder(); serializeCommonParts(builder, linkstate); final ChoiceNode objectType = (ChoiceNode) linkstate.getChild(OBJECT_TYPE_NID).get(); if (objectType.getChild(ADVERTISING_NODE_DESCRIPTORS_NID).isPresent()) { serializeAdvertisedNodeDescriptor(builder, objectType); } else if (objectType.getChild(LOCAL_NODE_DESCRIPTORS_NID).isPresent()) { serializeLocalNodeDescriptor(builder, objectType); } else if (objectType.getChild(NODE_DESCRIPTORS_NID).isPresent()) { serializeNodeDescriptor(builder, objectType); } else if (AbstractTeLspNlriCodec.isTeLsp(objectType)) { builder.setObjectType(AbstractTeLspNlriCodec.serializeTeLsp(objectType)); } else { LOG.warn("Unknown Object Type: {}.", objectType); } return builder.build(); }