Remove BindingDOMNotificationServiceAdapter.getDomService()
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / BindingDOMNotificationListenerAdapter.java
index 1ef252843f42d4c548358cb5fc6715e4edf25366..28e5c631d3dfcc9f600d627cf86b02e82a39facf 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.mdsal.binding.dom.adapter;
 
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ImmutableMap;
 import com.google.common.reflect.TypeToken;
 import java.lang.reflect.Method;
@@ -14,55 +16,36 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.dom.adapter.invoke.NotificationListenerInvoker;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
-import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
 import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.binding.NotificationListener;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-
-class BindingDOMNotificationListenerAdapter implements DOMNotificationListener {
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 
-    private final BindingNormalizedNodeSerializer codec;
-    private final NotificationListener delegate;
-    private final Map<SchemaPath,NotificationListenerInvoker> invokers;
+final class BindingDOMNotificationListenerAdapter extends AbstractDOMNotificationListenerAdapter {
+    private final ImmutableMap<Absolute, NotificationListenerInvoker> invokers;
+    private final @NonNull NotificationListener delegate;
 
-    BindingDOMNotificationListenerAdapter(final BindingNormalizedNodeSerializer codec,
-            final NotificationListener delegate) {
-        this.codec = codec;
-        this.delegate = delegate;
-        this.invokers = createInvokerMapFor(delegate.getClass());
+    BindingDOMNotificationListenerAdapter(final AdapterContext adapterContext, final NotificationListener delegate) {
+        super(adapterContext);
+        this.delegate = requireNonNull(delegate);
+        invokers = createInvokerMapFor(delegate.getClass());
     }
 
     @Override
-    public void onNotification(@Nonnull final DOMNotification notification) {
-        final Notification baNotification = deserialize(notification);
-        final QName notificationQName = notification.getType().getLastComponent();
-        getInvoker(notification.getType()).invokeNotification(delegate, notificationQName, baNotification);
-    }
-
-    private Notification deserialize(final DOMNotification notification) {
-        if (notification instanceof LazySerializedDOMNotification) {
-            return ((LazySerializedDOMNotification) notification).getBindingData();
-        }
-        return codec.fromNormalizedNodeNotification(notification.getType(), notification.getBody());
-    }
-
-    private NotificationListenerInvoker getInvoker(final SchemaPath type) {
-        return invokers.get(type);
+    void onNotification(final Absolute domType, final Notification<?> notification) {
+        invokers.get(domType).invokeNotification(delegate, domType.lastNodeIdentifier(), notification);
     }
 
-    protected Set<SchemaPath> getSupportedNotifications() {
+    @Override
+    Set<Absolute> getSupportedNotifications() {
         return invokers.keySet();
     }
 
-    public static Map<SchemaPath, NotificationListenerInvoker> createInvokerMapFor(
+    private static ImmutableMap<Absolute, NotificationListenerInvoker> createInvokerMapFor(
             final Class<? extends NotificationListener> implClz) {
-        final Map<SchemaPath, NotificationListenerInvoker> builder = new HashMap<>();
+        final Map<Absolute, NotificationListenerInvoker> builder = new HashMap<>();
         for (final TypeToken<?> ifaceToken : TypeToken.of(implClz).getTypes().interfaces()) {
             Class<?> iface = ifaceToken.getRawType();
             if (NotificationListener.class.isAssignableFrom(iface) && BindingReflections.isBindingClass(iface)) {
@@ -70,7 +53,7 @@ class BindingDOMNotificationListenerAdapter implements DOMNotificationListener {
                 final Class<? extends NotificationListener> listenerType
                         = (Class<? extends NotificationListener>) iface;
                 final NotificationListenerInvoker invoker = NotificationListenerInvoker.from(listenerType);
-                for (final SchemaPath path : getNotificationTypes(listenerType)) {
+                for (final Absolute path : getNotificationTypes(listenerType)) {
                     builder.put(path, invoker);
                 }
             }
@@ -78,15 +61,14 @@ class BindingDOMNotificationListenerAdapter implements DOMNotificationListener {
         return ImmutableMap.copyOf(builder);
     }
 
-    private static Set<SchemaPath> getNotificationTypes(final Class<? extends NotificationListener> type) {
+    private static Set<Absolute> getNotificationTypes(final Class<? extends NotificationListener> type) {
         // TODO: Investigate possibility and performance impact if we cache this or expose
         // it from NotificationListenerInvoker
-        final Set<SchemaPath> ret = new HashSet<>();
+        final Set<Absolute> ret = new HashSet<>();
         for (final Method method : type.getMethods()) {
             if (BindingReflections.isNotificationCallback(method)) {
                 final Class<?> notification = method.getParameterTypes()[0];
-                final QName name = BindingReflections.findQName(notification);
-                ret.add(SchemaPath.create(true, name));
+                ret.add(Absolute.of(BindingReflections.findQName(notification)));
             }
         }
         return ret;