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.DataObject;
14 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.Item;
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 Item<?> 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 ? Item.of((Class) bindingClass, (Class) childClass) : super.createItem(childClass, childSchema);
35 private static final @NonNull CodecItemFactory DEFAULT = new CodecItemFactory();
37 private CodecItemFactory() {
41 // FIXME: MDSAL-697: move this method into BindingRuntimeContext
42 // This method is only called from loadChildPrototype() and exists only to be overridden by
43 // CaseNodeCodecContext. Since we are providing childClass and our schema to BindingRuntimeContext and
44 // receiving childSchema from it via findChildSchemaDefinition, we should be able to receive the equivalent
45 // of Map.Entry<Item, DataSchemaNode>, along with the override we create here. One more input we may need to
46 // provide is our bindingClass().
47 @SuppressWarnings("unchecked")
48 Item<?> createItem(final Class<?> childClass, final EffectiveStatement<?, ?> childSchema) {
49 return Item.of((Class<? extends DataObject>) childClass);
52 static @NonNull CodecItemFactory of() {
56 static @NonNull CodecItemFactory of(final Class<?> bindingClass) {
57 return new Case(bindingClass);