*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
+import java.util.Map.Entry;
+
+import javax.annotation.concurrent.GuardedBy;
+
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.annotation.concurrent.GuardedBy;
-import java.util.Map.Entry;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
final class InMemoryDataTreeModification implements DataTreeModification {
private static final Logger LOG = LoggerFactory.getLogger(InMemoryDataTreeModification.class);
- private final ModificationApplyOperation strategyTree;
+ private final RootModificationApplyOperation strategyTree;
private final InMemoryDataTreeSnapshot snapshot;
private final ModifiedNode rootNode;
@GuardedBy("this")
private boolean sealed = false;
- InMemoryDataTreeModification(final InMemoryDataTreeSnapshot snapshot, final ModificationApplyOperation resolver) {
+ InMemoryDataTreeModification(final InMemoryDataTreeSnapshot snapshot, final RootModificationApplyOperation resolver) {
this.snapshot = Preconditions.checkNotNull(snapshot);
- this.strategyTree = Preconditions.checkNotNull(resolver);
+ this.strategyTree = Preconditions.checkNotNull(resolver).snapshot();
this.rootNode = ModifiedNode.createUnmodified(snapshot.getRootNode());
}
}
@Override
- public synchronized void write(final InstanceIdentifier path, final NormalizedNode<?, ?> value) {
+ public synchronized void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> value) {
checkSealed();
resolveModificationFor(path).write(value);
}
@Override
- public synchronized void merge(final InstanceIdentifier path, final NormalizedNode<?, ?> data) {
+ public synchronized void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
checkSealed();
mergeImpl(resolveModificationFor(path),data);
}
}
@Override
- public synchronized void delete(final InstanceIdentifier path) {
+ public synchronized void delete(final YangInstanceIdentifier path) {
checkSealed();
resolveModificationFor(path).delete();
}
@Override
- public synchronized Optional<NormalizedNode<?, ?>> readNode(final InstanceIdentifier path) {
+ public synchronized Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier path) {
/*
* Walk the tree from the top, looking for the first node between root and
* the requested path which has been modified. If no such node exists,
* we use the node itself.
*/
- final Entry<InstanceIdentifier, ModifiedNode> entry = TreeNodeUtils.findClosestsOrFirstMatch(rootNode, path, ModifiedNode.IS_TERMINAL_PREDICATE);
- final InstanceIdentifier key = entry.getKey();
+ final Entry<YangInstanceIdentifier, ModifiedNode> entry = TreeNodeUtils.findClosestsOrFirstMatch(rootNode, path, ModifiedNode.IS_TERMINAL_PREDICATE);
+ final YangInstanceIdentifier key = entry.getKey();
final ModifiedNode mod = entry.getValue();
final Optional<TreeNode> result = resolveSnapshot(key, mod);
}
}
- private Optional<TreeNode> resolveSnapshot(final InstanceIdentifier path,
+ private Optional<TreeNode> resolveSnapshot(final YangInstanceIdentifier path,
final ModifiedNode modification) {
final Optional<Optional<TreeNode>> potentialSnapshot = modification.getSnapshotCache();
if(potentialSnapshot.isPresent()) {
}
}
- private ModificationApplyOperation resolveModificationStrategy(final InstanceIdentifier path) {
+ private ModificationApplyOperation resolveModificationStrategy(final YangInstanceIdentifier path) {
LOG.trace("Resolving modification apply strategy for {}", path);
- return TreeNodeUtils.findNodeChecked(strategyTree, path);
+ if(rootNode.getType() == ModificationType.UNMODIFIED) {
+ strategyTree.upgradeIfPossible();
+ }
+
+ return TreeNodeUtils.<ModificationApplyOperation>findNodeChecked(strategyTree, path);
}
- private OperationWithModification resolveModificationFor(final InstanceIdentifier path) {
+ private OperationWithModification resolveModificationFor(final YangInstanceIdentifier path) {
ModifiedNode modification = rootNode;
// We ensure strategy is present.
ModificationApplyOperation operation = resolveModificationStrategy(path);
- for (PathArgument pathArg : path.getPath()) {
+ for (PathArgument pathArg : path.getPathArguments()) {
modification = modification.modifyChild(pathArg);
}
return OperationWithModification.from(operation, modification);