package org.opendaylight.yangtools.yang.data.impl.schema.tree;
import static com.google.common.base.Preconditions.checkArgument;
-import com.google.common.base.Optional;
+
import com.google.common.base.Preconditions;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import java.util.Optional;
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.tree.IncorrectDataStructureException;
private final Class<? extends NormalizedNode<?, ?>> nodeClass;
private final T schema;
- protected AbstractValueNodeModificationStrategy(final T schema, final Class<? extends NormalizedNode<?, ?>> nodeClass) {
+ protected AbstractValueNodeModificationStrategy(final T schema,
+ final Class<? extends NormalizedNode<?, ?>> nodeClass) {
this.nodeClass = Preconditions.checkNotNull(nodeClass);
this.schema = schema;
}
@Override
- protected final void verifyWrittenStructure(final NormalizedNode<?, ?> writtenValue) {
+ protected final void verifyStructure(final NormalizedNode<?, ?> writtenValue, final boolean verifyChildren) {
checkArgument(nodeClass.isInstance(writtenValue), "Node should must be of type %s", nodeClass);
}
@Override
public final Optional<ModificationApplyOperation> getChild(final PathArgument child) {
throw new UnsupportedOperationException("Node " + schema.getPath()
- + "is leaf type node. Child nodes not allowed");
+ + " is leaf type node. Child nodes not allowed");
}
@Override
}
@Override
- protected final TreeNode applySubtreeChange(final ModifiedNode modification,
- final TreeNode currentMeta, final Version version) {
+ protected final TreeNode applyTouch(final ModifiedNode modification, final TreeNode currentMeta,
+ final Version version) {
throw new UnsupportedOperationException("Node " + schema.getPath()
- + "is leaf type node. Subtree change is not allowed.");
+ + " is leaf type node. Subtree change is not allowed.");
}
@Override
protected final TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
final Version version) {
- // Just overwrite whatever was there
+ // Just overwrite whatever was there, but be sure to run validation
+ final NormalizedNode<?, ?> newValue = modification.getWrittenValue();
+ verifyStructure(newValue, true);
modification.resolveModificationType(ModificationType.WRITE);
- return applyWrite(modification, null, version);
+ return applyWrite(modification, newValue, null, version);
}
@Override
- protected final TreeNode applyWrite(final ModifiedNode modification,
+ protected final TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode<?, ?> newValue,
final Optional<TreeNode> currentMeta, final Version version) {
- return TreeNodeFactory.createTreeNode(modification.getWrittenValue(), version);
+ return TreeNodeFactory.createTreeNode(newValue, version);
+ }
+
+ @Override
+ protected final void checkTouchApplicable(final ModificationPath path, final NodeModification modification,
+ final Optional<TreeNode> current, final Version version) throws IncorrectDataStructureException {
+ throw new IncorrectDataStructureException(path.toInstanceIdentifier(), "Subtree modification is not allowed.");
+ }
+
+ @Override
+ void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode<?, ?> value, final Version version) {
+
+ switch (node.getOperation()) {
+ // Delete performs a data dependency check on existence of the node. Performing a merge
+ // on DELETE means we
+ // are really performing a write.
+ case DELETE:
+ case WRITE:
+ node.write(value);
+ break;
+ default:
+ node.updateValue(LogicalOperation.MERGE, value);
+ }
}
@Override
- protected final void checkTouchApplicable(final YangInstanceIdentifier path, final NodeModification modification,
- final Optional<TreeNode> current) throws IncorrectDataStructureException {
- throw new IncorrectDataStructureException(path, "Subtree modification is not allowed.");
+ void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
+ verifyStructure(value, false);
}
-}
\ No newline at end of file
+}