/** * Check whether the data to be written consists only from mixins */ private static boolean containsOnlyNonVisibleData(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) { // There's only one such case:top level list (pathArguments == 1 && data is Mixin) // any other mixin nodes are contained by a "regular" node thus visible when serialized return path.getPathArguments().size() == 1 && data instanceof MixinNode; }
private static NodeIdentifierWithPredicates firstKeyOf(final YangInstanceIdentifier id, final Predicate<PathArgument> match) { final PathArgument ret = Iterables.find(id.getPathArguments(), match); Preconditions.checkArgument(ret instanceof NodeIdentifierWithPredicates, "Non-key peer identifier %s", ret); return (NodeIdentifierWithPredicates) ret; }
private static List<QName> extractSchemaPathQNames(final YangInstanceIdentifier topLevelIdentifier, final Map.Entry<YangInstanceIdentifier.PathArgument, DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> entry) { // must be filtered out of augmentation and keyed NodeIdentifiers return Stream.concat(topLevelIdentifier.getPathArguments().stream(), Stream.of(entry.getKey())) .filter(pathArgument -> pathArgument instanceof YangInstanceIdentifier.NodeIdentifier) .map(YangInstanceIdentifier.PathArgument::getNodeType) .collect(Collectors.toList()); } }
public DataNormalizationOperation<?> getOperation(final YangInstanceIdentifier legacy) throws DataNormalizationException { DataNormalizationOperation<?> currentOp = operation; for (PathArgument pathArgument : legacy.getPathArguments()) { currentOp = currentOp.getChild(pathArgument); } return currentOp; }
public static DataSchemaNode getSchemaNode(final SchemaContext schema,final YangInstanceIdentifier path) { checkArgument(schema != null,"YANG Schema must not be null."); checkArgument(path != null,"Path must not be null."); return getSchemaNode(schema, FluentIterable.from(path.getPathArguments()).transform(QNAME_FROM_PATH_ARGUMENT)); }
private void writeYangInstanceIdentifierInternal(final YangInstanceIdentifier identifier) throws IOException { Collection<PathArgument> pathArguments = identifier.getPathArguments(); output.writeInt(pathArguments.size()); for(PathArgument pathArgument : pathArguments) { writePathArgument(pathArgument); } }
private void writeYangInstanceIdentifierInternal(final YangInstanceIdentifier identifier) throws IOException { Collection<PathArgument> pathArguments = identifier.getPathArguments(); output.writeInt(pathArguments.size()); for (PathArgument pathArgument : pathArguments) { writePathArgument(pathArgument); } }
@Override public Optional<NormalizedNode<?, ?>> apply(final DOMRpcResult result) { checkReadSuccess(result, path); final DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> dataNode = findDataNode(result); return NormalizedNodes.findNode(dataNode, path.getPathArguments()); } });
void remove(final YangInstanceIdentifier id) { this.remove(id.getPathArguments().iterator()); } }
public static Optional<NormalizedNode<?, ?>> findNode(final NormalizedNode<?, ?> tree, final YangInstanceIdentifier path) { requireNonNull(tree, "Tree must not be null"); requireNonNull(path, "Path must not be null"); return findNode(Optional.of(tree), path.getPathArguments()); }
private static YangInstanceIdentifier firstIdentifierOf(final YangInstanceIdentifier id, final Predicate<PathArgument> match) { final int idx = Iterables.indexOf(id.getPathArguments(), match); Preconditions.checkArgument(idx != -1, "Failed to find %s in %s", match, id); // we want the element at index idx to be included in the list return YangInstanceIdentifier.create(Iterables.limit(id.getPathArguments(), idx + 1)); }
private void writeObject(final ObjectOutputStream outputStream) throws IOException { outputStream.defaultWriteObject(); final FixedYangInstanceIdentifier p; if (parent instanceof FixedYangInstanceIdentifier) { p = (FixedYangInstanceIdentifier) parent; } else { p = FixedYangInstanceIdentifier.create(parent.getPathArguments(), parent.hashCode()); } outputStream.writeObject(p); }
public YangInstanceIdentifier toLegacy(final YangInstanceIdentifier normalized) throws DataNormalizationException { ImmutableList.Builder<PathArgument> legacyArgs = ImmutableList.builder(); DataNormalizationOperation<?> currentOp = operation; for (PathArgument normalizedArg : normalized.getPathArguments()) { currentOp = currentOp.getChild(normalizedArg); if (!currentOp.isMixin()) { legacyArgs.add(normalizedArg); } } return YangInstanceIdentifier.create(legacyArgs.build()); }
private Collection<DataTreeCohortActor.CanCommit> perform(final RegistrationTreeNode<ActorRef> rootNode) { final List<PathArgument> toLookup = candidate.getRootPath().getPathArguments(); lookupAndCreateCanCommits(toLookup, 0, rootNode); return messages; } }
/** * Returns new builder for InstanceIdentifier with path arguments copied from original instance identifier. * * @param origin InstanceIdentifier from which path arguments are copied. * @return new builder for InstanceIdentifier with path arguments copied from original instance identifier. */ public static InstanceIdentifierBuilder builder(final YangInstanceIdentifier origin) { return new YangInstanceIdentifierBuilder(origin.getPathArguments(), origin.hashCode()); }
private String getModuleName(final YangInstanceIdentifier path) { if (path.isEmpty()) { return UNKNOWN_MODULE_NAME; } String namespace = path.getPathArguments().iterator().next().getNodeType().getNamespace().toASCIIString(); String moduleName = configuration.getModuleNameFromNameSpace(namespace); return moduleName != null ? moduleName : UNKNOWN_MODULE_NAME; } }
NormalizedNodeContext createContext(final YangInstanceIdentifier path) { NormalizedNodeContext result = root; for (PathArgument arg : path.getPathArguments()) { final Optional<NormalizedNode<?, ?>> node = NormalizedNodes.getDirectChild(result.getNode(), arg); checkArgument(node.isPresent(), "Node %s has no child %s", result.getNode(), arg); result = result.createChild(node.get()); } return result; }
@Override public DOMDataTreeWriteCursor createCursor(final DOMDataTreeIdentifier prefix) { Preconditions.checkState(!finished, "Transaction is finished/closed already."); Preconditions.checkState(cursor == null, "Previous cursor wasn't closed"); final YangInstanceIdentifier relativePath = toRelative(prefix.getRootIdentifier()); final DOMDataTreeWriteCursor ret = getCursor(); ret.enter(relativePath.getPathArguments()); return ret; } }
private String findModuleName(final YangInstanceIdentifier id, final SchemaContext context) { PathArgument rootQName = id.getPathArguments().iterator().next(); for (Module mod : context.getModules()) { if (mod.getDataChildByName(rootQName.getNodeType()) != null) { return mod.getName(); } } return null; }
private static DataSchemaContextNode<?> findSchemaNodeForNodePath(YangInstanceIdentifier nodePath, SchemaContext schemaContext) { DataSchemaContextNode<?> schemaNode = DataSchemaContextTree.from(schemaContext).getRoot(); for (PathArgument arg : nodePath.getPathArguments()) { schemaNode = schemaNode.getChild(arg); if (schemaNode == null) { break; } } return schemaNode; }