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 org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
14 import org.opendaylight.mdsal.binding.model.api.Type;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.yang.binding.Action;
17 import org.opendaylight.yangtools.yang.binding.Augmentation;
18 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
19 import org.opendaylight.yangtools.yang.binding.Rpc;
20 import org.opendaylight.yangtools.yang.binding.RpcInput;
21 import org.opendaylight.yangtools.yang.binding.RpcOutput;
22 import org.opendaylight.yangtools.yang.binding.YangData;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.common.YangDataName;
25 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
28 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
29 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
30 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
33 * Runtime Context for Java YANG Binding classes. It provides information derived from the backing effective model,
34 * which is not captured in generated classes (and hence cannot be obtained from {@code BindingReflections}.
37 // FIXME: refactor return to follow foo()/getFoo()/findFoo() naming
38 public interface BindingRuntimeContext extends EffectiveModelContextProvider, Immutable {
39 @NonNull BindingRuntimeTypes getTypes();
41 @NonNull <T> Class<T> loadClass(JavaTypeName type) throws ClassNotFoundException;
43 default @NonNull <T> Class<T> loadClass(final Type type) throws ClassNotFoundException {
44 return loadClass(type.getIdentifier());
48 default EffectiveModelContext getEffectiveModelContext() {
49 return getTypes().getEffectiveModelContext();
53 * Returns schema of augmentation.
55 * <p>Returned schema is schema definition from which augmentation class was generated.
56 * This schema is isolated from other augmentations. This means it contains
57 * augmentation definition as was present in original YANG module.
59 * <p>Children of returned schema does not contain any additional augmentations,
60 * which may be present in runtime for them, thus returned schema is unsuitable
61 * for use for validation of data.
63 * @param <T> Augmentation class type
64 * @param augClass Augmentation class
65 * @return Schema of augmentation or null if augmentation is not known in this context
66 * @throws NullPointerException if {@code augClass} is null
68 <T extends Augmentation<?>> @Nullable AugmentRuntimeType getAugmentationDefinition(Class<T> augClass);
71 * Returns defining {@link DataSchemaNode} for supplied class.
73 * <p>Returned schema is schema definition from which class was generated.
74 * This schema may be isolated from augmentations, if supplied class
75 * represent node, which was child of grouping or augmentation.
77 * <p>For getting augmentation schema from augmentation class use
78 * {@link #getAugmentationDefinition(Class)} instead.
80 * @param cls Class which represents list, container, choice or case.
81 * @return Schema node, from which class was generated.
83 @Nullable CompositeRuntimeType getSchemaDefinition(Class<?> cls);
85 @Nullable ActionRuntimeType getActionDefinition(Class<? extends Action<?, ?, ?>> cls);
87 @Nullable RpcRuntimeType getRpcDefinition(Class<? extends Rpc<?, ?>> cls);
90 * Returns schema ({@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition})
91 * from which supplied class was generated. Returned schema may be augmented with
92 * additional information, which was not available at compile type
93 * (e.g. third party augmentations).
95 * @param type Binding Class for which schema should be retrieved.
96 * @return Instance of generated type (definition of Java API), along with
97 * {@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition}
98 * which was used to generate supplied class.
100 @NonNull RuntimeType getTypeWithSchema(Class<?> type);
102 @NonNull Class<? extends RpcInput> getRpcInput(QName rpcName);
104 @NonNull Class<? extends RpcOutput> getRpcOutput(QName rpcName);
106 // FIXME: 9.0.0: this needs to accept an EffectiveStatementInference
107 @NonNull Class<?> getClassForSchema(Absolute schema);
109 @NonNull Class<? extends BaseIdentity> getIdentityClass(QName input);
111 @NonNull Class<? extends YangData<?>> getYangDataClass(YangDataName templateName);