Use bindingChild() to locate notifications 63/109363/6
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 17 Dec 2023 01:46:40 +0000 (02:46 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 19 Dec 2023 08:25:53 +0000 (09:25 +0100)
BindingRuntimeTypes provides an interface to directly find
NotificationRuntimeType based on its name. Use it instead of dancing
around with reflection.

JIRA: MDSAL-781
Change-Id: I3ba1a06d8dc07700bd86a3288116989a1a445138
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingCodecContext.java

index 08997deaf3537cc4e48645d2a4422ce129c458eb..05bf47d62633e734fedefecb00fdcd49c927e3b4 100644 (file)
@@ -275,15 +275,13 @@ public final class BindingCodecContext extends AbstractBindingNormalizedNodeSeri
         .build(new CacheLoader<>() {
             @Override
             public NotificationCodecContext<?> load(final Class<?> key) {
-                // FIXME: sharpen check to an Notification.class
-                checkArgument(key.isInterface(), "Supplied class must be interface.");
-
-                // TODO: we should be able to work with bindingChild() instead of schemaTreeChild() here
-                final var qname = BindingReflections.findQName(key);
-                if (context.getTypes().schemaTreeChild(qname) instanceof NotificationRuntimeType type) {
-                    return new NotificationCodecContext<>(key, type, BindingCodecContext.this);
+                final var runtimeType = context.getTypes().bindingChild(JavaTypeName.create(key));
+                if (runtimeType instanceof NotificationRuntimeType notification) {
+                    return new NotificationCodecContext<>(key, notification, BindingCodecContext.this);
+                } if (runtimeType != null) {
+                    throw new IllegalArgumentException(key + " maps to unexpected " + runtimeType);
                 }
-                throw new IllegalArgumentException("Supplied " + key + " is not valid notification");
+                throw new IllegalArgumentException(key + " is not a known class");
             }
         });
     private final LoadingCache<Absolute, NotificationCodecContext<?>> notificationsByPath =