@Override public final PathArgument getIdentifier() { return data.getIdentifier(); }
private static Optional<String> getValueOfSimpleNode(final NormalizedNode<? extends YangInstanceIdentifier.PathArgument, ?> node) { final Object value = node.getValue(); return value == null || Strings.isNullOrEmpty(value.toString()) ? Optional.<String>absent() : Optional.of(value.toString().trim()); }
private void validateLeafRefNodeData(final NormalizedNode<?, ?> leaf, final LeafRefContext referencingCtx, final ModificationType modificationType, final YangInstanceIdentifier current) { final Set<Object> values = computeValues(root, createPath(referencingCtx.getAbsoluteLeafRefTargetPath()), current); if (values.contains(leaf.getValue())) { LOG.debug("Operation [{}] validate data of LEAFREF node: name[{}] = value[{}] {}", modificationType, referencingCtx.getNodeName(), leaf.getValue(), SUCCESS); return; } LOG.debug("Operation [{}] validate data of LEAFREF node: name[{}] = value[{}] {}", modificationType, referencingCtx.getNodeName(), leaf.getValue(), FAILED); LOG.debug("Invalid leafref value [{}] allowed values {} of LEAFREF node: {} leafRef target path: {}", leaf.getValue(), values, leaf.getNodeType(), referencingCtx.getAbsoluteLeafRefTargetPath()); errorsMessages.add(String.format("Invalid leafref value [%s] allowed values %s of LEAFREF node: %s leafRef " + "target path: %s", leaf.getValue(), values, leaf.getNodeType(), referencingCtx.getAbsoluteLeafRefTargetPath())); }
@Override public void visitNode(int level, String parentPath, NormalizedNode<?, ?> normalizedNode) { System.out.println(spaces((level) * 4) + normalizedNode.getClass().toString() + ":" + normalizedNode.getIdentifier()); if(normalizedNode instanceof LeafNode || normalizedNode instanceof LeafSetEntryNode){ System.out.println(spaces((level) * 4) + " parentPath = " + parentPath); System.out.println(spaces((level) * 4) + " key = " + normalizedNode.getClass().toString() + ":" + normalizedNode.getIdentifier()); System.out.println(spaces((level) * 4) + " value = " + normalizedNode.getValue()); } } }
@Override public boolean apply(final NormalizedNode<?, ?> input) { if (input instanceof AugmentationNode) { return true; } if (!qnames.contains(input.getNodeType())) { return true; } LOG.debug("Skipping key child {}", input); return false; } }));
private static void toStringTree(final StringBuilder builder, final NormalizedNode<?, ?> node, final int offset) { final String prefix = Strings.repeat(" ", offset); builder.append(prefix).append(toStringTree(node.getIdentifier())); if (node instanceof NormalizedNodeContainer<?, ?, ?>) { final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) node; builder.append(" {\n"); for (NormalizedNode<?, ?> child : container.getValue()) { toStringTree(builder, child, offset + STRINGTREE_INDENT); } builder.append(prefix).append('}'); } else { builder.append(' ').append(node.getValue()); } builder.append('\n'); }
private QName resolveQName(final NormalizedNode<?, ?> node, final String prefix, final String localName) { final QNameModule module; if (prefix.isEmpty()) { module = node.getNodeType().getModule(); } else { module = namespaceContext.convert(prefix); } return QName.create(module, localName); }
@Override public final PathArgument getIdentifier() { return data.getIdentifier(); }
@Override protected Object deserializeObject(final NormalizedNode<?, ?> normalizedNode) { if (normalizedNode instanceof AnyXmlNode) { return valueCodec.deserialize(normalizedNode.getValue()); } return null; }
private static void toStringTree(final StringBuilder builder, final NormalizedNode<?, ?> node, final int offset) { final String prefix = Strings.repeat(" ", offset); builder.append(prefix).append(toStringTree(node.getIdentifier())); if (node instanceof NormalizedNodeContainer<?, ?, ?>) { final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) node; builder.append(" {\n"); for (NormalizedNode<?, ?> child : container.getValue()) { toStringTree(builder, child, offset + STRINGTREE_INDENT); } builder.append(prefix).append('}'); } else { builder.append(' ').append(node.getValue()); } builder.append('\n'); }
private void validateLeafRefNodeData(final NormalizedNode<?, ?> leaf, final LeafRefContext referencingCtx, final ModificationType modificationType, final YangInstanceIdentifier current) { final Set<Object> values = computeValues(root, createPath(referencingCtx.getAbsoluteLeafRefTargetPath()), current); if (values.contains(leaf.getValue())) { LOG.debug("Operation [{}] validate data of LEAFREF node: name[{}] = value[{}] {}", modificationType, referencingCtx.getNodeName(), leaf.getValue(), SUCCESS); return; } LOG.debug("Operation [{}] validate data of LEAFREF node: name[{}] = value[{}] {}", modificationType, referencingCtx.getNodeName(), leaf.getValue(), FAILED); LOG.debug("Invalid leafref value [{}] allowed values {} of LEAFREF node: {} leafRef target path: {}", leaf.getValue(), values, leaf.getNodeType(), referencingCtx.getAbsoluteLeafRefTargetPath()); errorsMessages.add(String.format("Invalid leafref value [%s] allowed values %s of LEAFREF node: %s leafRef " + "target path: %s", leaf.getValue(), values, leaf.getNodeType(), referencingCtx.getAbsoluteLeafRefTargetPath())); }
private QName resolveQName(final NormalizedNode<?, ?> node, final String prefix, final String localName) { final QNameModule module; if (prefix.isEmpty()) { module = node.getNodeType().getModule(); } else { module = namespaceContext.convert(prefix); } return QName.create(module, localName); }
@Override @Nonnull public final PathArgument getIdentifier() { return data.getIdentifier(); }
public static RouteDistinguisher extractRouteDistinguisher(final DataContainerNode<?> route, final NodeIdentifier rdNid) { final NormalizedNode<?, ?> rdNode = NormalizedNodes.findNode(route, rdNid).orNull(); if (rdNode != null) { return parseRouteDistinguisher(rdNode.getValue()); } return null; } }
if (!validatedLeafRefCtx.add(referencedByCtx)) { LOG.trace("Operation [{}] validate data of leafref TARGET node: name[{}] = value[{}] -> SKIP: Already " + "validated", modificationType, referencedByCtx.getNodeName(), leaf.getValue()); return; referencedByCtx.getNodeName(), leaf.getValue()); final Set<LeafRefContext> leafRefs = referencedByCtx.getAllReferencedByLeafRefCtxs().values().stream() .filter(LeafRefContext::isReferencing).collect(Collectors.toSet()); leafRefTargetNodeValues, leaf.getNodeType(), leafRefContext.getCurrentNodePath(), leafRefContext.getAbsoluteLeafRefTargetPath(), FAILED); errorsMessages.add(String.format("Invalid leafref value [%s] allowed values %s by validation of leafref" + " TARGET node: %s path of invalid LEAFREF node: %s leafRef target path: %s %s", leafRefsValue, leafRefTargetNodeValues, leaf.getNodeType(), leafRefContext.getCurrentNodePath(), leafRefContext.getAbsoluteLeafRefTargetPath(), FAILED));
@Override public SchemaOrderedNormalizedNodeWriter write(final NormalizedNode<?, ?> node) throws IOException { if (Objects.equals(root, schemaContext)) { currentSchemaNode = schemaContext.getDataChildByName(node.getNodeType()); } else { currentSchemaNode = root; } return write(node, currentSchemaNode); }
@Nonnull @Override public PathArgument getIdentifier() { return data.getIdentifier(); }
@Override public String getElementStringValue(final Object element) { final NormalizedNode<?, ?> node = contextNode(element); if (node instanceof LeafNode || node instanceof LeafSetEntryNode) { final Object value = node.getValue(); // TODO: This is a rather poor approximation of what the codec infrastructure, but it should be sufficient // to work for now. Tracking SchemaPath will mean we will need to wrap each NormalizedNode with a // corresponding SchemaPath. That in turn would complicate this class and result in a lot of object // allocations. if (value instanceof byte[]) { // Binary return BaseEncoding.base64().encode((byte[]) value); } if (value instanceof Set) { // Bits return JOINER.join((Set<?>)value); } if (value != null) { // Everything else... return String.valueOf(value); } } return ""; }
if (!validatedLeafRefCtx.add(referencedByCtx)) { LOG.trace("Operation [{}] validate data of leafref TARGET node: name[{}] = value[{}] -> SKIP: Already " + "validated", modificationType, referencedByCtx.getNodeName(), leaf.getValue()); return; referencedByCtx.getNodeName(), leaf.getValue()); final Set<LeafRefContext> leafRefs = referencedByCtx.getAllReferencedByLeafRefCtxs().values().stream() .filter(LeafRefContext::isReferencing).collect(Collectors.toSet()); leafRefTargetNodeValues, leaf.getNodeType(), leafRefContext.getCurrentNodePath(), leafRefContext.getAbsoluteLeafRefTargetPath(), FAILED); errorsMessages.add(String.format("Invalid leafref value [%s] allowed values %s by validation of leafref" + " TARGET node: %s path of invalid LEAFREF node: %s leafRef target path: %s %s", leafRefsValue, leafRefTargetNodeValues, leaf.getNodeType(), leafRefContext.getCurrentNodePath(), leafRefContext.getAbsoluteLeafRefTargetPath(), FAILED));
@Override public SchemaOrderedNormalizedNodeWriter write(final NormalizedNode<?, ?> node) throws IOException { if (Objects.equals(root, schemaContext)) { currentSchemaNode = schemaContext.getDataChildByName(node.getNodeType()); } else { currentSchemaNode = root; } return write(node, currentSchemaNode); }