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;
}
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);
}
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);
}
}
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);
}
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());
}
Aggregations