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.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;
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}.
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.
47 public interface BindingRuntimeContext extends EffectiveModelContextProvider, Immutable {
49 * Returns a class loading strategy associated with this binding runtime context
50 * which is used to load classes.
52 * @return Class loading strategy.
54 @NonNull ClassLoadingStrategy getStrategy();
56 @NonNull BindingRuntimeTypes getTypes();
59 default EffectiveModelContext getEffectiveModelContext() {
60 return getTypes().getEffectiveModelContext();
64 * Returns schema of augmentation.
66 * <p>Returned schema is schema definition from which augmentation class was generated.
67 * This schema is isolated from other augmentations. This means it contains
68 * augmentation definition as was present in original YANG module.
70 * <p>Children of returned schema does not contain any additional augmentations,
71 * which may be present in runtime for them, thus returned schema is unsuitable
72 * for use for validation of data.
74 * <p>For retrieving {@link AugmentationSchemaNode}, which will contains
75 * full model for child nodes, you should use method
76 * {@link #getResolvedAugmentationSchema(DataNodeContainer, Class)}
77 * which will return augmentation schema derived from supplied augmentation target
80 * @param augClass Augmentation class
81 * @return Schema of augmentation or null if augmentaiton is not known in this context
82 * @throws IllegalArgumentException If supplied class is not an augmentation
84 @Nullable AugmentationSchemaNode getAugmentationDefinition(Class<?> augClass);
87 * Returns defining {@link DataSchemaNode} for supplied class.
89 * <p>Returned schema is schema definition from which class was generated.
90 * This schema may be isolated from augmentations, if supplied class
91 * represent node, which was child of grouping or augmentation.
93 * <p>For getting augmentation schema from augmentation class use
94 * {@link #getAugmentationDefinition(Class)} instead.
96 * @param cls Class which represents list, container, choice or case.
97 * @return Schema node, from which class was generated.
99 @Nullable DataSchemaNode getSchemaDefinition(Class<?> cls);
101 @Nullable ActionDefinition getActionDefinition(Class<? extends Action<?, ?, ?>> cls);
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);
138 @NonNull ImmutableMap<AugmentationIdentifier, Type> getAvailableAugmentationTypes(DataNodeContainer container);
140 @NonNull Class<?> getIdentityClass(QName input);