Correct mdsal-binding-runtime-{api,spi} packages
[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.yangtools.yang.model.api.DataNodeContainer;
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  * <p>Some of this information are for example list of all available children for cases
21  * {@link #getChoiceCaseChildren(DataNodeContainer)}, since choices are augmentable and new choices may be introduced
22  * by additional models. Same goes for all possible augmentations.
23  */
24 @Beta
25 public final class DefaultBindingRuntimeContext extends AbstractBindingRuntimeContext {
26     private final @NonNull BindingRuntimeTypes runtimeTypes;
27     private final @NonNull ClassLoadingStrategy strategy;
28
29     private DefaultBindingRuntimeContext(final BindingRuntimeTypes runtimeTypes, final ClassLoadingStrategy strategy) {
30         this.runtimeTypes = requireNonNull(runtimeTypes);
31         this.strategy = requireNonNull(strategy);
32     }
33
34     /**
35      * Creates Binding Runtime Context from supplied class loading strategy and schema context.
36      *
37      * @param strategy Class loading strategy to retrieve generated Binding classes
38      * @param runtimeTypes Binding classes to YANG schema mapping
39      * @return A new instance
40      */
41     public static @NonNull DefaultBindingRuntimeContext create(final BindingRuntimeTypes runtimeTypes,
42             final ClassLoadingStrategy strategy) {
43         return new DefaultBindingRuntimeContext(runtimeTypes, strategy);
44     }
45
46     /**
47      * Returns a class loading strategy associated with this binding runtime context
48      * which is used to load classes.
49      *
50      * @return Class loading strategy.
51      */
52     @Override
53     public @NonNull ClassLoadingStrategy getStrategy() {
54         return strategy;
55     }
56
57     @Override
58     public @NonNull BindingRuntimeTypes getTypes() {
59         return runtimeTypes;
60     }
61 }