Separate out notification handling
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / SchemaRootCodecContext.java
index be48e153fd1820893683c14fca66ded6817fe4c0..bfa286ac54267f1aea8728fc8883c6a4c1636043 100644 (file)
@@ -61,13 +61,6 @@ final class SchemaRootCodecContext<D extends DataObject> extends DataContainerCo
         CacheBuilder.newBuilder().build(new CacheLoader<>() {
             @Override
             public DataContainerCodecContext<?, ?> load(final Class<? extends DataObject> key) {
-                if (Notification.class.isAssignableFrom(key)) {
-                    checkArgument(key.isInterface(), "Supplied class must be interface.");
-                    final QName qname = BindingReflections.findQName(key);
-                    final NotificationDefinition schema = getSchema().findNotification(qname).orElseThrow(
-                        () -> new IllegalArgumentException("Supplied " + key + " is not valid notification"));
-                    return new NotificationCodecContext<>(key, schema, factory());
-                }
                 return createDataTreeChildContext(key);
             }
         });
@@ -88,6 +81,18 @@ final class SchemaRootCodecContext<D extends DataObject> extends DataContainerCo
             }
         });
 
+    private final LoadingCache<Class<?>, NotificationCodecContext<?>> notificationsByClass = CacheBuilder.newBuilder()
+        .build(new CacheLoader<Class<?>, NotificationCodecContext<?>>() {
+            @Override
+            public NotificationCodecContext<?> load(final Class<?> key) {
+                checkArgument(key.isInterface(), "Supplied class must be interface.");
+                final QName qname = BindingReflections.findQName(key);
+                final NotificationDefinition schema = getSchema().findNotification(qname).orElseThrow(
+                    () -> new IllegalArgumentException("Supplied " + key + " is not valid notification"));
+                return new NotificationCodecContext<>(key, schema, factory());
+            }
+        });
+
     private final LoadingCache<Class<?>, ContainerNodeCodecContext<?>> rpcDataByClass = CacheBuilder.newBuilder()
         .build(new CacheLoader<Class<?>, ContainerNodeCodecContext<?>>() {
             @Override
@@ -205,7 +210,7 @@ final class SchemaRootCodecContext<D extends DataObject> extends DataContainerCo
     }
 
     NotificationCodecContext<?> getNotification(final Class<? extends Notification<?>> notification) {
-        return (NotificationCodecContext<?>) streamChild((Class<? extends DataObject>)notification);
+        return getOrRethrow(notificationsByClass, notification);
     }
 
     NotificationCodecContext<?> getNotification(final Absolute notification) {