Correct mdsal-binding-runtime-{api,spi} packages
[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 com.google.common.collect.ImmutableMap;
12 import java.util.Map;
13 import java.util.Map.Entry;
14 import java.util.Optional;
15 import java.util.Set;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.eclipse.jdt.annotation.Nullable;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
19 import org.opendaylight.mdsal.binding.model.api.Type;
20 import org.opendaylight.yangtools.concepts.Immutable;
21 import org.opendaylight.yangtools.yang.binding.Action;
22 import org.opendaylight.yangtools.yang.binding.Augmentation;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
25 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
26 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
29 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
30 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
31 import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
32 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
33 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
34 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
35 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
36
37 /**
38  * Runtime Context for Java YANG Binding classes. It provides information derived from the backing effective model,
39  * which is not captured in generated classes (and hence cannot be obtained from {@code BindingReflections}.
40  *
41  * <p>Some of this information are for example list of all available children for cases
42  * {@link #getChoiceCaseChildren(DataNodeContainer)}, since choices are augmentable and new choices may be introduced
43  * by additional models. Same goes for all possible augmentations.
44  */
45 @Beta
46 public interface BindingRuntimeContext extends EffectiveModelContextProvider, Immutable {
47     /**
48      * Returns a class loading strategy associated with this binding runtime context
49      * which is used to load classes.
50      *
51      * @return Class loading strategy.
52      */
53     @NonNull ClassLoadingStrategy getStrategy();
54
55     @NonNull BindingRuntimeTypes getTypes();
56
57     @Override
58     default EffectiveModelContext getEffectiveModelContext() {
59         return getTypes().getEffectiveModelContext();
60     }
61
62     /**
63      * Returns schema of augmentation.
64      *
65      * <p>Returned schema is schema definition from which augmentation class was generated.
66      * This schema is isolated from other augmentations. This means it contains
67      * augmentation definition as was present in original YANG module.
68      *
69      * <p>Children of returned schema does not contain any additional augmentations,
70      * which may be present in runtime for them, thus returned schema is unsuitable
71      * for use for validation of data.
72      *
73      * <p>For retrieving {@link AugmentationSchemaNode}, which will contains
74      * full model for child nodes, you should use method
75      * {@link #getResolvedAugmentationSchema(DataNodeContainer, Class)}
76      * which will return augmentation schema derived from supplied augmentation target
77      * schema.
78      *
79      * @param augClass Augmentation class
80      * @return Schema of augmentation or null if augmentaiton is not known in this context
81      * @throws IllegalArgumentException If supplied class is not an augmentation
82      */
83     @Nullable AugmentationSchemaNode getAugmentationDefinition(Class<?> augClass);
84
85     /**
86      * Returns defining {@link DataSchemaNode} for supplied class.
87      *
88      * <p>Returned schema is schema definition from which class was generated.
89      * This schema may be isolated from augmentations, if supplied class
90      * represent node, which was child of grouping or augmentation.
91      *
92      * <p>For getting augmentation schema from augmentation class use
93      * {@link #getAugmentationDefinition(Class)} instead.
94      *
95      * @param cls Class which represents list, container, choice or case.
96      * @return Schema node, from which class was generated.
97      */
98     @Nullable DataSchemaNode getSchemaDefinition(Class<?> cls);
99
100     @Nullable ActionDefinition getActionDefinition(Class<? extends Action<?, ?, ?>> cls);
101
102     @NonNull Entry<AugmentationIdentifier, AugmentationSchemaNode> getResolvedAugmentationSchema(
103             DataNodeContainer target, Class<? extends Augmentation<?>> aug);
104
105     /**
106      * Returns resolved case schema for supplied class.
107      *
108      * @param schema Resolved parent choice schema
109      * @param childClass Class representing case.
110      * @return Optionally a resolved case schema,.empty if the choice is not legal in
111      *         the given context.
112      * @throws IllegalArgumentException If supplied class does not represent case.
113      */
114     @NonNull Optional<CaseSchemaNode> getCaseSchemaDefinition(ChoiceSchemaNode schema, Class<?> childClass);
115
116     /**
117      * Returns schema ({@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition})
118      * from which supplied class was generated. Returned schema may be augmented with
119      * additional information, which was not available at compile type
120      * (e.g. third party augmentations).
121      *
122      * @param type Binding Class for which schema should be retrieved.
123      * @return Instance of generated type (definition of Java API), along with
124      *     {@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition}
125      *     which was used to generate supplied class.
126      */
127     @NonNull Entry<GeneratedType, WithStatus> getTypeWithSchema(Class<?> type);
128
129     @NonNull Map<Type, Entry<Type, Type>> getChoiceCaseChildren(DataNodeContainer schema);
130
131     @NonNull Set<Class<?>> getCases(Class<?> choice);
132
133     @NonNull Class<?> getClassForSchema(SchemaNode childSchema);
134
135     @NonNull ImmutableMap<AugmentationIdentifier, Type> getAvailableAugmentationTypes(DataNodeContainer container);
136
137     @NonNull Class<?> getIdentityClass(QName input);
138 }