Reduce code duplication a tiny bit 13/97913/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 15 Oct 2021 19:55:51 +0000 (21:55 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 15 Oct 2021 19:57:11 +0000 (21:57 +0200)
The 'else' part of CaseNodeCodecContext's return is the same as
overridden method, hence call super instead of duplicating code.

Also add a few FIXMEs to guide our intent going forward.

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

index cabd5b97ca7a935ccb919abd6e7e11a0ad1a37ac..4dda319a073a7d8bbb553e664aeed24935e5b384 100644 (file)
@@ -28,8 +28,9 @@ final class CaseNodeCodecContext<D extends DataObject> extends DataObjectCodecCo
     @Override
     @SuppressWarnings({ "unchecked", "rawtypes" })
     Item<?> createBindingArg(final Class<?> childClass, final DataSchemaNode childSchema) {
+        // FIXME: MDSAL-697: see overridden method for further guidance
         return childSchema.isAddedByUses() ? Item.of((Class)getBindingClass(), (Class)childClass)
-                : Item.of((Class<? extends DataObject>) childClass);
+            : super.createBindingArg(childClass, childSchema);
     }
 
     @Override
index ccaddc55dd71f5fd68384471b99a6ce3f24d715f..295146b5c05af081fbdb769e2c76299ad4847174 100644 (file)
@@ -269,12 +269,18 @@ public abstract class DataObjectCodecContext<D extends DataObject, T extends Dat
     }
 
     private DataContainerCodecPrototype<?> loadChildPrototype(final Class<?> childClass) {
-        final DataSchemaNode nonNullChild = childNonNull(
+        final DataSchemaNode childSchema = childNonNull(
             factory().getRuntimeContext().findChildSchemaDefinition(getSchema(), namespace(), childClass), childClass,
             "Node %s does not have child named %s", getSchema(), childClass);
-        return DataContainerCodecPrototype.from(createBindingArg(childClass, nonNullChild), nonNullChild, factory());
+        return DataContainerCodecPrototype.from(createBindingArg(childClass, childSchema), childSchema, factory());
     }
 
+    // FIXME: MDSAL-697: move this method into BindingRuntimeContext
+    //                   This method is only called from loadChildPrototype() and exists only to be overridden by
+    //                   CaseNodeCodecContext. Since we are providing childClass and our schema to BindingRuntimeContext
+    //                   and receiving childSchema from it via findChildSchemaDefinition, we should be able to receive
+    //                   the equivalent of Map.Entry<Item, DataSchemaNode>, along with the override we create here. One
+    //                   more input we may need to provide is our bindingClass().
     @SuppressWarnings("unchecked")
     Item<?> createBindingArg(final Class<?> childClass, final DataSchemaNode childSchema) {
         return Item.of((Class<? extends DataObject>) childClass);