X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=binding%2Fmdsal-binding-dom-adapter%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fadapter%2FLazyDataTreeModification.java;h=8c89a5a128ded5f30c7a1ae38ab7dc42d8bad367;hb=11408d627adca7eb71ac956c3ad01f75b6b91596;hp=a327205eeff01480bbcc3fac0e09caf627d868ae;hpb=c241dcfa5322ac10810a1068ccd2eb57f6f2dbb2;p=mdsal.git diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDataTreeModification.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDataTreeModification.java index a327205eef..8c89a5a128 100644 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDataTreeModification.java +++ b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDataTreeModification.java @@ -7,66 +7,60 @@ */ package org.opendaylight.mdsal.binding.dom.adapter; +import static java.util.Objects.requireNonNull; + import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; import java.util.ArrayList; -import java.util.Collection; import java.util.List; -import java.util.Map.Entry; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.binding.api.DataObjectModification; import org.opendaylight.mdsal.binding.api.DataTreeIdentifier; import org.opendaylight.mdsal.binding.api.DataTreeModification; -import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode; +import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMDataTreeCandidate; +import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate; /** * Lazily translated {@link DataTreeModification} based on {@link DataTreeCandidate}. * *

- * {@link DataTreeModification} represents Data tree change event, - * but whole tree is not translated or resolved eagerly, but only child nodes - * which are directly accessed by user of data object modification. - * + * {@link DataTreeModification} represents Data tree change event, but whole tree is not translated or resolved eagerly, + * but only child nodes which are directly accessed by user of data object modification. */ -class LazyDataTreeModification implements DataTreeModification { - - private final DataTreeIdentifier path; - private final DataObjectModification rootNode; +final class LazyDataTreeModification implements DataTreeModification { + private final @NonNull DataTreeIdentifier path; + private final @NonNull DataObjectModification rootNode; - LazyDataTreeModification(final DataTreeIdentifier path, final DataObjectModification modification) { - this.path = Preconditions.checkNotNull(path); - this.rootNode = Preconditions.checkNotNull(modification); + private LazyDataTreeModification(final DataTreeIdentifier path, final DataObjectModification modification) { + this.path = requireNonNull(path); + this.rootNode = requireNonNull(modification); } @SuppressWarnings({"unchecked", "rawtypes"}) - static DataTreeModification create(final BindingToNormalizedNodeCodec codec, + static DataTreeModification create(final CurrentAdapterSerializer serializer, final DataTreeCandidate domChange, final LogicalDatastoreType datastoreType) { - final Entry, BindingCodecTreeNode> codecCtx = - codec.getSubtreeCodec(domChange.getRootPath()); - final DataTreeIdentifier path = DataTreeIdentifier.create(datastoreType, codecCtx.getKey()); - final DataObjectModification modification = - LazyDataObjectModification.create(codecCtx.getValue(), domChange.getRootNode()); - return new LazyDataTreeModification(path, modification); + final InstanceIdentifier bindingPath = serializer.coerceInstanceIdentifier(domChange.getRootPath()); + final BindingDataObjectCodecTreeNode codec = serializer.getSubtreeCodec(bindingPath); + final DataTreeIdentifier path = DataTreeIdentifier.create(datastoreType, bindingPath); + return new LazyDataTreeModification(path, LazyDataObjectModification.create(codec, domChange.getRootNode())); } @SuppressWarnings({"unchecked", "rawtypes"}) - static DataTreeModification create(final BindingToNormalizedNodeCodec codec, + static DataTreeModification create(final CurrentAdapterSerializer serializer, final DOMDataTreeCandidate candidate) { - final Entry, BindingCodecTreeNode> codecCtx = - codec.getSubtreeCodec(candidate.getRootPath().getRootIdentifier()); - final DataTreeIdentifier path = - DataTreeIdentifier.create(candidate.getRootPath().getDatastoreType(), codecCtx.getKey()); - final DataObjectModification modification = - LazyDataObjectModification.create(codecCtx.getValue(), candidate.getRootNode()); - return new LazyDataTreeModification(path, modification); + final DOMDataTreeIdentifier domRootPath = candidate.getRootPath(); + final InstanceIdentifier bindingPath = serializer.coerceInstanceIdentifier(domRootPath.getRootIdentifier()); + final BindingDataObjectCodecTreeNode codec = serializer.getSubtreeCodec(bindingPath); + return new LazyDataTreeModification(DataTreeIdentifier.create(domRootPath.getDatastoreType(), bindingPath), + LazyDataObjectModification.create(codec, candidate.getRootNode())); } - static Collection> from(final BindingToNormalizedNodeCodec codec, - final Collection domChanges, final LogicalDatastoreType datastoreType) { + static @NonNull List> from(final CurrentAdapterSerializer codec, + final List domChanges, final LogicalDatastoreType datastoreType) { final List> result = new ArrayList<>(domChanges.size()); for (final DataTreeCandidate domChange : domChanges) { result.add(LazyDataTreeModification.create(codec, domChange, datastoreType));