a4c1da1e2b7ca01e82ba19452dc9507a6a334260
[mdsal.git] / binding / mdsal-binding-runtime-api / src / main / java / org / opendaylight / mdsal / binding / runtime / api / DefaultBindingRuntimeContext.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.runtime.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.binding.model.api.Type;
15 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
16
17 /**
18  * Runtime Context for Java YANG Binding classes. It provides information derived from the backing effective model,
19  * which is not captured in generated classes (and hence cannot be obtained from {@code BindingReflections}.
20  *
21  * <p>Some of this information are for example list of all available children for cases
22  * {@link #getChoiceCaseChildren(DataNodeContainer)}, since choices are augmentable and new choices may be introduced
23  * by additional models. Same goes for all possible augmentations.
24  */
25 @Beta
26 public final class DefaultBindingRuntimeContext extends AbstractBindingRuntimeContext {
27     private final @NonNull BindingRuntimeTypes runtimeTypes;
28     private final @NonNull ModuleInfoSnapshot moduleInfos;
29
30     public DefaultBindingRuntimeContext(final BindingRuntimeTypes runtimeTypes, final ModuleInfoSnapshot moduleInfos) {
31         this.runtimeTypes = requireNonNull(runtimeTypes);
32         this.moduleInfos = requireNonNull(moduleInfos);
33     }
34
35     @Override
36     public BindingRuntimeTypes getTypes() {
37         return runtimeTypes;
38     }
39
40     @Override
41     public <T> Class<T> loadClass(Type type) throws ClassNotFoundException {
42         return moduleInfos.loadClass(type.getFullyQualifiedName());
43     }
44 }