import com.google.common.annotations.Beta;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Utility class holding methods useful when dealing with {@link DataTreeCandidate} instances.
*/
@Beta
public final class DataTreeCandidates {
+ private static final Logger LOG = LoggerFactory.getLogger(DataTreeCandidates.class);
private DataTreeCandidates() {
throw new UnsupportedOperationException();
}
}
public static void applyToModification(final DataTreeModification modification, final DataTreeCandidate candidate) {
- applyNode(modification, candidate.getRootPath(), candidate.getRootNode());
+ if (modification instanceof CursorAwareDataTreeModification) {
+ try (DataTreeModificationCursor cursor = ((CursorAwareDataTreeModification) modification).createCursor(candidate.getRootPath())) {
+ applyNode(cursor, candidate.getRootNode());
+ }
+ } else {
+ applyNode(modification, candidate.getRootPath(), candidate.getRootNode());
+ }
}
private static void applyNode(final DataTreeModification modification, final YangInstanceIdentifier path, final DataTreeCandidateNode node) {
switch (node.getModificationType()) {
case DELETE:
modification.delete(path);
+ LOG.debug("Modification {} deleted path {}", modification, path);
break;
case SUBTREE_MODIFIED:
+ LOG.debug("Modification {} modified path {}", modification, path);
for (DataTreeCandidateNode child : node.getChildNodes()) {
applyNode(modification, path.node(child.getIdentifier()), child);
}
break;
case UNMODIFIED:
+ LOG.debug("Modification {} unmodified path {}", modification, path);
// No-op
break;
case WRITE:
modification.write(path, node.getDataAfter().get());
+ LOG.debug("Modification {} written path {}", modification, path);
+ break;
+ default:
+ throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());
+ }
+ }
+
+ private static void applyNode(final DataTreeModificationCursor cursor, final DataTreeCandidateNode node) {
+ switch (node.getModificationType()) {
+ case DELETE:
+ cursor.delete(node.getIdentifier());
+ break;
+ case SUBTREE_MODIFIED:
+ cursor.enter(node.getIdentifier());
+ for (DataTreeCandidateNode child : node.getChildNodes()) {
+ applyNode(cursor, child);
+ }
+ cursor.exit();
+ break;
+ case UNMODIFIED:
+ // No-op
+ break;
+ case WRITE:
+ cursor.write(node.getIdentifier(), node.getDataAfter().get());
break;
default:
throw new IllegalArgumentException("Unsupported modification " + node.getModificationType());