9fbc08ec44586ae1582565155a41d3ab57eab828
[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
16 /**
17  * A prototype for codecs dealing with {@link DataContainer}s.
18  *
19  * @param <C> {@link CodecContext} type
20  * @param <R> {@link CompositeRuntimeType} type
21  */
22 abstract sealed class DataContainerPrototype<C extends CodecContext, R extends CompositeRuntimeType>
23         extends LazyCodecContextSupplier<C> permits CommonDataObjectCodecPrototype {
24     private final @NonNull CodecContextFactory contextFactory;
25     private final @NonNull R runtimeType;
26
27     DataContainerPrototype(final CodecContextFactory contextFactory, final R runtimeType) {
28         this.contextFactory = requireNonNull(contextFactory);
29         this.runtimeType = requireNonNull(runtimeType);
30     }
31
32     /**
33      * Return the {@link CodecContextFactory} associated with this prototype.
34      *
35      * @return the context factory associated with this prototype
36      */
37     final @NonNull CodecContextFactory contextFactory() {
38         return contextFactory;
39     }
40
41     /**
42      * Return associated run-time type.
43      *
44      * @return associated run-time type
45      */
46     final @NonNull R runtimeType() {
47         return runtimeType;
48     }
49
50     /**
51      * Return the generated binding class this prototype corresponds to.
52      *
53      * @return the generated binding class this prototype corresponds to
54      */
55     abstract @NonNull Class<? extends DataContainer> javaClass();
56 }