}
AugmentationCodecContext(final AugmentationCodecPrototype<A> prototype) {
- this(prototype, new DataContainerAnalysis<>(prototype, CodecItemFactory.of()));
+ this(prototype, new DataContainerAnalysis<>(prototype));
}
@Override
import java.util.List;
import org.opendaylight.mdsal.binding.runtime.api.CaseRuntimeType;
+import org.opendaylight.yangtools.yang.binding.ChoiceIn;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.DataObjectStep;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-final class CaseCodecContext<D extends DataObject> extends DataObjectCodecContext<D, CaseRuntimeType> {
- CaseCodecContext(final CaseCodecPrototype prototype) {
- super(prototype, CodecItemFactory.of(prototype.javaClass()));
+final class CaseCodecContext<C extends ChoiceIn<?> & DataObject> extends DataObjectCodecContext<C, CaseRuntimeType> {
+ CaseCodecContext(final CaseCodecPrototype<C> prototype) {
+ super(prototype, prototype.javaClass());
}
@Override
}
@Override
- public D deserialize(final NormalizedNode data) {
+ public C deserialize(final NormalizedNode data) {
return createBindingProxy(checkDataArgument(ChoiceNode.class, data));
}
package org.opendaylight.mdsal.binding.dom.codec.impl;
import org.opendaylight.mdsal.binding.runtime.api.CaseRuntimeType;
+import org.opendaylight.yangtools.yang.binding.ChoiceIn;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-final class CaseCodecPrototype extends DataObjectCodecPrototype<CaseRuntimeType> {
- CaseCodecPrototype(final Class<?> cls, final CaseRuntimeType type, final CodecContextFactory factory) {
+final class CaseCodecPrototype<C extends ChoiceIn<?> & DataObject> extends DataObjectCodecPrototype<CaseRuntimeType> {
+ CaseCodecPrototype(final Class<C> cls, final CaseRuntimeType type, final CodecContextFactory factory) {
super(cls, NodeIdentifier.create(type.statement().argument()), type, factory);
}
+++ /dev/null
-/*
- * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.binding.dom.codec.impl;
-
-import static java.util.Objects.requireNonNull;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.binding.DataObjectStep;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.model.api.AddedByUsesAware;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-
-sealed class CodecItemFactory {
- private static final class Case extends CodecItemFactory {
- private final Class<?> bindingClass;
-
- Case(final Class<?> bindingClass) {
- this.bindingClass = requireNonNull(bindingClass);
- }
-
- @Override
- @SuppressWarnings({ "rawtypes", "unchecked" })
- DataObjectStep<?> createItem(final Class<?> childClass, final EffectiveStatement<?, ?> childSchema) {
- // FIXME: MDSAL-697: see overridden method for further guidance
- return childSchema instanceof AddedByUsesAware aware && aware.isAddedByUses()
- ? InstanceIdentifier.createStep((Class) bindingClass, (Class) childClass)
- : super.createItem(childClass, childSchema);
- }
- }
-
- private static final @NonNull CodecItemFactory DEFAULT = new CodecItemFactory();
-
- private CodecItemFactory() {
- // Hidden on purpose
- }
-
- // 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().
- DataObjectStep<?> createItem(final Class<?> childClass, final EffectiveStatement<?, ?> childSchema) {
- return InstanceIdentifier.createStep((Class) childClass);
- }
-
- static @NonNull CodecItemFactory of() {
- return DEFAULT;
- }
-
- static @NonNull CodecItemFactory of(final Class<?> bindingClass) {
- return new Case(bindingClass);
- }
-}
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verify;
import static com.google.common.base.Verify.verifyNotNull;
+import static java.util.Objects.requireNonNull;
import com.google.common.collect.ImmutableMap;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
import org.opendaylight.mdsal.binding.runtime.api.ChoiceRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.CompositeRuntimeType;
import org.opendaylight.yangtools.util.ClassLoaderUtils;
import org.opendaylight.yangtools.yang.binding.ChoiceIn;
import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.DataObjectStep;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.OpaqueObject;
import org.opendaylight.yangtools.yang.binding.contract.Naming;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.model.api.AddedByUsesAware;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PresenceEffectiveStatement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final @NonNull ImmutableMap<Method, ValueNodeCodecContext> leafContexts;
final @NonNull ImmutableMap<Class<?>, PropertyInfo> daoProperties;
- DataContainerAnalysis(final CommonDataObjectCodecPrototype<R> prototype, final CodecItemFactory itemFactory) {
- this(prototype.javaClass(), prototype.runtimeType(), prototype.contextFactory(), itemFactory);
+ DataContainerAnalysis(final CommonDataObjectCodecPrototype<R> prototype) {
+ this(prototype.javaClass(), prototype.runtimeType(), prototype.contextFactory(), null);
+ }
+
+ DataContainerAnalysis(final CommonDataObjectCodecPrototype<R> prototype,
+ final Class<? extends DataObject> caseClass) {
+ this(prototype.javaClass(), prototype.runtimeType(), prototype.contextFactory(), requireNonNull(caseClass));
}
DataContainerAnalysis(final Class<?> bindingClass, final R runtimeType, final CodecContextFactory factory,
- final CodecItemFactory itemFactory) {
+ final @Nullable Class<? extends DataObject> caseClass) {
leafContexts = factory.getLeafNodes(bindingClass, runtimeType.statement());
// Reflection-based on the passed class
// Record getter method
daoPropertiesBuilder.put(retClass, new PropertyInfo.Getter(method));
- final var childProto = getChildPrototype(runtimeType, factory, itemFactory, retClass);
+ final var childProto = getChildPrototype(runtimeType, factory, caseClass, retClass);
byStreamClassBuilder.put(childProto.javaClass(), childProto);
byYangBuilder.put(childProto.yangArg(), childProto);
}
private static @NonNull DataContainerPrototype<?, ?> getChildPrototype(final CompositeRuntimeType type,
- final CodecContextFactory factory, final CodecItemFactory itemFactory,
+ final CodecContextFactory factory, final @Nullable Class<? extends DataObject> caseClass,
final Class<? extends DataContainer> childClass) {
final var child = type.bindingChild(JavaTypeName.create(childClass));
if (child == null) {
return new ChoiceCodecPrototype<>(factory, choice, childClass.asSubclass(ChoiceIn.class));
}
- final var item = itemFactory.createItem(childClass, child.statement());
+ final var item = createItem(caseClass, childClass, child.statement());
if (child instanceof ContainerLikeRuntimeType containerLike) {
if (child instanceof ContainerRuntimeType container
&& container.statement().findFirstEffectiveSubstatement(PresenceEffectiveStatement.class).isEmpty()) {
}
}
+ // 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().
+ private static @NonNull DataObjectStep<?> createItem(final @Nullable Class<? extends DataObject> caseClass,
+ final Class<?> childClass, final EffectiveStatement<?, ?> childSchema) {
+ return caseClass != null && childSchema instanceof AddedByUsesAware aware && aware.isAddedByUses()
+ ? InstanceIdentifier.createStep((Class) caseClass, (Class) childClass)
+ : InstanceIdentifier.createStep((Class) childClass);
+ }
+
// FIXME: MDSAL-780: these methods perform analytics using java.lang.reflect to acquire the basic shape of the
// class. This is not exactly AOT friendly, as most of the information should be provided by
// CompositeRuntimeType.
private volatile ImmutableMap<Class<?>, CommonDataObjectCodecPrototype<?>> mismatchedAugmented = ImmutableMap.of();
DataObjectCodecContext(final CommonDataObjectCodecPrototype<T> prototype) {
- this(prototype, CodecItemFactory.of());
+ this(prototype, new DataContainerAnalysis<>(prototype), null);
}
- DataObjectCodecContext(final CommonDataObjectCodecPrototype<T> prototype, final CodecItemFactory itemFactory) {
- this(prototype, new DataContainerAnalysis<>(prototype, itemFactory), null);
+ DataObjectCodecContext(final CommonDataObjectCodecPrototype<T> prototype,
+ final Class<? extends DataObject> caseClass) {
+ this(prototype, new DataContainerAnalysis<>(prototype, caseClass), null);
}
DataObjectCodecContext(final CommonDataObjectCodecPrototype<T> prototype, final Method keyMethod) {
- this(prototype, new DataContainerAnalysis<>(prototype, CodecItemFactory.of()), keyMethod);
+ this(prototype, new DataContainerAnalysis<>(prototype), keyMethod);
}
private DataObjectCodecContext(final CommonDataObjectCodecPrototype<T> prototype,
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) {
- this(InstanceIdentifier.createStep((Class<? extends DataObject>) cls), yangArg, type, factory);
+ this(InstanceIdentifier.createStep(cls.asSubclass(DataObject.class)), yangArg, type, factory);
}
DataObjectCodecPrototype(final DataObjectStep<?> bindingArg, final NodeIdentifier yangArg, final T type,