X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-dom-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fcodec%2Fimpl%2FChoiceCodecContext.java;h=8e0adc74b7e6bb314a16b24288cb9330a61f0e78;hb=3b18d17d6882c14b0f3542717e3ca539c0bc9593;hp=e4d15d497e2e49623ee84587716df832b76b44ff;hpb=1ef4bd8ca900db2b2d65a09bac22ddbc832642a7;p=mdsal.git diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ChoiceCodecContext.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ChoiceCodecContext.java index e4d15d497e..8e0adc74b7 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ChoiceCodecContext.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ChoiceCodecContext.java @@ -40,7 +40,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.binding.contract.Naming; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; @@ -117,8 +116,8 @@ final class ChoiceCodecContext extends CommonDataObjectCod ., 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(); for (var caseType : choiceType.validCaseChildren()) { @SuppressWarnings("unchecked") @@ -149,7 +148,7 @@ final class ChoiceCodecContext 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()); @@ -205,14 +204,12 @@ final class ChoiceCodecContext 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(); } - @SuppressWarnings("unchecked") @Override - public CommonDataObjectCodecContext streamChild(final Class childClass) { - final var child = byClass.get(childClass); - return child == null ? null : (CommonDataObjectCodecContext) child.get(); + CommonDataObjectCodecPrototype streamChildPrototype(final Class childClass) { + return byClass.get(childClass); } Iterable> getCaseChildrenClasses() { @@ -221,15 +218,12 @@ final class ChoiceCodecContext extends CommonDataObjectCod @Override public CodecContext yangPathArgumentChild(final YangInstanceIdentifier.PathArgument arg) { - final CommonDataObjectCodecPrototype cazeProto; - if (arg instanceof NodeIdentifierWithPredicates) { - cazeProto = byYangCaseChild.get(new NodeIdentifier(arg.getNodeType())); - } else { - cazeProto = byYangCaseChild.get(arg); - } + return ((CaseCodecContext) super.yangPathArgumentChild(arg)).yangPathArgumentChild(arg); + } - return childNonNull(cazeProto, arg, "Argument %s is not valid child of %s", arg, getSchema()).get() - .yangPathArgumentChild(arg); + @Override + CaseCodecPrototype yangChildSupplier(final NodeIdentifier arg) { + return byYangCaseChild.get(arg); } @Override @@ -244,7 +238,7 @@ final class ChoiceCodecContext extends CommonDataObjectCod return null; } final var caze = byYangCaseChild.get(first.name()); - return ((CaseCodecContext) caze.get()).deserialize(data); + return ((CaseCodecContext) caze.getCodecContext()).deserialize(data); } @Override @@ -275,7 +269,7 @@ final class ChoiceCodecContext extends CommonDataObjectCod return createCachingCodec(this, cacheSpecifier); } - DataContainerCodecContext getCaseByChildClass(final @NonNull Class type) { + DataContainerCodecContext getCaseByChildClass(final @NonNull Class type) { var result = byCaseChildClass.get(type); if (result == null) { // We have not found an unambiguous result, try ambiguous ones @@ -288,13 +282,14 @@ final class ChoiceCodecContext 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(); } /** @@ -311,7 +306,7 @@ final class ChoiceCodecContext extends CommonDataObjectCod checkArgument(DataContainer.class.isAssignableFrom(type), "Supplied type must be derived from DataContainer"); final var ret = new LinkedList>(); for (var method : type.getMethods()) { - AbstractDataContainerAnalysis.getYangModeledReturnType(method, Naming.GETTER_PREFIX) + DataContainerAnalysis.getYangModeledReturnType(method, Naming.GETTER_PREFIX) .ifPresent(entity -> ret.add((Class) entity)); } return ret;