Reparent ChoiceCodecContext
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / DataContainerPrototype.java
1 /*
2  * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.dom.codec.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.mdsal.binding.runtime.api.CompositeRuntimeType;
14 import org.opendaylight.yangtools.yang.binding.DataContainer;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
16
17 /**
18  * A prototype for codecs dealing with {@link DataContainer}s.
19  *
20  * @param <C> {@link CodecContext} type
21  * @param <R> {@link CompositeRuntimeType} type
22  */
23 abstract sealed class DataContainerPrototype<C extends DataContainerCodecContext<?, R, ?>,
24         R extends CompositeRuntimeType>
25         extends LazyCodecContextSupplier<C> permits ChoiceCodecPrototype, CommonDataObjectCodecPrototype {
26     private final @NonNull CodecContextFactory contextFactory;
27     private final @NonNull R runtimeType;
28
29     DataContainerPrototype(final CodecContextFactory contextFactory, final R runtimeType) {
30         this.contextFactory = requireNonNull(contextFactory);
31         this.runtimeType = requireNonNull(runtimeType);
32     }
33
34     /**
35      * Return the {@link CodecContextFactory} associated with this prototype.
36      *
37      * @return the context factory associated with this prototype
38      */
39     final @NonNull CodecContextFactory contextFactory() {
40         return contextFactory;
41     }
42
43     /**
44      * Return associated run-time type.
45      *
46      * @return associated run-time type
47      */
48     final @NonNull R runtimeType() {
49         return runtimeType;
50     }
51
52     /**
53      * Return the generated binding class this prototype corresponds to.
54      *
55      * @return the generated binding class this prototype corresponds to
56      */
57     abstract @NonNull Class<? extends DataContainer> javaClass();
58
59     abstract @NonNull NodeIdentifier yangArg();
60 }