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