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