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.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
26 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
27 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
28 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
31 * Runtime Context for Java YANG Binding classes. It provides information derived from the backing effective model,
32 * which is not captured in generated classes (and hence cannot be obtained from {@code BindingReflections}.
35 // FIXME: refactor return to follow foo()/getFoo()/findFoo() naming
36 public interface BindingRuntimeContext extends EffectiveModelContextProvider, Immutable {
37 @NonNull BindingRuntimeTypes getTypes();
39 @NonNull <T> Class<T> loadClass(JavaTypeName type) throws ClassNotFoundException;
41 default @NonNull <T> Class<T> loadClass(final Type type) throws ClassNotFoundException {
42 return loadClass(type.getIdentifier());
46 default EffectiveModelContext getEffectiveModelContext() {
47 return getTypes().getEffectiveModelContext();
51 * Returns schema of augmentation.
53 * <p>Returned schema is schema definition from which augmentation class was generated.
54 * This schema is isolated from other augmentations. This means it contains
55 * augmentation definition as was present in original YANG module.
57 * <p>Children of returned schema does not contain any additional augmentations,
58 * which may be present in runtime for them, thus returned schema is unsuitable
59 * for use for validation of data.
61 * @param <T> Augmentation class type
62 * @param augClass Augmentation class
63 * @return Schema of augmentation or null if augmentation is not known in this context
64 * @throws NullPointerException if {@code augClass} is null
66 <T extends Augmentation<?>> @Nullable AugmentRuntimeType getAugmentationDefinition(Class<T> augClass);
69 * Returns defining {@link DataSchemaNode} for supplied class.
71 * <p>Returned schema is schema definition from which class was generated.
72 * This schema may be isolated from augmentations, if supplied class
73 * represent node, which was child of grouping or augmentation.
75 * <p>For getting augmentation schema from augmentation class use
76 * {@link #getAugmentationDefinition(Class)} instead.
78 * @param cls Class which represents list, container, choice or case.
79 * @return Schema node, from which class was generated.
81 @Nullable CompositeRuntimeType getSchemaDefinition(Class<?> cls);
83 @Nullable ActionRuntimeType getActionDefinition(Class<? extends Action<?, ?, ?>> cls);
85 @Nullable RpcRuntimeType getRpcDefinition(Class<? extends Rpc<?, ?>> cls);
88 * Returns schema ({@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition})
89 * from which supplied class was generated. Returned schema may be augmented with
90 * additional information, which was not available at compile type
91 * (e.g. third party augmentations).
93 * @param type Binding Class for which schema should be retrieved.
94 * @return Instance of generated type (definition of Java API), along with
95 * {@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition}
96 * which was used to generate supplied class.
98 @NonNull RuntimeType getTypeWithSchema(Class<?> type);
100 @NonNull Class<? extends RpcInput> getRpcInput(QName rpcName);
102 @NonNull Class<? extends RpcOutput> getRpcOutput(QName rpcName);
104 // FIXME: 9.0.0: this needs to accept an EffectiveStatementInference
105 @NonNull Class<?> getClassForSchema(Absolute schema);
107 @NonNull Class<? extends BaseIdentity> getIdentityClass(QName input);