Do not use BindingReflections.findQName() 82/109382/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 19 Dec 2023 08:41:06 +0000 (09:41 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 19 Dec 2023 08:42:09 +0000 (09:42 +0100)
Use BindingRuntimeTypes to resolve the RuntimeType for both actions and
notifications, removing the need to use BindingReflections.findQName().

JIRA: MDSAL-781
Change-Id: Ic49189377a53d35367f0c4dcfac27b28bb6c77e8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/main/java/module-info.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/CurrentAdapterSerializer.java

index 40bca155a9ca0c57fb092e8bd43248323c9b8821..30d15ab216c17f6b270e89a5b1c0d6b3be7e2b85 100644 (file)
@@ -31,6 +31,7 @@ module org.opendaylight.mdsal.binding.dom.adapter {
     requires transitive org.opendaylight.mdsal.dom.api;
     requires transitive org.opendaylight.yangtools.yang.data.impl;
     requires org.opendaylight.mdsal.binding.dom.codec.api;
+    requires org.opendaylight.mdsal.binding.runtime.api;
     requires org.opendaylight.mdsal.binding.spec.util;
     requires org.opendaylight.mdsal.dom.spi;
     requires org.slf4j;
index 015d66c34d3639bfea2d4d2f49ca8c59755704c3..cad0c4fda686a081f4071a41ec026dfb696bdba3 100644 (file)
@@ -30,8 +30,9 @@ import org.opendaylight.mdsal.binding.api.InstanceNotificationSpec;
 import org.opendaylight.mdsal.binding.dom.codec.spi.BindingDOMCodecServices;
 import org.opendaylight.mdsal.binding.dom.codec.spi.ForwardingBindingDOMCodecServices;
 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
+import org.opendaylight.mdsal.binding.runtime.api.ActionRuntimeType;
 import org.opendaylight.mdsal.binding.runtime.api.InputRuntimeType;
-import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
+import org.opendaylight.mdsal.binding.runtime.api.NotificationRuntimeType;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -88,17 +89,29 @@ public final class CurrentAdapterSerializer extends ForwardingBindingDOMCodecSer
     }
 
     @NonNull Absolute getActionPath(final @NonNull ActionSpec<?, ?> spec) {
+        final var type = getRuntimeContext().getTypes().findSchema(JavaTypeName.create(spec.type()))
+            .orElseThrow(() -> new IllegalArgumentException("Action " + spec + " is not known"));
+        if (!(type instanceof ActionRuntimeType actionType)) {
+            throw new IllegalArgumentException("Action " + spec + " resolved to unexpected " + type);
+        }
+
         final var entry = resolvePath(spec.path());
         final var stack = entry.getKey();
-        final var stmt = stack.enterSchemaTree(BindingReflections.findQName(spec.type()).bindTo(entry.getValue()));
+        final var stmt = stack.enterSchemaTree(actionType.statement().argument().bindTo(entry.getValue()));
         verify(stmt instanceof ActionEffectiveStatement, "Action %s resolved to unexpected statement %s", spec, stmt);
         return stack.toSchemaNodeIdentifier();
     }
 
     @NonNull Absolute getNotificationPath(final @NonNull InstanceNotificationSpec<?, ?> spec) {
+        final var type = getRuntimeContext().getTypes().findSchema(JavaTypeName.create(spec.type()))
+            .orElseThrow(() -> new IllegalArgumentException("Notification " + spec + " is not known"));
+        if (!(type instanceof NotificationRuntimeType notifType)) {
+            throw new IllegalArgumentException("Notification " + spec + " resolved to unexpected " + type);
+        }
+
         final var entry = resolvePath(spec.path());
         final var stack = entry.getKey();
-        final var stmt = stack.enterSchemaTree(BindingReflections.findQName(spec.type()).bindTo(entry.getValue()));
+        final var stmt = stack.enterSchemaTree(notifType.statement().argument().bindTo(entry.getValue()));
         verify(stmt instanceof NotificationEffectiveStatement, "Notification %s resolved to unexpected statement %s",
             spec, stmt);
         return stack.toSchemaNodeIdentifier();