Cleanup findChildSchemaDefinition() 07/97907/3
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 15 Oct 2021 13:46:04 +0000 (15:46 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 15 Oct 2021 13:58:40 +0000 (15:58 +0200)
Now that we have the search and codec check split out, we can clean up
some of the logic to ditch if-else blocks. Also fixes a potential NPE.

Change-Id: I2a341d06bd3abfc39d7ecfaaf876e6617ddea037
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-runtime-api/src/main/java/org/opendaylight/mdsal/binding/runtime/api/AbstractBindingRuntimeContext.java

index 0eb80331245e9a6ea0084c2ea8ff4f6c75f15f3a..876cdd42a79f09cfeca7f7a9cd712556140a441a 100644 (file)
@@ -95,39 +95,33 @@ public abstract class AbstractBindingRuntimeContext implements BindingRuntimeCon
     public final DataSchemaNode findChildSchemaDefinition(final DataNodeContainer parentSchema,
             final QNameModule parentNamespace, final Class<?> childClass) {
         final DataSchemaNode origDef = getSchemaDefinition(childClass);
-        // Direct instantiation or use in same module in which grouping was defined.
-        DataSchemaNode sameName;
-        try {
-            sameName = parentSchema.dataChildByName(origDef.getQName());
-        } catch (final IllegalArgumentException e) {
-            LOG.trace("Failed to find schema for {}", origDef, e);
-            sameName = null;
+        if (origDef == null) {
+            // Weird, the child does not have an associated definition
+            return null;
         }
 
-        final DataSchemaNode childSchema;
+        // Direct instantiation or use in same module in which grouping was defined.
+        final QName origName = origDef.getQName();
+        final DataSchemaNode sameName = parentSchema.dataChildByName(origName);
         if (sameName != null) {
             // Check if it is:
             // - exactly same schema node, or
             // - instantiated node was added via uses statement and is instantiation of same grouping
             if (origDef.equals(sameName) || origDef.equals(getRootOriginalIfPossible(sameName))) {
-                childSchema = sameName;
-            } else {
-                // Node has same name, but clearly is different
-                childSchema = null;
-            }
-        } else {
-            // We are looking for instantiation via uses in other module
-            final QName instantiedName = origDef.getQName().bindTo(parentNamespace);
-            final DataSchemaNode potential = parentSchema.dataChildByName(instantiedName);
-            // We check if it is really instantiated from same definition as class was derived
-            if (potential != null && origDef.equals(getRootOriginalIfPossible(potential))) {
-                childSchema = potential;
-            } else {
-                childSchema = null;
+                return sameName;
             }
+
+            // Node has same name, but clearly is different
+            return null;
         }
 
-        return childSchema;
+        // We are looking for instantiation via uses in other module
+        final DataSchemaNode potential = parentSchema.dataChildByName(origName.bindTo(parentNamespace));
+        // We check if it is really instantiated from same definition as class was derived
+        if (potential != null && origDef.equals(getRootOriginalIfPossible(potential))) {
+            return potential;
+        }
+        return null;
     }
 
     private static @Nullable SchemaNode getRootOriginalIfPossible(final SchemaNode data) {