X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2FBindingDOMNotificationListenerAdapter.java;h=f749cb2fcaa2c18a9c5804acd398ff228768bd94;hb=refs%2Fchanges%2F11%2F80211%2F6;hp=86822274efb2d6dfa9965e9e7b33863bec141164;hpb=dfbfbf7abe18e6d6011cd33d4906f8a7e030ee84;p=controller.git diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java index 86822274ef..f749cb2fca 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingDOMNotificationListenerAdapter.java @@ -8,19 +8,19 @@ package org.opendaylight.controller.md.sal.binding.impl; import com.google.common.collect.ImmutableMap; +import com.google.common.reflect.TypeToken; import java.lang.reflect.Method; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import javax.annotation.Nonnull; import org.opendaylight.controller.md.sal.dom.api.DOMNotification; import org.opendaylight.controller.md.sal.dom.api.DOMNotificationListener; -import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; +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.yangtools.yang.binding.Notification; import org.opendaylight.yangtools.yang.binding.NotificationListener; -import org.opendaylight.yangtools.yang.binding.util.BindingReflections; -import org.opendaylight.yangtools.yang.binding.util.NotificationListenerInvoker; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.SchemaPath; @@ -30,21 +30,22 @@ class BindingDOMNotificationListenerAdapter implements DOMNotificationListener { private final NotificationListener delegate; private final Map invokers; - public BindingDOMNotificationListenerAdapter(final BindingNormalizedNodeSerializer codec, final NotificationListener delegate) { + BindingDOMNotificationListenerAdapter(final BindingNormalizedNodeSerializer codec, + final NotificationListener delegate) { this.codec = codec; this.delegate = delegate; this.invokers = createInvokerMapFor(delegate.getClass()); } @Override - public void onNotification(@Nonnull final DOMNotification notification) { + public void onNotification(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) { + if (notification instanceof LazySerializedDOMNotification) { return ((LazySerializedDOMNotification) notification).getBindingData(); } return codec.fromNormalizedNodeNotification(notification.getType(), notification.getBody()); @@ -58,14 +59,17 @@ class BindingDOMNotificationListenerAdapter implements DOMNotificationListener { return invokers.keySet(); } - public static Map createInvokerMapFor(final Class implClz) { + public static Map createInvokerMapFor( + final Class implClz) { final Map builder = new HashMap<>(); - for(final Class iface : implClz.getInterfaces()) { - if(NotificationListener.class.isAssignableFrom(iface) && BindingReflections.isBindingClass(iface)) { + for (final TypeToken ifaceToken : TypeToken.of(implClz).getTypes().interfaces()) { + Class iface = ifaceToken.getRawType(); + if (NotificationListener.class.isAssignableFrom(iface) && BindingReflections.isBindingClass(iface)) { @SuppressWarnings("unchecked") - final Class listenerType = (Class) iface; + final Class listenerType = + (Class) iface; final NotificationListenerInvoker invoker = NotificationListenerInvoker.from(listenerType); - for(final SchemaPath path : getNotificationTypes(listenerType)) { + for (final SchemaPath path : getNotificationTypes(listenerType)) { builder.put(path, invoker); } } @@ -77,8 +81,8 @@ class BindingDOMNotificationListenerAdapter implements DOMNotificationListener { // TODO: Investigate possibility and performance impact if we cache this or expose // it from NotificationListenerInvoker final Set ret = new HashSet<>(); - for(final Method method : type.getMethods()) { - if(BindingReflections.isNotificationCallback(method)) { + 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)); @@ -86,4 +90,4 @@ class BindingDOMNotificationListenerAdapter implements DOMNotificationListener { } return ret; } -} \ No newline at end of file +}