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.OrderedNodeContainer;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
*/
@FunctionalInterface
interface Apply {
- Optional<TreeNode> apply(ModifiedNode modification, Optional<TreeNode> storeMeta, Version version);
+ Optional<? extends TreeNode> apply(ModifiedNode modification, Optional<? extends TreeNode> storeMeta,
+ Version version);
}
/**
*/
@FunctionalInterface
interface ApplyWrite {
- TreeNode applyWrite(ModifiedNode modification, NormalizedNode<?, ?> newValue, Optional<TreeNode> storeMeta,
- Version version);
- }
-
- /**
- * This is a capture of
- * {@link ModificationApplyOperation#checkApplicable(ModificationPath, NodeModification, Optional, Version)}.
- */
- @FunctionalInterface
- interface CheckApplicable {
- void checkApplicable(ModificationPath path, NodeModification modification, Optional<TreeNode> current,
- Version version) throws DataValidationFailedException;
+ TreeNode applyWrite(ModifiedNode modification, NormalizedNode<?, ?> newValue,
+ Optional<? extends TreeNode> storeMeta, Version version);
}
- /**
- * Fake TreeNode version used in
- * {@link #checkApplicable(ModificationPath, NodeModification, Optional, Version)}.
- * It is okay to use a global constant, as the delegate will ignore it anyway. For
- * {@link #apply(ModifiedNode, Optional, Version)} we will use the appropriate version as provided to us.
- */
- private static final Version FAKE_VERSION = Version.initial();
-
private AutomaticLifecycleMixin() {
}
- static Optional<TreeNode> apply(final Apply delegate, final ApplyWrite writeDelegate,
- final NormalizedNode<?, ?> emptyNode, final ModifiedNode modification, final Optional<TreeNode> storeMeta,
- final Version version) {
- // The only way a tree node can disappear is through delete (which we handle here explicitly) or through
- // actions of disappearResult(). It is therefore safe to perform Optional.get() on the results of
- // delegate.apply()
- final TreeNode ret;
+ static Optional<? extends TreeNode> apply(final Apply delegate, final ApplyWrite writeDelegate,
+ final NormalizedNode<?, ?> emptyNode, final ModifiedNode modification,
+ final Optional<? extends TreeNode> storeMeta, final Version version) {
+ final Optional<? extends TreeNode> ret;
if (modification.getOperation() == LogicalOperation.DELETE) {
if (modification.getChildren().isEmpty()) {
return delegate.apply(modification, storeMeta, version);
}
// Delete with children, implies it really is an empty write
- ret = writeDelegate.applyWrite(modification, emptyNode, storeMeta, version);
+ ret = Optional.of(writeDelegate.applyWrite(modification, emptyNode, storeMeta, version));
} else if (modification.getOperation() == LogicalOperation.TOUCH && !storeMeta.isPresent()) {
ret = applyTouch(delegate, emptyNode, modification, storeMeta, version);
} else {
// No special handling required here, run normal apply operation
- ret = delegate.apply(modification, storeMeta, version).get();
+ ret = delegate.apply(modification, storeMeta, version);
}
- return disappearResult(modification, ret, storeMeta);
- }
-
- static void checkApplicable(final CheckApplicable delegate, final NormalizedNode<?, ?> emptyNode,
- final ModificationPath path, final NodeModification modification, final Optional<TreeNode> current,
- final Version version) throws DataValidationFailedException {
- if (modification.getOperation() == LogicalOperation.TOUCH && !current.isPresent()) {
- // Structural containers are created as needed, so we pretend this container is here
- delegate.checkApplicable(path, modification, fakeMeta(emptyNode, FAKE_VERSION), version);
- } else {
- delegate.checkApplicable(path, modification, current, version);
- }
+ return ret.isPresent() ? disappearResult(modification, ret.get(), storeMeta) : ret;
}
- private static TreeNode applyTouch(final Apply delegate, final NormalizedNode<?, ?> emptyNode,
- final ModifiedNode modification, final Optional<TreeNode> storeMeta, final Version version) {
+ private static Optional<? extends TreeNode> applyTouch(final Apply delegate, final NormalizedNode<?, ?> emptyNode,
+ final ModifiedNode modification, final Optional<? extends TreeNode> storeMeta, final Version version) {
// Container is not present, let's take care of the 'magically appear' part of our job
- final Optional<TreeNode> ret = delegate.apply(modification, fakeMeta(emptyNode, version), version);
+ final Optional<? extends TreeNode> ret = delegate.apply(modification, fakeMeta(emptyNode, version), version);
// If the delegate indicated SUBTREE_MODIFIED, account for the fake and report APPEARED
if (modification.getModificationType() == ModificationType.SUBTREE_MODIFIED) {
modification.resolveModificationType(ModificationType.APPEARED);
}
- return ret.get();
+ return ret;
}
- private static Optional<TreeNode> disappearResult(final ModifiedNode modification, final TreeNode result,
- final Optional<TreeNode> storeMeta) {
+ private static Optional<? extends TreeNode> disappearResult(final ModifiedNode modification, final TreeNode result,
+ final Optional<? extends TreeNode> storeMeta) {
// Check if the result is in fact empty before pulling any tricks
if (!isEmpty(result)) {
return Optional.of(result);