Rename opendaylight.mdsal.binding.model.ri
[yangtools.git] / binding / binding-runtime-api / src / main / java / org / opendaylight / yangtools / binding / runtime / api / BindingRuntimeContext.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.yangtools.binding.runtime.api;
9
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.yangtools.binding.lib.Action;
14 import org.opendaylight.yangtools.binding.lib.Augmentation;
15 import org.opendaylight.yangtools.binding.lib.BaseIdentity;
16 import org.opendaylight.yangtools.binding.lib.Rpc;
17 import org.opendaylight.yangtools.binding.lib.RpcInput;
18 import org.opendaylight.yangtools.binding.lib.RpcOutput;
19 import org.opendaylight.yangtools.binding.lib.YangData;
20 import org.opendaylight.yangtools.binding.model.api.JavaTypeName;
21 import org.opendaylight.yangtools.binding.model.api.Type;
22 import org.opendaylight.yangtools.concepts.Immutable;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.common.YangDataName;
25 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
28 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
29 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
30
31 /**
32  * Runtime Context for Java YANG Binding classes. It provides information derived from the backing effective model,
33  * which is not captured in generated classes (and hence cannot be obtained from {@code BindingReflections}.
34  */
35 @Beta
36 // FIXME: refactor return to follow foo()/getFoo()/findFoo() naming
37 public interface BindingRuntimeContext extends Immutable {
38
39     @NonNull BindingRuntimeTypes getTypes();
40
41     @NonNull <T> Class<T> loadClass(JavaTypeName type) throws ClassNotFoundException;
42
43     default @NonNull <T> Class<T> loadClass(final Type type) throws ClassNotFoundException {
44         return loadClass(type.getIdentifier());
45     }
46
47     default @NonNull EffectiveModelContext modelContext() {
48         return getTypes().modelContext();
49     }
50
51     /**
52      * Returns schema of augmentation.
53      *
54      * <p>Returned schema is schema definition from which augmentation class was generated.
55      * This schema is isolated from other augmentations. This means it contains
56      * augmentation definition as was present in original YANG module.
57      *
58      * <p>Children of returned schema does not contain any additional augmentations,
59      * which may be present in runtime for them, thus returned schema is unsuitable
60      * for use for validation of data.
61      *
62      * @param <T> Augmentation class type
63      * @param augClass Augmentation class
64      * @return Schema of augmentation or null if augmentation is not known in this context
65      * @throws NullPointerException if {@code augClass} is null
66      */
67     <T extends Augmentation<?>> @Nullable AugmentRuntimeType getAugmentationDefinition(Class<T> augClass);
68
69     /**
70      * Returns defining {@link DataSchemaNode} for supplied class.
71      *
72      * <p>Returned schema is schema definition from which class was generated.
73      * This schema may be isolated from augmentations, if supplied class
74      * represent node, which was child of grouping or augmentation.
75      *
76      * <p>For getting augmentation schema from augmentation class use
77      * {@link #getAugmentationDefinition(Class)} instead.
78      *
79      * @param cls Class which represents list, container, choice or case.
80      * @return Schema node, from which class was generated.
81      */
82     @Nullable CompositeRuntimeType getSchemaDefinition(Class<?> cls);
83
84     @Nullable ActionRuntimeType getActionDefinition(Class<? extends Action<?, ?, ?>> cls);
85
86     @Nullable RpcRuntimeType getRpcDefinition(Class<? extends Rpc<?, ?>> cls);
87
88     /**
89      * Returns schema ({@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition})
90      * from which supplied class was generated. Returned schema may be augmented with
91      * additional information, which was not available at compile type
92      * (e.g. third party augmentations).
93      *
94      * @param type Binding Class for which schema should be retrieved.
95      * @return Instance of generated type (definition of Java API), along with
96      *     {@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition}
97      *     which was used to generate supplied class.
98      */
99     @NonNull RuntimeType getTypeWithSchema(Class<?> type);
100
101     @NonNull Class<? extends RpcInput> getRpcInput(QName rpcName);
102
103     @NonNull Class<? extends RpcOutput> getRpcOutput(QName rpcName);
104
105     // FIXME: 9.0.0: this needs to accept an EffectiveStatementInference
106     @NonNull Class<?> getClassForSchema(Absolute schema);
107
108     @NonNull Class<? extends BaseIdentity> getIdentityClass(QName input);
109
110     @NonNull Class<? extends YangData<?>> getYangDataClass(YangDataName templateName);
111 }