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 @Nullable Absolute getActionIdentifier(Class<? extends Action<?, ?, ?>> cls);
104 @NonNull Entry<AugmentationIdentifier, AugmentationSchemaNode> getResolvedAugmentationSchema(
105 DataNodeContainer target, Class<? extends Augmentation<?>> aug);
108 * Returns resolved case schema for supplied class.
110 * @param schema Resolved parent choice schema
111 * @param childClass Class representing case.
112 * @return Optionally a resolved case schema,.empty if the choice is not legal in
114 * @throws IllegalArgumentException If supplied class does not represent case.
116 @NonNull Optional<CaseSchemaNode> getCaseSchemaDefinition(ChoiceSchemaNode schema, Class<?> childClass);
119 * Returns schema ({@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition})
120 * from which supplied class was generated. Returned schema may be augmented with
121 * additional information, which was not available at compile type
122 * (e.g. third party augmentations).
124 * @param type Binding Class for which schema should be retrieved.
125 * @return Instance of generated type (definition of Java API), along with
126 * {@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition}
127 * which was used to generate supplied class.
129 @NonNull Entry<GeneratedType, WithStatus> getTypeWithSchema(Class<?> type);
131 @NonNull Map<Type, Entry<Type, Type>> getChoiceCaseChildren(DataNodeContainer schema);
133 @NonNull Set<Class<?>> getCases(Class<?> choice);
135 @NonNull Class<?> getClassForSchema(SchemaNode childSchema);
137 @NonNull ImmutableMap<AugmentationIdentifier, Type> getAvailableAugmentationTypes(DataNodeContainer container);
139 @NonNull Class<?> getIdentityClass(QName input);