import org.opendaylight.mdsal.binding.runtime.api.CompositeRuntimeType;
import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.DataObjectStep;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
public abstract sealed class AbstractDataObjectCodecContext<D extends DataObject, T extends CompositeRuntimeType>
extends CommonDataObjectCodecContext<D, T>
permits AugmentationCodecContext, DataObjectCodecContext {
- private final ImmutableMap<Class<?>, CommonDataObjectCodecPrototype<?>> byBindingArgClass;
- private final ImmutableMap<Class<?>, CommonDataObjectCodecPrototype<?>> byStreamClass;
+ private final ImmutableMap<Class<?>, DataContainerPrototype<?, ?>> byBindingArgClass;
+ private final ImmutableMap<Class<?>, DataContainerPrototype<?, ?>> byStreamClass;
private final ImmutableMap<NodeIdentifier, CodecContextSupplier> byYang;
private final ImmutableMap<String, ValueNodeCodecContext> leafChild;
@Override
public final WithStatus getSchema() {
// FIXME: Bad cast, we should be returning an EffectiveStatement perhaps?
- return (WithStatus) type().statement();
+ return (WithStatus) prototype().runtimeType().statement();
}
@Override
- CommonDataObjectCodecPrototype<?> streamChildPrototype(final Class<?> childClass) {
+ DataContainerPrototype<?, ?> streamChildPrototype(final Class<?> childClass) {
return byStreamClass.get(childClass);
}
@Override
- public final CommonDataObjectCodecContext<?, ?> bindingPathArgumentChild(final InstanceIdentifier.PathArgument arg,
+ public final CommonDataObjectCodecContext<?, ?> bindingPathArgumentChild(final DataObjectStep<?> step,
final List<PathArgument> builder) {
- final var argType = arg.getType();
- final var context = childNonNull(pathChildPrototype(argType), argType,
- "Class %s is not valid child of %s", argType, getBindingClass())
+ final var type = step.type();
+ final var context = childNonNull(pathChildPrototype(type), type,
+ "Class %s is not valid child of %s", type, getBindingClass())
.getCodecContext();
- if (context instanceof ChoiceCodecContext<?> choice) {
- choice.addYangPathArgument(arg, builder);
-
- final var caseType = arg.getCaseType();
- final var type = arg.getType();
- final DataContainerCodecContext<?, ?> caze;
- if (caseType.isPresent()) {
- // Non-ambiguous addressing this should not pose any problems
- caze = choice.getStreamChild(caseType.orElseThrow());
- } else {
- caze = choice.getCaseByChildClass(type);
- }
-
- caze.addYangPathArgument(arg, builder);
- return caze.bindingPathArgumentChild(arg, builder);
+ context.addYangPathArgument(step, builder);
+ if (context instanceof CommonDataObjectCodecContext<?, ?> dataObject) {
+ return dataObject;
+ } else if (context instanceof ChoiceCodecContext<?> choice) {
+ return choice.bindingPathArgumentChild(step, builder);
+ } else {
+ throw new IllegalStateException("Unhandled context " + context);
}
- context.addYangPathArgument(arg, builder);
- return context;
}
- @Nullable CommonDataObjectCodecPrototype<?> pathChildPrototype(final @NonNull Class<? extends DataObject> argType) {
+ @Nullable DataContainerPrototype<?, ?> pathChildPrototype(final @NonNull Class<? extends DataObject> argType) {
return byBindingArgClass.get(argType);
}