@Override public Esi parseEsiModel(final ChoiceNode esiChoice) { Preconditions.checkArgument(esiChoice != null && !esiChoice.getValue().isEmpty(), "ESI is mandatory. Can't be null or empty."); final ContainerNode cont = (ContainerNode) Iterables.getOnlyElement(esiChoice.getValue()); final EsiSerializer serializer = this.modelHandlers.get(cont.getIdentifier()); if (serializer != null) { return serializer.serializeEsi(cont); } LOG.warn("Unrecognized ESI {}", esiChoice); return null; }
private EvpnChoice getEvpnCase(final ChoiceNode evpnChoice, final SerializerInterface serializerInterface) { Preconditions.checkArgument(evpnChoice != null && !evpnChoice.getValue().isEmpty(), "Evpn case is mandatory. Can't be null or empty."); final ContainerNode cont = (ContainerNode) Iterables.getOnlyElement(evpnChoice.getValue()); final EvpnSerializer serializer = this.modelHandlers.get(cont.getIdentifier()); if (serializer == null) { return null; } return serializerInterface.check(serializer, cont); } }
@SuppressWarnings("unchecked") @Override public D deserialize(final NormalizedNode<?, ?> data) { checkArgument(data instanceof ChoiceNode); final ChoiceNode casted = (ChoiceNode) data; final NormalizedNode<?, ?> first = Iterables.getFirst(casted.getValue(), null); if (first == null) { // FIXME: this needs to be sorted out return null; } final DataContainerCodecPrototype<?> caze = byYangCaseChild.get(first.getIdentifier()); return (D) caze.get().deserialize(data); }
private void enforceCases(final NormalizedNode<?, ?> normalizedNode) { Verify.verify(normalizedNode instanceof ChoiceNode); final Collection<DataContainerChild<?, ?>> children = ((ChoiceNode) normalizedNode).getValue(); if (!children.isEmpty()) { final DataContainerChild<?, ?> firstChild = children.iterator().next(); final CaseEnforcer enforcer = Verify.verifyNotNull(caseEnforcers.get(firstChild.getIdentifier()), "Case enforcer cannot be null. Most probably, child node %s of choice node %s does not belong " + "in current tree type.", firstChild.getIdentifier(), normalizedNode.getIdentifier()); // Make sure no leaves from other cases are present for (final CaseEnforcer other : exclusions.get(enforcer)) { for (final PathArgument id : other.getAllChildIdentifiers()) { final Optional<NormalizedNode<?, ?>> maybeChild = NormalizedNodes.getDirectChild(normalizedNode, id); Preconditions.checkArgument(!maybeChild.isPresent(), "Child %s (from case %s) implies non-presence of child %s (from case %s), which is %s", firstChild.getIdentifier(), enforcer, id, other, maybeChild.orElse(null)); } } // Make sure all mandatory children are present enforcer.enforceOnTreeNode(normalizedNode); } }
private void enforceCases(final NormalizedNode<?, ?> normalizedNode) { Verify.verify(normalizedNode instanceof ChoiceNode); final Collection<DataContainerChild<?, ?>> children = ((ChoiceNode) normalizedNode).getValue(); if (!children.isEmpty()) { final DataContainerChild<?, ?> firstChild = children.iterator().next(); final CaseEnforcer enforcer = Verify.verifyNotNull(caseEnforcers.get(firstChild.getIdentifier()), "Case enforcer cannot be null. Most probably, child node %s of choice node %s does not belong " + "in current tree type.", firstChild.getIdentifier(), normalizedNode.getIdentifier()); // Make sure no leaves from other cases are present for (final CaseEnforcer other : exclusions.get(enforcer)) { for (final PathArgument id : other.getAllChildIdentifiers()) { final Optional<NormalizedNode<?, ?>> maybeChild = NormalizedNodes.getDirectChild(normalizedNode, id); Preconditions.checkArgument(!maybeChild.isPresent(), "Child %s (from case %s) implies non-presence of child %s (from case %s), which is %s", firstChild.getIdentifier(), enforcer, id, other, maybeChild.orElse(null)); } } // Make sure all mandatory children are present enforcer.enforceOnTreeNode(normalizedNode); } }
for (DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> child : modification.get().getValue()) { Optional<ChoiceCaseNode> detectedCaseForChild = SchemaUtils.detectCase(schema, child);
private void validateChoiceNodeData(final ChoiceNode node, final LeafRefContext referencedByCtx, final LeafRefContext referencingCtx, final ModificationType modificationType, final YangInstanceIdentifier current) { for (final DataContainerChild<?, ?> child : node.getValue()) { final QName qname = child.getNodeType(); final LeafRefContext childReferencedByCtx = referencedByCtx == null ? null : findReferencedByCtxUnderChoice(referencedByCtx, qname); final LeafRefContext childReferencingCtx = referencingCtx == null ? null : findReferencingCtxUnderChoice(referencingCtx, qname); if (childReferencedByCtx != null || childReferencingCtx != null) { validateNodeData(child, childReferencedByCtx, childReferencingCtx, modificationType, current.node(child.getIdentifier())); } } }
private void validateChoiceNodeData(final ChoiceNode node, final LeafRefContext referencedByCtx, final LeafRefContext referencingCtx, final ModificationType modificationType, final YangInstanceIdentifier current) { for (final DataContainerChild<?, ?> child : node.getValue()) { final QName qname = child.getNodeType(); final LeafRefContext childReferencedByCtx = referencedByCtx == null ? null : findReferencedByCtxUnderChoice(referencedByCtx, qname); final LeafRefContext childReferencingCtx = referencingCtx == null ? null : findReferencingCtxUnderChoice(referencingCtx, qname); if (childReferencedByCtx != null || childReferencingCtx != null) { validateNodeData(child, childReferencedByCtx, childReferencingCtx, modificationType, current.node(child.getIdentifier())); } } }