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.controller.md.sal.binding.compat;
10 import javax.annotation.Nonnull;
11 import org.opendaylight.controller.md.sal.binding.impl.LazySerializedDOMNotification;
12 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
13 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener;
14 import org.opendaylight.controller.sal.binding.api.NotificationListener;
15 import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer;
16 import org.opendaylight.yangtools.yang.binding.Notification;
18 final class FunctionalNotificationListenerAdapter<N extends Notification> implements DOMNotificationListener {
20 private final BindingNormalizedNodeSerializer codec;
21 private final NotificationListener<N> delegate;
22 private final Class<N> type;
24 public FunctionalNotificationListenerAdapter(final BindingNormalizedNodeSerializer codec, final Class<N> type, final NotificationListener<N> delegate) {
27 this.delegate = delegate;
31 public void onNotification(@Nonnull final DOMNotification notification) {
32 delegate.onNotification( type.cast(deserialize(notification)));
35 private Notification deserialize(final DOMNotification notification) {
36 if(notification instanceof LazySerializedDOMNotification) {
37 return ((LazySerializedDOMNotification) notification).getBindingData();
39 return codec.fromNormalizedNodeNotification(notification.getType(), notification.getBody());