Rework BindingRuntimeTypes
[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.JavaTypeName;
15
16 /**
17  * Runtime Context for Java YANG Binding classes. It provides information derived from the backing effective model,
18  * which is not captured in generated classes (and hence cannot be obtained from {@code BindingReflections}.
19  */
20 @Beta
21 public final class DefaultBindingRuntimeContext extends AbstractBindingRuntimeContext {
22     private final @NonNull BindingRuntimeTypes runtimeTypes;
23     private final @NonNull ModuleInfoSnapshot moduleInfos;
24
25     public DefaultBindingRuntimeContext(final BindingRuntimeTypes runtimeTypes, final ModuleInfoSnapshot moduleInfos) {
26         this.runtimeTypes = requireNonNull(runtimeTypes);
27         this.moduleInfos = requireNonNull(moduleInfos);
28     }
29
30     @Override
31     public BindingRuntimeTypes getTypes() {
32         return runtimeTypes;
33     }
34
35     @Override
36     public <T> Class<T> loadClass(final JavaTypeName type) throws ClassNotFoundException {
37         return moduleInfos.loadClass(type.toString());
38     }
39 }