2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.runtime.api;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableMap;
13 import java.util.Map.Entry;
14 import java.util.Optional;
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;
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}.
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.
48 // FIXME: refactor return to follow foo()/getFoo()/findFoo() naming
49 public interface BindingRuntimeContext extends EffectiveModelContextProvider, Immutable {
50 @NonNull BindingRuntimeTypes getTypes();
52 @NonNull <T> Class<T> loadClass(Type type) throws ClassNotFoundException;
55 default EffectiveModelContext getEffectiveModelContext() {
56 return getTypes().getEffectiveModelContext();
60 * Returns schema of augmentation.
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.
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.
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
76 * @param augClass Augmentation class
77 * @return Schema of augmentation or null if augmentation is not known in this context
79 <T extends Augmentation<?>> @Nullable AugmentationSchemaNode getAugmentationDefinition(Class<T> augClass);
82 * Returns defining {@link DataSchemaNode} for supplied class.
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.
88 * <p>For getting augmentation schema from augmentation class use
89 * {@link #getAugmentationDefinition(Class)} instead.
91 * @param cls Class which represents list, container, choice or case.
92 * @return Schema node, from which class was generated.
94 @Nullable DataSchemaNode getSchemaDefinition(Class<?> cls);
96 // FIXME: document this thing and perhaps move it to BindingRuntimeTypes?
97 @Nullable DataSchemaNode findChildSchemaDefinition(DataNodeContainer parentSchema, QNameModule parentNamespace,
100 @Nullable ActionDefinition getActionDefinition(Class<? extends Action<?, ?, ?>> cls);
102 @Deprecated(forRemoval = true)
103 @Nullable Absolute getActionIdentifier(Class<? extends Action<?, ?, ?>> cls);
105 @NonNull Entry<AugmentationIdentifier, AugmentationSchemaNode> getResolvedAugmentationSchema(
106 DataNodeContainer target, Class<? extends Augmentation<?>> aug);
109 * Returns resolved case schema for supplied class.
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
115 * @throws IllegalArgumentException If supplied class does not represent case.
117 @NonNull Optional<CaseSchemaNode> getCaseSchemaDefinition(ChoiceSchemaNode schema, Class<?> childClass);
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).
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.
130 @NonNull Entry<GeneratedType, WithStatus> getTypeWithSchema(Class<?> type);
132 @NonNull Map<Type, Entry<Type, Type>> getChoiceCaseChildren(DataNodeContainer schema);
134 @NonNull Set<Class<?>> getCases(Class<?> choice);
136 @NonNull Class<?> getClassForSchema(SchemaNode childSchema);
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.
143 * @param container {@link DataNodeContainer} to examine
144 * @return a mapping from local {@link AugmentationIdentifier}s to their corresponding Binding augmentations
146 @NonNull ImmutableMap<AugmentationIdentifier, Type> getAvailableAugmentationTypes(DataNodeContainer container);
148 @NonNull Class<?> getIdentityClass(QName input);