Search in sources :

Example 6 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.

the class DataTreeCandidateInputOutput method readChildren.

private static Collection<DataTreeCandidateNode> readChildren(final NormalizedNodeDataInput in, final ReusableStreamReceiver receiver) throws IOException {
    final int size = in.readInt();
    if (size == 0) {
        return ImmutableList.of();
    }
    final Collection<DataTreeCandidateNode> ret = new ArrayList<>(size);
    for (int i = 0; i < size; ++i) {
        final DataTreeCandidateNode child = readNode(in, receiver);
        if (child != null) {
            ret.add(child);
        }
    }
    return ret;
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) ArrayList(java.util.ArrayList)

Example 7 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.

the class DataTreeCandidateInputOutput method readDataTreeCandidate.

@NonNull
public static DataTreeCandidate readDataTreeCandidate(final NormalizedNodeDataInput in, final ReusableStreamReceiver receiver) throws IOException {
    final YangInstanceIdentifier rootPath = in.readYangInstanceIdentifier();
    final byte type = in.readByte();
    final DataTreeCandidateNode rootNode;
    switch(type) {
        case APPEARED:
            rootNode = ModifiedDataTreeCandidateNode.create(ModificationType.APPEARED, readChildren(in, receiver));
            break;
        case DELETE:
            rootNode = DeletedDataTreeCandidateNode.create();
            break;
        case DISAPPEARED:
            rootNode = ModifiedDataTreeCandidateNode.create(ModificationType.DISAPPEARED, readChildren(in, receiver));
            break;
        case SUBTREE_MODIFIED:
            rootNode = ModifiedDataTreeCandidateNode.create(ModificationType.SUBTREE_MODIFIED, readChildren(in, receiver));
            break;
        case WRITE:
            rootNode = DataTreeCandidateNodes.written(in.readNormalizedNode(receiver));
            break;
        case UNMODIFIED:
            rootNode = UnmodifiedRootDataTreeCandidateNode.INSTANCE;
            break;
        default:
            throw unhandledNodeType(type);
    }
    return DataTreeCandidates.newDataTreeCandidate(rootPath, rootNode);
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 8 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.

the class DataTreeCandidateInputOutput method writeDataTreeCandidate.

public static void writeDataTreeCandidate(final NormalizedNodeDataOutput out, final DataTreeCandidate candidate) throws IOException {
    out.writeYangInstanceIdentifier(candidate.getRootPath());
    final DataTreeCandidateNode node = candidate.getRootNode();
    switch(node.getModificationType()) {
        case APPEARED:
            out.writeByte(APPEARED);
            writeChildren(out, node.getChildNodes());
            break;
        case DELETE:
            out.writeByte(DELETE);
            break;
        case DISAPPEARED:
            out.writeByte(DISAPPEARED);
            writeChildren(out, node.getChildNodes());
            break;
        case SUBTREE_MODIFIED:
            out.writeByte(SUBTREE_MODIFIED);
            writeChildren(out, node.getChildNodes());
            break;
        case UNMODIFIED:
            out.writeByte(UNMODIFIED);
            break;
        case WRITE:
            out.writeByte(WRITE);
            out.writeNormalizedNode(node.getDataAfter().get());
            break;
        default:
            throw unhandledNodeType(node);
    }
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)

Example 9 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.

the class DataTreeCandidateInputOutput method readModifiedNode.

private static DataTreeCandidateNode readModifiedNode(final ModificationType type, final NormalizedNodeDataInput in, final ReusableStreamReceiver receiver) throws IOException {
    final PathArgument identifier = in.readPathArgument();
    final Collection<DataTreeCandidateNode> children = readChildren(in, receiver);
    if (children.isEmpty()) {
        LOG.debug("Modified node {} does not have any children, not instantiating it", identifier);
        return null;
    }
    return ModifiedDataTreeCandidateNode.create(identifier, type, children);
}
Also used : DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)

Example 10 with DataTreeCandidateNode

use of org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode in project yangtools by opendaylight.

the class Bug3674Test method testDeleteOfNonExistingNode.

@Test
public void testDeleteOfNonExistingNode() throws DataValidationFailedException {
    final DataTreeModification mod = tree.takeSnapshot().newModification();
    mod.delete(TestModel.OUTER_LIST_PATH);
    mod.ready();
    final DataTreeCandidate candidate = tree.prepare(mod);
    final DataTreeCandidateNode root = candidate.getRootNode();
    assertEquals(ModificationType.UNMODIFIED, root.getModificationType());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTreeCandidateNode(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode) Test(org.junit.Test)

Aggregations

DataTreeCandidateNode (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode)63 Test (org.junit.Test)48 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)36 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)23 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)15 DataTreeModificationCursor (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModificationCursor)13 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)9 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)7 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 DOMDataTreeChangeService (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService)6 DOMDataTreeWriteTransaction (org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction)6 ArrayList (java.util.ArrayList)5 NonNull (org.eclipse.jdt.annotation.NonNull)3 ModificationType (org.opendaylight.yangtools.yang.data.tree.api.ModificationType)3 Objects.requireNonNull (java.util.Objects.requireNonNull)2 List (java.util.List)1 BindingCodecTreeNode (org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode)1 BindingDataObjectCodecTreeNode (org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode)1 DOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)1