X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=yang%2Fyang-data-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fimpl%2Fschema%2Ftree%2FAbstractDataTreeTip.java;h=40c08b5b5ce9cc135c8e34e650f4db94c7bc3061;hb=refs%2Fchanges%2F55%2F93855%2F1;hp=9b1ef2d2ef50148aacbf47488c95ae4f718fe0d0;hpb=2832d604e4de5aa8136e65baca528a9be9154557;p=yangtools.git diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractDataTreeTip.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractDataTreeTip.java index 9b1ef2d2ef..40c08b5b5c 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractDataTreeTip.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractDataTreeTip.java @@ -7,12 +7,12 @@ */ package org.opendaylight.yangtools.yang.data.impl.schema.tree; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import java.util.Collections; -import javax.annotation.Nonnull; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; + +import java.util.Optional; +import org.eclipse.jdt.annotation.NonNull; 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.tree.DataTreeCandidateTip; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeTip; @@ -20,38 +20,44 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailed import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode; abstract class AbstractDataTreeTip implements DataTreeTip { - private static final YangInstanceIdentifier PUBLIC_ROOT_PATH = YangInstanceIdentifier.create(Collections.emptyList()); - /** * Return the current root node of this tip. * * @return Current tip root node, may not be null. */ - @Nonnull protected abstract TreeNode getTipRoot(); + protected abstract @NonNull TreeNode getTipRoot(); + + abstract @NonNull YangInstanceIdentifier getRootPath(); @Override public final void validate(final DataTreeModification modification) throws DataValidationFailedException { - Preconditions.checkArgument(modification instanceof InMemoryDataTreeModification, "Invalid modification class %s", modification.getClass()); - final InMemoryDataTreeModification m = (InMemoryDataTreeModification)modification; + final InMemoryDataTreeModification m = checkedCast(modification); + checkArgument(m.isSealed(), "Attempted to verify unsealed modification %s", m); - m.getStrategy().checkApplicable(PUBLIC_ROOT_PATH, m.getRootModification(), Optional.of(getTipRoot())); + m.getStrategy().checkApplicable(new ModificationPath(getRootPath()), m.getRootModification(), + Optional.of(getTipRoot()), m.getVersion()); } @Override public final DataTreeCandidateTip prepare(final DataTreeModification modification) { - Preconditions.checkArgument(modification instanceof InMemoryDataTreeModification, "Invalid modification class %s", modification.getClass()); + final InMemoryDataTreeModification m = checkedCast(modification); + checkArgument(m.isSealed(), "Attempted to prepare unsealed modification %s", m); - final InMemoryDataTreeModification m = (InMemoryDataTreeModification)modification; final ModifiedNode root = m.getRootModification(); final TreeNode currentRoot = getTipRoot(); if (root.getOperation() == LogicalOperation.NONE) { - return new NoopDataTreeCandidate(PUBLIC_ROOT_PATH, root, currentRoot); + return new NoopDataTreeCandidate(YangInstanceIdentifier.empty(), root, currentRoot); } - final Optional newRoot = m.getStrategy().apply(m.getRootModification(), - Optional.of(currentRoot), m.getVersion()); - Preconditions.checkState(newRoot.isPresent(), "Apply strategy failed to produce root node for modification %s", modification); - return new InMemoryDataTreeCandidate(PUBLIC_ROOT_PATH, root, currentRoot, newRoot.get()); + final Optional newRoot = m.getStrategy().apply(m.getRootModification(), + Optional.of(currentRoot), m.getVersion()); + checkState(newRoot.isPresent(), "Apply strategy failed to produce root node for modification %s", modification); + return new InMemoryDataTreeCandidate(YangInstanceIdentifier.empty(), root, currentRoot, newRoot.get()); + } + + private static InMemoryDataTreeModification checkedCast(final DataTreeModification mod) { + checkArgument(mod instanceof InMemoryDataTreeModification, "Invalid modification class %s", mod.getClass()); + return (InMemoryDataTreeModification)mod; } }