*/
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}.
*
* <p>
- * {@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<T extends DataObject> implements DataTreeModification<T> {
-
- private final DataTreeIdentifier<T> path;
- private final DataObjectModification<T> rootNode;
+final class LazyDataTreeModification<T extends DataObject> implements DataTreeModification<T> {
+ private final @NonNull DataTreeIdentifier<T> path;
+ private final @NonNull DataObjectModification<T> rootNode;
- LazyDataTreeModification(final DataTreeIdentifier<T> path, final DataObjectModification<T> modification) {
- this.path = Preconditions.checkNotNull(path);
- this.rootNode = Preconditions.checkNotNull(modification);
+ private LazyDataTreeModification(final DataTreeIdentifier<T> path, final DataObjectModification<T> modification) {
+ this.path = requireNonNull(path);
+ this.rootNode = requireNonNull(modification);
}
@SuppressWarnings({"unchecked", "rawtypes"})
- static <T extends DataObject> DataTreeModification<T> create(final BindingToNormalizedNodeCodec codec,
+ static <T extends DataObject> DataTreeModification<T> create(final CurrentAdapterSerializer serializer,
final DataTreeCandidate domChange, final LogicalDatastoreType datastoreType) {
- final Entry<InstanceIdentifier<?>, 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 <T extends DataObject> DataTreeModification<T> create(final BindingToNormalizedNodeCodec codec,
+ static <T extends DataObject> DataTreeModification<T> create(final CurrentAdapterSerializer serializer,
final DOMDataTreeCandidate candidate) {
- final Entry<InstanceIdentifier<?>, 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 <T extends DataObject> Collection<DataTreeModification<T>> from(final BindingToNormalizedNodeCodec codec,
- final Collection<DataTreeCandidate> domChanges, final LogicalDatastoreType datastoreType) {
+ static <T extends DataObject> @NonNull List<DataTreeModification<T>> from(final CurrentAdapterSerializer codec,
+ final List<DataTreeCandidate> domChanges, final LogicalDatastoreType datastoreType) {
final List<DataTreeModification<T>> result = new ArrayList<>(domChanges.size());
for (final DataTreeCandidate domChange : domChanges) {
result.add(LazyDataTreeModification.create(codec, domChange, datastoreType));