Java Code Examples for org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier#isEmpty()

The following examples show how to use org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InMemoryDataTreeFactory.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private static @NonNull NormalizedNode<?, ?> createRoot(final DataNodeContainer schemaNode,
        final YangInstanceIdentifier path) {
    if (path.isEmpty()) {
        checkArgument(schemaNode instanceof ContainerSchemaNode,
            "Conceptual tree root has to be a container, not %s", schemaNode);
        return ROOT_CONTAINER;
    }

    final PathArgument arg = path.getLastPathArgument();
    if (schemaNode instanceof ContainerSchemaNode) {
        checkArgument(arg instanceof NodeIdentifier, "Mismatched container %s path %s", schemaNode, path);
        return ImmutableContainerNodeBuilder.create().withNodeIdentifier((NodeIdentifier) arg).build();
    } else if (schemaNode instanceof ListSchemaNode) {
        // This can either be a top-level list or its individual entry
        if (arg instanceof NodeIdentifierWithPredicates) {
            return ImmutableNodes.mapEntryBuilder().withNodeIdentifier((NodeIdentifierWithPredicates) arg).build();
        }
        checkArgument(arg instanceof NodeIdentifier, "Mismatched list %s path %s", schemaNode, path);
        return ImmutableNodes.mapNodeBuilder().withNodeIdentifier((NodeIdentifier) arg).build();
    } else {
        throw new IllegalArgumentException("Unsupported root schema " + schemaNode);
    }
}
 
Example 2
Source File: InMemoryDataTreeFactory.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
private static @NonNull NormalizedNode<?, ?> createRoot(final YangInstanceIdentifier path) {
    if (path.isEmpty()) {
        return ROOT_CONTAINER;
    }

    final PathArgument arg = path.getLastPathArgument();
    if (arg instanceof NodeIdentifier) {
        return ImmutableContainerNodeBuilder.create().withNodeIdentifier((NodeIdentifier) arg).build();
    }
    if (arg instanceof NodeIdentifierWithPredicates) {
        return ImmutableNodes.mapEntryBuilder().withNodeIdentifier((NodeIdentifierWithPredicates) arg).build();
    }

    // FIXME: implement augmentations and leaf-lists
    throw new IllegalArgumentException("Unsupported root node " + arg);
}
 
Example 3
Source File: NormalizedNodeContext.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
Optional<NormalizedNodeContext> findDescendant(final YangInstanceIdentifier path) {
    if (path.isEmpty()) {
        return Optional.of(this);
    }

    NormalizedNodeContext ctxWalk = this;
    NormalizedNode<?, ?> dataWalk = node;
    for (PathArgument arg : path.getPathArguments()) {
        checkArgument(dataWalk instanceof DataContainerNode, "Path %s refers beyond node %s", path, dataWalk);

        final Optional<DataContainerChild<? extends @Nullable PathArgument, ?>> optChild =
                ((DataContainerNode)dataWalk).getChild(arg);
        if (!optChild.isPresent()) {
            return Optional.empty();
        }

        dataWalk = optChild.get();
        ctxWalk = createChild(dataWalk);
    }

    return Optional.of(ctxWalk.createChild(dataWalk));
}
 
Example 4
Source File: DataTreeCandidates.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void applyToCursorAwareModification(final CursorAwareDataTreeModification modification,
                                                   final DataTreeCandidate candidate) {
    final YangInstanceIdentifier candidatePath = candidate.getRootPath();
    if (candidatePath.isEmpty()) {
        try (DataTreeModificationCursor cursor = modification.openCursor()) {
            DataTreeCandidateNodes.applyRootToCursor(cursor, candidate.getRootNode());
        }
    } else {
        try (DataTreeModificationCursor cursor = modification.openCursor(candidatePath.getParent()).get()) {
            DataTreeCandidateNodes.applyRootedNodeToCursor(cursor, candidatePath, candidate.getRootNode());
        }
    }
}
 
Example 5
Source File: InMemoryDataTreeModification.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private void checkIdentifierReferencesData(final YangInstanceIdentifier path,
        final NormalizedNode<?, ?> data) {
    final PathArgument arg;

    if (!path.isEmpty()) {
        arg = path.getLastPathArgument();
        checkArgument(arg != null, "Instance identifier %s has invalid null path argument", path);
    } else {
        arg = rootNode.getIdentifier();
    }

    checkIdentifierReferencesData(arg, data);
}