import static java.util.Objects.requireNonNull;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.mdsal.binding.runtime.api.ChoiceRuntimeType;
-import org.opendaylight.mdsal.binding.runtime.api.ContainerLikeRuntimeType;
-import org.opendaylight.mdsal.binding.runtime.api.ContainerRuntimeType;
-import org.opendaylight.mdsal.binding.runtime.api.ListRuntimeType;
-import org.opendaylight.mdsal.binding.runtime.api.RuntimeTypeContainer;
+import org.opendaylight.mdsal.binding.runtime.api.CompositeRuntimeType;
import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.Item;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.model.api.stmt.PresenceEffectiveStatement;
-// FIXME: abstract and sealed
-non-sealed class DataObjectCodecPrototype<T extends RuntimeTypeContainer> extends DataContainerCodecPrototype<T> {
+abstract sealed class DataObjectCodecPrototype<T extends CompositeRuntimeType> extends CommonDataObjectCodecPrototype<T>
+ permits CaseCodecPrototype, ContainerLikeCodecPrototype, ListCodecPrototype,
+ NotificationCodecContext.Prototype {
private final @NonNull NodeIdentifier yangArg;
+ // FIXME: this should not be needed
@SuppressWarnings("unchecked")
DataObjectCodecPrototype(final Class<?> cls, final NodeIdentifier yangArg, final T type,
final CodecContextFactory factory) {
DataObjectCodecPrototype(final Item<?> bindingArg, final NodeIdentifier yangArg, final T type,
final CodecContextFactory factory) {
- super(bindingArg, yangArg.getNodeType().getModule(), type, factory);
+ super(bindingArg, type, factory);
this.yangArg = requireNonNull(yangArg);
}
@Override
- final NodeIdentifier getYangArg() {
+ final NodeIdentifier yangArg() {
return yangArg;
}
-
- @Override
- @SuppressWarnings({ "rawtypes", "unchecked" })
- DataContainerCodecContext<?, T> createInstance() {
- final var type = getType();
- if (type instanceof ContainerLikeRuntimeType containerLike) {
- if (containerLike instanceof ContainerRuntimeType container
- && container.statement().findFirstEffectiveSubstatement(PresenceEffectiveStatement.class)
- .isEmpty()) {
- return new NonPresenceContainerNodeCodecContext(this);
- }
- return new ContainerNodeCodecContext(this);
- } else if (type instanceof ListRuntimeType) {
- return Identifiable.class.isAssignableFrom(getBindingClass())
- ? KeyedListNodeCodecContext.create((DataContainerCodecPrototype<ListRuntimeType>) this)
- : new ListNodeCodecContext(this);
- } else if (type instanceof ChoiceRuntimeType) {
- return new ChoiceNodeCodecContext(this);
- }
- throw new IllegalArgumentException("Unsupported type " + getBindingClass() + " " + type);
- }
-}
\ No newline at end of file
+}