Retain protype in DataContainerCodecContext
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / ChoiceCodecContext.java
index 9e55f2da29a157b1e58fcbefdad02380f14f2c19..8e0adc74b7e6bb314a16b24288cb9330a61f0e78 100644 (file)
@@ -116,8 +116,8 @@ final class ChoiceCodecContext<D extends DataObject> extends CommonDataObjectCod
             .<Class<?>, CommonDataObjectCodecPrototype<?>>build();
 
         // Load case statements valid in this choice and keep track of their names
-        final var choiceType = prototype.getType();
-        final var factory = prototype.getFactory();
+        final var choiceType = prototype.runtimeType();
+        final var factory = prototype.contextFactory();
         final var localCases = new HashSet<JavaTypeName>();
         for (var caseType : choiceType.validCaseChildren()) {
             @SuppressWarnings("unchecked")
@@ -148,7 +148,7 @@ final class ChoiceCodecContext<D extends DataObject> extends CommonDataObjectCod
             if (cases.size() != 1) {
                 // Sort all possibilities by their FQCN to retain semi-predictable results
                 final var list = new ArrayList<>(entry.getValue());
-                list.sort(Comparator.comparing(proto -> proto.getBindingClass().getCanonicalName()));
+                list.sort(Comparator.comparing(proto -> proto.javaClass().getCanonicalName()));
                 ambiguousByCaseBuilder.putAll(entry.getKey(), list);
             } else {
                 unambiguousByCaseBuilder.put(entry.getKey(), cases.iterator().next());
@@ -204,7 +204,7 @@ final class ChoiceCodecContext<D extends DataObject> extends CommonDataObjectCod
     @Override
     public WithStatus getSchema() {
         // FIXME: Bad cast, we should be returning an EffectiveStatement perhaps?
-        return (WithStatus) type().statement();
+        return (WithStatus) prototype().runtimeType().statement();
     }
 
     @Override
@@ -238,7 +238,7 @@ final class ChoiceCodecContext<D extends DataObject> extends CommonDataObjectCod
             return null;
         }
         final var caze = byYangCaseChild.get(first.name());
-        return ((CaseCodecContext<D>) caze.get()).deserialize(data);
+        return ((CaseCodecContext<D>) caze.getCodecContext()).deserialize(data);
     }
 
     @Override
@@ -269,7 +269,7 @@ final class ChoiceCodecContext<D extends DataObject> extends CommonDataObjectCod
         return createCachingCodec(this, cacheSpecifier);
     }
 
-    DataContainerCodecContext<?, ?> getCaseByChildClass(final @NonNull Class<? extends DataObject> type) {
+    DataContainerCodecContext<?, ?, ?> getCaseByChildClass(final @NonNull Class<? extends DataObject> type) {
         var result = byCaseChildClass.get(type);
         if (result == null) {
             // We have not found an unambiguous result, try ambiguous ones
@@ -282,13 +282,14 @@ final class ChoiceCodecContext<D extends DataObject> extends CommonDataObjectCod
                         Ambiguous reference {} to child of {} resolved to {}, the first case in {} This mapping is \
                         not guaranteed to be stable and is subject to variations based on runtime circumstances. \
                         Please see the stack trace for hints about the source of ambiguity.""",
-                        type, bindingArg(), result.getBindingClass(),
-                        Lists.transform(inexact, CommonDataObjectCodecPrototype::getBindingClass), new Throwable());
+                        type, bindingArg(), result.javaClass(),
+                        Lists.transform(inexact, CommonDataObjectCodecPrototype::javaClass), new Throwable());
                 }
             }
         }
 
-        return childNonNull(result, type, "Class %s is not child of any cases for %s", type, bindingArg()).get();
+        return childNonNull(result, type, "Class %s is not child of any cases for %s", type, bindingArg())
+            .getCodecContext();
     }
 
     /**