Merge "BUG-2288: deprecate old binding Notification API elements"
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / BindingDOMDataTreeChangeListenerAdapter.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.binding.impl;
9
10 import com.google.common.base.Preconditions;
11 import java.util.Collection;
12 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
14 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
15 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
18
19 /**
20  * Adapter wrapping Binding {@link DataTreeChangeListener} and exposing
21  * it as {@link DOMDataTreeChangeListener} and translated DOM events
22  * to their Binding equivalent.
23  *
24  */
25 final class BindingDOMDataTreeChangeListenerAdapter<T extends DataObject> implements DOMDataTreeChangeListener {
26
27     private final BindingToNormalizedNodeCodec codec;
28     private final DataTreeChangeListener<T> listener;
29     private final LogicalDatastoreType store;
30
31     BindingDOMDataTreeChangeListenerAdapter(final BindingToNormalizedNodeCodec codec, final DataTreeChangeListener<T> listener,
32             final LogicalDatastoreType store) {
33         this.codec = Preconditions.checkNotNull(codec);
34         this.listener = Preconditions.checkNotNull(listener);
35         this.store = Preconditions.checkNotNull(store);
36     }
37
38     @Override
39     public void onDataTreeChanged(final Collection<DataTreeCandidate> domChanges) {
40         final Collection<DataTreeModification<T>> bindingChanges = LazyDataTreeModification.from(codec, domChanges, store);
41         listener.onDataTreeChanged(bindingChanges);
42     }
43 }