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.mdsal.binding.dom.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 FunctionalNotificationListenerAdapter(final BindingNormalizedNodeSerializer codec, final Class<N> type,
25 final NotificationListener<N> delegate) {
28 this.delegate = delegate;
32 public void onNotification(@Nonnull final DOMNotification notification) {
33 delegate.onNotification(type.cast(deserialize(notification)));
36 private Notification deserialize(final DOMNotification notification) {
37 if (notification instanceof LazySerializedDOMNotification) {
38 return ((LazySerializedDOMNotification) notification).getBindingData();
40 return codec.fromNormalizedNodeNotification(notification.getType(), notification.getBody());