public static void check(final QName qName, final Optional<MapNode> actualNodes, final MapEntryNode listModification) throws DataModificationException { if (actualNodes.isPresent() && actualNodes.get().getChild(listModification.getIdentifier()).isPresent()) { throw new DataExistsException(qName, actualNodes.get(), listModification); } } }
writer.startMapNode(n.getIdentifier(), OrderedNormalizedNodeWriter.childSizeHint(n.getValue())); return writeChildren(n.getValue(), dataSchemaNode, true);
@Override protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) { return original instanceof MapNode ? ImmutableMapNodeBuilder.create() .withNodeIdentifier(((MapNode) original).getIdentifier()).build() : super.createEmptyValue(original); } }
writer.startMapNode(n.getIdentifier(), childSizeHint(n.getValue())); processedAsCompositeNode = writeChildren(n.getValue());
@Override protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) { if (original instanceof MapNode) { return ImmutableMapNodeBuilder.create().withNodeIdentifier(((MapNode) original).getIdentifier()).build(); } else if (original instanceof MapEntryNode) { return ImmutableMapEntryNodeBuilder.create().withNodeIdentifier( ((MapEntryNode) original).getIdentifier()).build(); } throw new IllegalArgumentException("MapModification strategy can only handle MapNode or MapEntryNode's, " + "offending node: " + original); }
writer.startMapNode(n.getIdentifier(), childSizeHint(n.getValue())); return writeChildren(n.getValue());
static void check(final QName nodeQName, final Optional<MapNode> actualNodes, final MapEntryNode modificationNode) throws DataModificationException { if (!actualNodes.isPresent() || !actualNodes.get().getChild(modificationNode.getIdentifier()).isPresent()) { throw new DataMissingException(nodeQName, modificationNode); } } }
private Map<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> mapEntries(MapNode mapNode) { Map<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> mapped = Maps.newLinkedHashMap(); for (MapEntryNode mapEntryNode : mapNode.getValue()) { mapped.put(mapEntryNode.getIdentifier(), mapEntryNode); } return mapped; }
writer.startMapNode(n.getIdentifier(), childSizeHint(n.getValue())); return writeChildren(n.getValue());
@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(); }
private Collection<String> getCandidateNames(MapEntryNode entity) { Collection<MapEntryNode> candidates = ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getValue(); Collection<String> candidateNames = new ArrayList<>(candidates.size()); for(MapEntryNode candidate: candidates) { candidateNames.add(candidate.getChild(CANDIDATE_NAME_NODE_ID).get().getValue().toString()); } return candidateNames; }
@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(); }
private void searchForEntities(EntityWalker walker) { Optional<NormalizedNode<?, ?>> possibleEntityTypes = getDataStore().readNode(ENTITY_TYPES_PATH); if(!possibleEntityTypes.isPresent()) { return; } for(MapEntryNode entityType: ((MapNode) possibleEntityTypes.get()).getValue()) { Optional<DataContainerChild<?, ?>> possibleEntities = entityType.getChild(ENTITY_NODE_ID); if(!possibleEntities.isPresent()) { // shouldn't happen but handle anyway continue; } for(MapEntryNode entity: ((MapNode) possibleEntities.get()).getValue()) { walker.onEntity(entityType, entity); } } }
private static boolean hasCandidate(MapEntryNode entity, MemberName candidateName) { return ((MapNode)entity.getChild(CANDIDATE_NODE_ID).get()).getChild(candidateNodeKey(candidateName.getName())) .isPresent(); }
@Override public Collection<NormalizedNodeUpdate> normalizedUpdates(@Nonnull final YangInstanceIdentifier topLevelIdentifier, @Nonnull final Map.Entry<YangInstanceIdentifier.PathArgument, DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> entry) { // identifier has different format : parent_node/list_node/list_node_with_key LOG.debug("Processing {} as list", topLevelIdentifier); return ((MapNode) entry.getValue()).getValue().stream() .map(mapEntryNode -> new NormalizedNodeUpdate(YangInstanceIdentifier.builder(topLevelIdentifier) .node(mapEntryNode.getNodeType()) .node(mapEntryNode.getIdentifier()).build(), mapEntryNode, null)) .collect(Collectors.toList()); } }
/** * Parse response of get(netconf-state/schemas) to find all schemas under netconf-state/schemas */ @VisibleForTesting protected static NetconfStateSchemas create(final RemoteDeviceId id, final ContainerNode schemasNode) { final Set<RemoteYangSchema> availableYangSchemas = Sets.newHashSet(); final Optional<DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> child = schemasNode.getChild(toId(Schema.QNAME)); Preconditions.checkState(child.isPresent(), "Unable to find list: %s in response: %s", Schema.QNAME.withoutRevision(), schemasNode); Preconditions.checkState(child.get() instanceof MapNode, "Unexpected structure for container: %s in response: %s. Expecting a list", Schema.QNAME.withoutRevision(), schemasNode); for (final MapEntryNode schemaNode : ((MapNode) child.get()).getValue()) { final Optional<RemoteYangSchema> fromCompositeNode = RemoteYangSchema.createFromNormalizedNode(id, schemaNode); if(fromCompositeNode.isPresent()) { availableYangSchemas.add(fromCompositeNode.get()); } } return new NetconfStateSchemas(availableYangSchemas); }
@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); }
@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); }