2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.dom.codec.impl;
10 import static java.util.Objects.requireNonNull;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.binding.DataObjectStep;
14 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
15 import org.opendaylight.yangtools.yang.model.api.AddedByUsesAware;
16 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
18 sealed class CodecItemFactory {
19 private static final class Case extends CodecItemFactory {
20 private final Class<?> bindingClass;
22 Case(final Class<?> bindingClass) {
23 this.bindingClass = requireNonNull(bindingClass);
27 @SuppressWarnings({ "rawtypes", "unchecked" })
28 DataObjectStep<?> createItem(final Class<?> childClass, final EffectiveStatement<?, ?> childSchema) {
29 // FIXME: MDSAL-697: see overridden method for further guidance
30 return childSchema instanceof AddedByUsesAware aware && aware.isAddedByUses()
31 ? InstanceIdentifier.createStep((Class) bindingClass, (Class) childClass)
32 : super.createItem(childClass, childSchema);
36 private static final @NonNull CodecItemFactory DEFAULT = new CodecItemFactory();
38 private CodecItemFactory() {
42 // FIXME: MDSAL-697: move this method into BindingRuntimeContext
43 // This method is only called from loadChildPrototype() and exists only to be overridden by
44 // CaseNodeCodecContext. Since we are providing childClass and our schema to BindingRuntimeContext and
45 // receiving childSchema from it via findChildSchemaDefinition, we should be able to receive the equivalent
46 // of Map.Entry<Item, DataSchemaNode>, along with the override we create here. One more input we may need to
47 // provide is our bindingClass().
48 DataObjectStep<?> createItem(final Class<?> childClass, final EffectiveStatement<?, ?> childSchema) {
49 return InstanceIdentifier.createStep((Class) childClass);
52 static @NonNull CodecItemFactory of() {
56 static @NonNull CodecItemFactory of(final Class<?> bindingClass) {
57 return new Case(bindingClass);