2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.dom.adapter;
10 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
12 import org.opendaylight.mdsal.binding.api.DataTreeChangeListener;
13 import org.opendaylight.mdsal.binding.api.DataTreeModification;
14 import com.google.common.base.Preconditions;
15 import java.util.Collection;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
21 * Adapter wrapping Binding {@link DataTreeChangeListener} and exposing
22 * it as {@link DOMDataTreeChangeListener} and translated DOM events
23 * to their Binding equivalent.
26 final class BindingDOMDataTreeChangeListenerAdapter<T extends DataObject> implements DOMDataTreeChangeListener {
28 private final BindingToNormalizedNodeCodec codec;
29 private final DataTreeChangeListener<T> listener;
30 private final LogicalDatastoreType store;
32 BindingDOMDataTreeChangeListenerAdapter(final BindingToNormalizedNodeCodec codec, final DataTreeChangeListener<T> listener,
33 final LogicalDatastoreType store) {
34 this.codec = Preconditions.checkNotNull(codec);
35 this.listener = Preconditions.checkNotNull(listener);
36 this.store = Preconditions.checkNotNull(store);
40 public void onDataTreeChanged(final Collection<DataTreeCandidate> domChanges) {
41 final Collection<DataTreeModification<T>> bindingChanges = LazyDataTreeModification.from(codec, domChanges, store);
42 listener.onDataTreeChanged(bindingChanges);