Reparent ChoiceCodecContext
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / ChoiceCodecPrototype.java
1 /*
2  * Copyright (c) 2023 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.ChoiceRuntimeType;
14 import org.opendaylight.yangtools.yang.binding.ChoiceIn;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
16
17 /**
18  * A prototype for {@link ChoiceCodecContext}.
19  */
20 final class ChoiceCodecPrototype<T extends ChoiceIn<?>>
21         extends DataContainerPrototype<ChoiceCodecContext<T>, ChoiceRuntimeType> {
22     private final @NonNull NodeIdentifier yangArg;
23     private final @NonNull Class<T> javaClass;
24
25     ChoiceCodecPrototype(final CodecContextFactory contextFactory, final ChoiceRuntimeType runtimeType,
26             final Class<T> javaClass) {
27         super(contextFactory, runtimeType);
28         this.javaClass = requireNonNull(javaClass);
29         yangArg = NodeIdentifier.create(runtimeType.statement().argument());
30     }
31
32     @Override
33     Class<T> javaClass() {
34         return javaClass;
35     }
36
37     @Override
38     NodeIdentifier yangArg() {
39         return yangArg;
40     }
41
42     @Override
43     ChoiceCodecContext<T> createInstance() {
44         return new ChoiceCodecContext<>(this);
45     }
46 }