((SchemaNode) schemaNode).getQName().equals(identifier.getNodeType())) { found = schemaNode; } else { found = ((DataNodeContainer) schemaNode).getDataChildByName(identifier.getNodeType()); .filter(child -> child.getQName().equals(identifier.getNodeType())) .findFirst(); if (maybeChild.isPresent()) { ((SchemaNode) schemaNode).getQName().equals(identifier.getNodeType())) { found = schemaNode;
@Override public int compareTo(final DOMDataTreeIdentifier domDataTreeIdentifier) { int cmp = datastoreType.compareTo(domDataTreeIdentifier.datastoreType); if (cmp != 0) { return cmp; } final Iterator<PathArgument> myIter = rootIdentifier.getPathArguments().iterator(); final Iterator<PathArgument> otherIter = domDataTreeIdentifier.rootIdentifier.getPathArguments().iterator(); while (myIter.hasNext()) { if (!otherIter.hasNext()) { return 1; } final PathArgument myPathArg = myIter.next(); final PathArgument otherPathArg = otherIter.next(); cmp = myPathArg.compareTo(otherPathArg); if (cmp != 0) { return cmp; } } return otherIter.hasNext() ? -1 : 0; }
@Override public final String toString() { /* * The toStringCache is safe, since the object contract requires * immutability of the object and all objects referenced from this * object. * Used lists, maps are immutable. Path Arguments (elements) are also * immutable, since the PathArgument contract requires immutability. * The cache is thread-safe - if multiple computations occurs at the * same time, cache will be overwritten with same result. */ String ret = toStringCache; if (ret == null) { final StringBuilder builder = new StringBuilder("/"); PathArgument prev = null; for (PathArgument argument : getPathArguments()) { if (prev != null) { builder.append('/'); } builder.append(argument.toRelativeString(prev)); prev = argument; } ret = builder.toString(); TOSTRINGCACHE_UPDATER.lazySet(this, ret); } return ret; }
final QName qname = arg.getNodeType(); sb.append('/'); appendQName(sb, qname, lastModule);
writeIdentifierWithNamespacePrefix(element, textContent, pathArgument.getNodeType(), prefixes); if (pathArgument instanceof NodeIdentifierWithPredicates) { final Map<QName, Object> predicates = ((NodeIdentifierWithPredicates) pathArgument).getKeyValues();
final QName qname = arg.getNodeType(); sb.append('/'); appendQName(sb, qname, lastModule);
if (it.hasNext()) { topLevelElement = it.next(); final DataSchemaNode dataChildByName = ctx.getDataChildByName(topLevelElement.getNodeType()); checkNotNull(dataChildByName, "Cannot find %s node in schema context. Instance identifier has to start from root", topLevelElement); instanceIdToNodes = InstanceIdToNodes.fromSchemaAndQNameChecked(ctx, topLevelElement.getNodeType()); } else { topLevelElement = SCHEMACONTEXT_NAME;
@Override @SuppressWarnings("unchecked") final NormalizedNode<?, ?> create(final PathArgument first, final Iterator<PathArgument> others, final Optional<NormalizedNode<?, ?>> lastChild, final Optional<Entry<QName, ModifyAction>> operation) { if (!isMixin()) { final QName type = getIdentifier().getNodeType(); if (type != null) { final QName firstType = first.getNodeType(); checkArgument(type.equals(firstType), "Node QName must be %s was %s", type, firstType); } } @SuppressWarnings("rawtypes") final NormalizedNodeContainerBuilder builder = createBuilder(first); if (others.hasNext()) { final PathArgument childPath = others.next(); final InstanceIdToNodes<?> childOp = getChildOperation(childPath); builder.addChild(childOp.create(childPath, others, lastChild, operation)); } else { if (lastChild.isPresent()) { builder.withValue(ImmutableList.copyOf((Collection<?>) lastChild.get().getValue())); } if (operation.isPresent()) { checkArgument(builder instanceof AttributesBuilder<?>); addModifyOpIfPresent(operation, (AttributesBuilder<?>) builder); } } return builder.build(); }
private YangInstanceIdentifier checkConsistencyOfNormalizedNodeContext(final NormalizedNodeContext payload) { Preconditions.checkArgument(payload != null); Preconditions.checkArgument(payload.getData() != null); Preconditions.checkArgument(payload.getData().getNodeType() != null); Preconditions.checkArgument(payload.getInstanceIdentifierContext() != null); Preconditions.checkArgument(payload.getInstanceIdentifierContext().getInstanceIdentifier() != null); final QName payloadNodeQname = payload.getData().getNodeType(); final YangInstanceIdentifier yangIdent = payload.getInstanceIdentifierContext().getInstanceIdentifier(); if (payloadNodeQname.compareTo(yangIdent.getLastPathArgument().getNodeType()) > 0) { return yangIdent; } final InstanceIdentifierContext<?> parentContext = payload.getInstanceIdentifierContext(); final SchemaNode parentSchemaNode = parentContext.getSchemaNode(); if(parentSchemaNode instanceof DataNodeContainer) { final DataNodeContainer cast = (DataNodeContainer) parentSchemaNode; for (final DataSchemaNode child : cast.getChildNodes()) { if (payloadNodeQname.compareTo(child.getQName()) == 0) { return YangInstanceIdentifier.builder(yangIdent).node(child.getQName()).build(); } } } if (parentSchemaNode instanceof RpcDefinition) { return yangIdent; } final String errMsg = "Error parsing input: DataSchemaNode has not children "; LOG.info(errMsg + yangIdent); throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE); }
if (it.hasNext()) { topLevelElement = it.next(); final DataSchemaNode dataChildByName = ctx.getDataChildByName(topLevelElement.getNodeType()); checkNotNull(dataChildByName, "Cannot find %s node in schema context. Instance identifier has to start from root", topLevelElement); instanceIdToNodes = InstanceIdToNodes.fromSchemaAndQNameChecked(ctx, topLevelElement.getNodeType()); } else { topLevelElement = SCHEMACONTEXT_NAME;
private static NormalizedNodeMessages.InstanceIdentifier.Builder toSerializableBuilder( YangInstanceIdentifier path, QNameSerializationContext context) { NormalizedNodeMessages.InstanceIdentifier.Builder builder = NormalizedNodeMessages.InstanceIdentifier.newBuilder(); try { for (PathArgument pathArgument : path.getPathArguments()) { NormalizedNodeMessages.PathArgument serializablePathArgument; if(context == null) { String nodeType = ""; if (!(pathArgument instanceof AugmentationIdentifier)) { nodeType = pathArgument.getNodeType().toString(); } serializablePathArgument = NormalizedNodeMessages.PathArgument.newBuilder() .setValue(pathArgument.toString()) .setType(pathArgument.getClass().getSimpleName()) .setNodeType(NormalizedNodeMessages.QName.newBuilder().setValue(nodeType)) .addAllAttributes(getPathArgumentAttributes(pathArgument)).build(); } else { serializablePathArgument = PathArgumentSerializer.serialize(context, pathArgument); } builder.addArguments(serializablePathArgument); } } catch(Exception e){ logger.error("An exception occurred", e); } return builder; }
public String toFullRestconfIdentifier(final YangInstanceIdentifier path, final DOMMountPoint mount) { checkPreconditions(); final Iterable<PathArgument> elements = path.getPathArguments(); final StringBuilder builder = new StringBuilder(); final PathArgument head = elements.iterator().next(); final QName startQName = head.getNodeType(); final SchemaContext schemaContext; if (mount != null) { schemaContext = mount.getSchemaContext(); } else { schemaContext = globalSchema; } final Module initialModule = schemaContext.findModuleByNamespaceAndRevision(startQName.getNamespace(), startQName.getRevision()); DataNodeContainer node = initialModule; for (final PathArgument element : elements) { if (!(element instanceof AugmentationIdentifier)) { final QName _nodeType = element.getNodeType(); final DataSchemaNode potentialNode = ControllerContext.childByQName(node, _nodeType); if (!(element instanceof NodeIdentifier && potentialNode instanceof ListSchemaNode) && !(potentialNode instanceof ChoiceSchemaNode)) { builder.append(convertToRestconfIdentifier(element, potentialNode, mount)); if (potentialNode instanceof DataNodeContainer) { node = (DataNodeContainer) potentialNode; } } } } return builder.toString(); }
private void validateChildren(final LeafRefContext rootLeafRefCtx, final Collection<DataTreeCandidateNode> children) throws LeafRefDataValidationFailedException { for (final DataTreeCandidateNode dataTreeCandidateNode : children) { if (dataTreeCandidateNode.getModificationType() != ModificationType.UNMODIFIED) { final PathArgument identifier = dataTreeCandidateNode.getIdentifier(); final QName childQName = identifier.getNodeType(); final LeafRefContext referencedByCtx = rootLeafRefCtx.getReferencedChildByName(childQName); final LeafRefContext referencingCtx = rootLeafRefCtx.getReferencingChildByName(childQName); if (referencedByCtx != null || referencingCtx != null) { validateNode(dataTreeCandidateNode, referencedByCtx, referencingCtx, YangInstanceIdentifier.create(identifier)); } } } if (!errorsMessages.isEmpty()) { final StringBuilder message = new StringBuilder(); int errCount = 0; for (final String errorMessage : errorsMessages) { message.append(errorMessage); errCount++; } throw new LeafRefDataValidationFailedException(message.toString(), errCount); } }
@Override @SuppressWarnings("unchecked") final NormalizedNode<?, ?> create(final PathArgument first, final Iterator<PathArgument> others, final Optional<NormalizedNode<?, ?>> lastChild, final Optional<Entry<QName, ModifyAction>> operation) { if (!isMixin()) { final QName type = getIdentifier().getNodeType(); if (type != null) { final QName firstType = first.getNodeType(); checkArgument(type.equals(firstType), "Node QName must be %s was %s", type, firstType); } } @SuppressWarnings("rawtypes") final NormalizedNodeContainerBuilder builder = createBuilder(first); if (others.hasNext()) { final PathArgument childPath = others.next(); final InstanceIdToNodes<?> childOp = getChildOperation(childPath); builder.addChild(childOp.create(childPath, others, lastChild, operation)); } else { if (lastChild.isPresent()) { builder.withValue(ImmutableList.copyOf((Collection<?>) lastChild.get().getValue())); } if (operation.isPresent()) { checkArgument(builder instanceof AttributesBuilder<?>); addModifyOpIfPresent(operation, (AttributesBuilder<?>) builder); } } return builder.build(); }
private void validateChildren(final LeafRefContext rootLeafRefCtx, final Collection<DataTreeCandidateNode> children) throws LeafRefDataValidationFailedException { for (final DataTreeCandidateNode dataTreeCandidateNode : children) { if (dataTreeCandidateNode.getModificationType() != ModificationType.UNMODIFIED) { final PathArgument identifier = dataTreeCandidateNode.getIdentifier(); final QName childQName = identifier.getNodeType(); final LeafRefContext referencedByCtx = rootLeafRefCtx.getReferencedChildByName(childQName); final LeafRefContext referencingCtx = rootLeafRefCtx.getReferencingChildByName(childQName); if (referencedByCtx != null || referencingCtx != null) { validateNode(dataTreeCandidateNode, referencedByCtx, referencingCtx, YangInstanceIdentifier.create(identifier)); } } } if (!errorsMessages.isEmpty()) { final StringBuilder message = new StringBuilder(); int errCount = 0; for (final String errorMessage : errorsMessages) { message.append(errorMessage); errCount++; } throw new LeafRefDataValidationFailedException(message.toString(), errCount); } }
/** * Return a collection children which match a {@link PathArgument} specification inexactly. * This explicitly excludes the child returned by {@link #getExactChild(PathArgument)}. * * @param arg Child identifier * @return Collection of children, guaranteed to be non-null. */ public @NonNull Collection<RegistrationTreeNode<T>> getInexactChildren(final @NonNull PathArgument arg) { requireNonNull(arg); if (arg instanceof NodeWithValue || arg instanceof NodeIdentifierWithPredicates) { /* * TODO: This just all-or-nothing wildcards, which we have historically supported. Given * that the argument is supposed to have all the elements filled out, we could support * partial wildcards by iterating over the registrations and matching the maps for * partial matches. */ final RegistrationTreeNode<T> child = children.get(new NodeIdentifier(arg.getNodeType())); if (child == null) { return Collections.emptyList(); } return Collections.singletonList(child); } return Collections.emptyList(); }
@Override public final String toString() { /* * The toStringCache is safe, since the object contract requires * immutability of the object and all objects referenced from this * object. * Used lists, maps are immutable. Path Arguments (elements) are also * immutable, since the PathArgument contract requires immutability. * The cache is thread-safe - if multiple computations occurs at the * same time, cache will be overwritten with same result. */ String ret = toStringCache; if (ret == null) { final StringBuilder builder = new StringBuilder("/"); PathArgument prev = null; for (PathArgument argument : getPathArguments()) { if (prev != null) { builder.append('/'); } builder.append(argument.toRelativeString(prev)); prev = argument; } ret = builder.toString(); TOSTRINGCACHE_UPDATER.lazySet(this, ret); } return ret; }
/** * Return a collection children which match a {@link PathArgument} specification inexactly. * This explicitly excludes the child returned by {@link #getExactChild(PathArgument)}. * * @param arg Child identifier * @return Collection of children, guaranteed to be non-null. */ public @Nonnull Collection<RegistrationTreeNode<T>> getInexactChildren(@Nonnull final PathArgument arg) { Preconditions.checkNotNull(arg); if (arg instanceof NodeWithValue || arg instanceof NodeIdentifierWithPredicates) { /* * TODO: This just all-or-nothing wildcards, which we have historically supported. Given * that the argument is supposed to have all the elements filled out, we could support * partial wildcards by iterating over the registrations and matching the maps for * partial matches. */ final RegistrationTreeNode<T> child = children.get(new NodeIdentifier(arg.getNodeType())); if (child == null) { return Collections.emptyList(); } else { return Collections.singletonList(child); } } else { return Collections.emptyList(); } }
private SchemaNode getSchema(final PathArgument name) { final Object parent = getParent(); SchemaNode schema = null; final QName qname = name.getNodeType(); if (parent instanceof DataNodeContainer) { schema = ((DataNodeContainer)parent).getDataChildByName(qname); if (schema == null) { if (parent instanceof GroupingDefinition) { schema = (GroupingDefinition) parent; } else if (parent instanceof NotificationDefinition) { schema = (NotificationDefinition) parent; } } } else if (parent instanceof ChoiceSchemaNode) { schema = findChildInCases((ChoiceSchemaNode) parent, qname); } else { throw new IllegalStateException("Unsupported schema type " + parent.getClass() + " on stack."); } checkArgument(schema != null, "Could not find schema for node %s in %s", qname, parent); return schema; }
@Nonnull @SuppressWarnings("unchecked") @Override public NodeCodecContext<D> yangPathArgumentChild(final YangInstanceIdentifier.PathArgument arg) { final NodeContextSupplier childSupplier; if (arg instanceof NodeIdentifierWithPredicates) { childSupplier = byYang.get(new NodeIdentifier(arg.getNodeType())); } else if (arg instanceof AugmentationIdentifier) { childSupplier = yangAugmentationChild((AugmentationIdentifier) arg); } else { childSupplier = byYang.get(arg); } // FIXME: Since instance identifier does not reference choice or case, // we should search in data children of choice/case if (childSupplier instanceof DataContainerCodecPrototype) { final DataContainerCodecContext<?,T> context = ((DataContainerCodecPrototype) childSupplier).get(); if (context instanceof ChoiceNodeCodecContext) { return (NodeCodecContext<D>) childNonNull(((ChoiceNodeCodecContext) context).yangPathArgumentChild(arg), arg, "Argument %s is not valid child of %s", arg, getSchema()); } } return (NodeCodecContext<D>) childNonNull(childSupplier, arg, "Argument %s is not valid child of %s", arg, getSchema()).get(); }