Split this class out into CaseCodecPrototype top-level class.
Change-Id: I9b94a07f5b78bdec684d17ed0831e67a06cf0c0e
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
--- /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 org.opendaylight.mdsal.binding.dom.codec.impl.NodeCodecContext.CodecContextFactory;
+import org.opendaylight.mdsal.binding.runtime.api.CaseRuntimeType;
+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) {
+ super(cls, NodeIdentifier.create(type.statement().argument()), type, factory);
+ }
+
+ @Override
+ DataContainerCodecContext<?, CaseRuntimeType> createInstance() {
+ return new CaseNodeCodecContext<>(this);
+ }
+}
\ No newline at end of file
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final class CaseNodeCodecContext<D extends DataObject> extends DataObjectCodecContext<D, CaseRuntimeType> {
- static final class Prototype extends DataObjectCodecPrototype<CaseRuntimeType> {
- Prototype(final Class<?> cls, final CaseRuntimeType type, final CodecContextFactory factory) {
- super(cls, NodeIdentifier.create(type.statement().argument()), type, factory);
- }
-
- @Override
- DataContainerCodecContext<?, CaseRuntimeType> createInstance() {
- return new CaseNodeCodecContext<>(this);
- }
- }
-
- private CaseNodeCodecContext(final Prototype prototype) {
+ CaseNodeCodecContext(final CaseCodecPrototype prototype) {
super(prototype, CodecItemFactory.of(prototype.getBindingClass()));
}
final var factory = prototype.getFactory();
final var localCases = new HashSet<JavaTypeName>();
for (var caseType : choiceType.validCaseChildren()) {
- final var caseProto = new CaseNodeCodecContext.Prototype(loadCase(factory.getRuntimeContext(), caseType),
- caseType, factory);
+ @SuppressWarnings("unchecked")
+ final var caseClass = (Class<? extends DataObject>) loadCase(factory.getRuntimeContext(), caseType);
+ final var caseProto = new CaseCodecPrototype(caseClass, caseType, factory);
localCases.add(caseType.getIdentifier());
- byClassBuilder.put(caseProto.getBindingClass(), caseProto);
+ byClassBuilder.put(caseClass, caseProto);
// Updates collection of case children
- @SuppressWarnings("unchecked")
- final var cazeCls = (Class<? extends DataObject>) caseProto.getBindingClass();
- for (var cazeChild : getChildrenClasses(cazeCls)) {
+ for (var cazeChild : getChildrenClasses(caseClass)) {
childToCase.put(cazeChild, caseProto);
}
// Updates collection of YANG instance identifier to case
- for (var stmt : caseProto.getType().statement().effectiveSubstatements()) {
+ for (var stmt : caseType.statement().effectiveSubstatements()) {
if (stmt instanceof DataSchemaNode cazeChild) {
byYangCaseChildBuilder.put(NodeIdentifier.create(cazeChild.getQName()), caseProto);
}