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