Rework BindingRuntimeTypes
[mdsal.git] / binding / mdsal-binding-runtime-api / src / main / java / org / opendaylight / mdsal / binding / runtime / api / BindingRuntimeContext.java
index 9fe1e546a0ee3098a46a267d3717e56536eab49a..109656a7bd6337f0b9eb142ddba6d2febf7f6d11 100644 (file)
@@ -8,47 +8,37 @@
 package org.opendaylight.mdsal.binding.runtime.api;
 
 import com.google.common.annotations.Beta;
-import com.google.common.collect.ImmutableMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.Set;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.mdsal.binding.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
 import org.opendaylight.mdsal.binding.model.api.Type;
 import org.opendaylight.yangtools.concepts.Immutable;
 import org.opendaylight.yangtools.yang.binding.Action;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.binding.RpcInput;
+import org.opendaylight.yangtools.yang.binding.RpcOutput;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
-import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 
 /**
  * Runtime Context for Java YANG Binding classes. It provides information derived from the backing effective model,
  * which is not captured in generated classes (and hence cannot be obtained from {@code BindingReflections}.
- *
- * <p>Some of this information are for example list of all available children for cases
- * {@link #getChoiceCaseChildren(DataNodeContainer)}, since choices are augmentable and new choices may be introduced
- * by additional models. Same goes for all possible augmentations.
  */
 @Beta
 // FIXME: refactor return to follow foo()/getFoo()/findFoo() naming
 public interface BindingRuntimeContext extends EffectiveModelContextProvider, Immutable {
     @NonNull BindingRuntimeTypes getTypes();
 
-    @NonNull <T> Class<T> loadClass(Type type) throws ClassNotFoundException;
+    @NonNull <T> Class<T> loadClass(JavaTypeName type) throws ClassNotFoundException;
+
+    default @NonNull <T> Class<T> loadClass(final Type type) throws ClassNotFoundException {
+        return loadClass(type.getIdentifier());
+    }
 
     @Override
     default EffectiveModelContext getEffectiveModelContext() {
@@ -66,16 +56,12 @@ public interface BindingRuntimeContext extends EffectiveModelContextProvider, Im
      * which may be present in runtime for them, thus returned schema is unsuitable
      * for use for validation of data.
      *
-     * <p>For retrieving {@link AugmentationSchemaNode}, which will contains
-     * full model for child nodes, you should use method
-     * {@link #getResolvedAugmentationSchema(DataNodeContainer, Class)}
-     * which will return augmentation schema derived from supplied augmentation target
-     * schema.
-     *
+     * @param <T> Augmentation class type
      * @param augClass Augmentation class
      * @return Schema of augmentation or null if augmentation is not known in this context
+     * @throws NullPointerException if {@code augClass} is null
      */
-    <T extends Augmentation<?>> @Nullable AugmentationSchemaNode getAugmentationDefinition(Class<T> augClass);
+    <T extends Augmentation<?>> @Nullable AugmentRuntimeType getAugmentationDefinition(Class<T> augClass);
 
     /**
      * Returns defining {@link DataSchemaNode} for supplied class.
@@ -90,27 +76,9 @@ public interface BindingRuntimeContext extends EffectiveModelContextProvider, Im
      * @param cls Class which represents list, container, choice or case.
      * @return Schema node, from which class was generated.
      */
-    @Nullable DataSchemaNode getSchemaDefinition(Class<?> cls);
-
-    // FIXME: document this thing and perhaps move it to BindingRuntimeTypes?
-    @Nullable DataSchemaNode findChildSchemaDefinition(DataNodeContainer parentSchema, QNameModule parentNamespace,
-        Class<?> childClass);
-
-    @Nullable ActionDefinition getActionDefinition(Class<? extends Action<?, ?, ?>> cls);
-
-    @NonNull Entry<AugmentationIdentifier, AugmentationSchemaNode> getResolvedAugmentationSchema(
-            DataNodeContainer target, Class<? extends Augmentation<?>> aug);
+    @Nullable CompositeRuntimeType getSchemaDefinition(Class<?> cls);
 
-    /**
-     * Returns resolved case schema for supplied class.
-     *
-     * @param schema Resolved parent choice schema
-     * @param childClass Class representing case.
-     * @return Optionally a resolved case schema,.empty if the choice is not legal in
-     *         the given context.
-     * @throws IllegalArgumentException If supplied class does not represent case.
-     */
-    @NonNull Optional<CaseSchemaNode> getCaseSchemaDefinition(ChoiceSchemaNode schema, Class<?> childClass);
+    @Nullable ActionRuntimeType getActionDefinition(Class<? extends Action<?, ?, ?>> cls);
 
     /**
      * Returns schema ({@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition})
@@ -123,23 +91,14 @@ public interface BindingRuntimeContext extends EffectiveModelContextProvider, Im
      *     {@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition}
      *     which was used to generate supplied class.
      */
-    @NonNull Entry<GeneratedType, WithStatus> getTypeWithSchema(Class<?> type);
-
-    @NonNull Map<Type, Entry<Type, Type>> getChoiceCaseChildren(DataNodeContainer schema);
+    @NonNull RuntimeType getTypeWithSchema(Class<?> type);
 
-    @NonNull Set<Class<?>> getCases(Class<?> choice);
+    @NonNull Class<? extends RpcInput> getRpcInput(QName rpcName);
 
-    @NonNull Class<?> getClassForSchema(SchemaNode childSchema);
+    @NonNull Class<? extends RpcOutput> getRpcOutput(QName rpcName);
 
-    /**
-     * Return the mapping of a particular {@link DataNodeContainer}'s available augmentations. This method deals with
-     * resolving {@code uses foo { augment bar { ... } } } scenarios by returning the augmentation created for
-     * {@code grouping foo}'s Binding representation.
-     *
-     * @param container {@link DataNodeContainer} to examine
-     * @return a mapping from local {@link AugmentationIdentifier}s to their corresponding Binding augmentations
-     */
-    @NonNull ImmutableMap<AugmentationIdentifier, Type> getAvailableAugmentationTypes(DataNodeContainer container);
+    // FIXME: 9.0.0: this needs to accept an EffectiveStatementInference
+    @NonNull Class<?> getClassForSchema(Absolute schema);
 
     @NonNull Class<?> getIdentityClass(QName input);
 }