2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3 * Copyright (c) 2021 PANTHEON.tech, s.r.o.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.mdsal.binding.dom.adapter;
11 import static com.google.common.base.Verify.verifyNotNull;
12 import static java.util.Objects.requireNonNull;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.mdsal.dom.api.DOMEvent;
17 import org.opendaylight.mdsal.dom.api.DOMNotification;
18 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
19 import org.opendaylight.yangtools.yang.binding.Notification;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
22 abstract class AbstractDOMNotificationListenerAdapter implements DOMNotificationListener {
23 private final AdapterContext adapterContext;
25 AbstractDOMNotificationListenerAdapter(final AdapterContext adapterContext) {
26 this.adapterContext = requireNonNull(adapterContext);
30 public final void onNotification(final DOMNotification notification) {
31 onNotification(notification.getType(), verifyNotNull(deserialize(notification)));
34 abstract void onNotification(@NonNull Absolute domType, @NonNull Notification<?> notification);
36 abstract Set<Absolute> getSupportedNotifications();
38 private Notification<?> deserialize(final DOMNotification notification) {
39 if (notification instanceof LazySerializedDOMNotification) {
40 // TODO: This is a routed-back notification, for which we may end up losing event time here, but that is
41 // okay, for now at least.
42 return ((LazySerializedDOMNotification) notification).getBindingData();
45 final CurrentAdapterSerializer serializer = adapterContext.currentSerializer();
46 return notification instanceof DOMEvent
47 ? serializer.fromNormalizedNodeNotification(notification.getType(), notification.getBody(),
48 ((DOMEvent) notification).getEventInstant())
49 : serializer.fromNormalizedNodeNotification(notification.getType(), notification.getBody());