Improve BindingRuntimeContext.getAugmentationDefinition() 09/92809/7
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 30 Sep 2020 12:24:13 +0000 (14:24 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 30 Sep 2020 17:54:37 +0000 (19:54 +0200)
All callers are already guarding the call site with a check, hence
we can also require them to perform an explicit reinterpret. This
pushes safety checks to compile-time.

Also remove duplicate javadocs, so that we have one text defining
semantics.

Change-Id: I3ce23440c725441e663331e94a931ad09d71634a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/FutureSchema.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataContainerCodecContext.java
binding/mdsal-binding-runtime-api/src/main/java/org/opendaylight/mdsal/binding/runtime/api/AbstractBindingRuntimeContext.java
binding/mdsal-binding-runtime-api/src/main/java/org/opendaylight/mdsal/binding/runtime/api/BindingRuntimeContext.java
binding/mdsal-binding-runtime-spi/src/main/java/org/opendaylight/mdsal/binding/runtime/spi/ForwardingBindingRuntimeContext.java

index f9868d28bee1949a2fd924e1b24676fc2b833f63..6d66ce888808b0daf7ff6c0dafb15b397e627797 100644 (file)
@@ -138,7 +138,7 @@ abstract class FutureSchema implements AutoCloseable {
             public boolean test(final BindingRuntimeContext context) {
                 return bindingClasses.stream().allMatch(clz -> {
                     if (Augmentation.class.isAssignableFrom(clz)) {
-                        return context.getAugmentationDefinition(clz) != null;
+                        return context.getAugmentationDefinition(clz.asSubclass(Augmentation.class)) != null;
                     }
 
                     return context.getSchemaDefinition(clz) != null;
index e8bca5d0d1e5cde58b6f64affad6f8521c92f2eb..338b8046bd8c6a23dcab262bfe05afc6748b574f 100644 (file)
@@ -203,7 +203,7 @@ abstract class DataContainerCodecContext<D extends DataObject, T extends WithSta
         final BindingRuntimeContext runtimeContext = factory().getRuntimeContext();
         final WithStatus schema;
         if (Augmentation.class.isAssignableFrom(childClass)) {
-            schema = runtimeContext.getAugmentationDefinition(childClass);
+            schema = runtimeContext.getAugmentationDefinition(childClass.asSubclass(Augmentation.class));
         } else {
             schema = runtimeContext.getSchemaDefinition(childClass);
         }
index 920d11546b67dce331ec1c05c9c8d4828f9450a6..96b5db7ab23d76644de9d85539e715fe8e80874e 100644 (file)
@@ -26,7 +26,6 @@ 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.DefaultType;
 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
@@ -46,7 +45,6 @@ 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.SchemaNode;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
 import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
 import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
@@ -79,47 +77,11 @@ public abstract class AbstractBindingRuntimeContext implements BindingRuntimeCon
             }
         });
 
-    /**
-     * Returns schema of augmentation.
-     *
-     * <p>Returned schema is schema definition from which augmentation class was generated.
-     * This schema is isolated from other augmentations. This means it contains
-     * augmentation definition as was present in original YANG module.
-     *
-     * <p>Children of returned schema does not contain any additional augmentations,
-     * 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 augClass Augmentation class
-     * @return Schema of augmentation or null if augmentaiton is not known in this context
-     * @throws IllegalArgumentException If supplied class is not an augmentation
-     */
     @Override
-    public final @Nullable AugmentationSchemaNode getAugmentationDefinition(final Class<?> augClass) {
-        checkArgument(Augmentation.class.isAssignableFrom(augClass),
-            "Class %s does not represent augmentation", augClass);
+    public final <T extends Augmentation<?>> AugmentationSchemaNode getAugmentationDefinition(final Class<T> augClass) {
         return getTypes().findAugmentation(DefaultType.of(augClass)).orElse(null);
     }
 
-    /**
-     * Returns defining {@link DataSchemaNode} for supplied class.
-     *
-     * <p>Returned schema is schema definition from which class was generated.
-     * This schema may be isolated from augmentations, if supplied class
-     * represent node, which was child of grouping or augmentation.
-     *
-     * <p>For getting augmentation schema from augmentation class use
-     * {@link #getAugmentationDefinition(Class)} instead.
-     *
-     * @param cls Class which represents list, container, choice or case.
-     * @return Schema node, from which class was generated.
-     */
     @Override
     public final DataSchemaNode getSchemaDefinition(final Class<?> cls) {
         checkArgument(!Augmentation.class.isAssignableFrom(cls), "Supplied class must not be an augmentation (%s is)",
@@ -178,15 +140,6 @@ public abstract class AbstractBindingRuntimeContext implements BindingRuntimeCon
         return new SimpleEntry<>(identifier, proxy);
     }
 
-    /**
-     * 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.
-     */
     @Override
     public final Optional<CaseSchemaNode> getCaseSchemaDefinition(final ChoiceSchemaNode schema,
             final Class<?> childClass) {
@@ -202,17 +155,6 @@ public abstract class AbstractBindingRuntimeContext implements BindingRuntimeCon
         return findInstantiatedCase(schema, (CaseSchemaNode) origSchema);
     }
 
-    /**
-     * Returns schema ({@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition})
-     * from which supplied class was generated. Returned schema may be augmented with
-     * additional information, which was not available at compile type
-     * (e.g. third party augmentations).
-     *
-     * @param type Binding Class for which schema should be retrieved.
-     * @return Instance of generated type (definition of Java API), along with
-     *     {@link DataSchemaNode}, {@link AugmentationSchemaNode} or {@link TypeDefinition}
-     *     which was used to generate supplied class.
-     */
     @Override
     public final Entry<GeneratedType, WithStatus> getTypeWithSchema(final Class<?> type) {
         return getTypeWithSchema(getTypes(), DefaultType.of(type));
index 99b98d1c3365b347f4c8f2dd83ccd04a3779716d..a525528e9b397088b49f5a9209a607afb3b4200a 100644 (file)
@@ -72,10 +72,9 @@ public interface BindingRuntimeContext extends EffectiveModelContextProvider, Im
      * schema.
      *
      * @param augClass Augmentation class
-     * @return Schema of augmentation or null if augmentaiton is not known in this context
-     * @throws IllegalArgumentException If supplied class is not an augmentation
+     * @return Schema of augmentation or null if augmentation is not known in this context
      */
-    @Nullable AugmentationSchemaNode getAugmentationDefinition(Class<?> augClass);
+    <T extends Augmentation<?>> @Nullable AugmentationSchemaNode getAugmentationDefinition(Class<T> augClass);
 
     /**
      * Returns defining {@link DataSchemaNode} for supplied class.
index a48d44f0cabbdab084384d8328e8b81d95876660..464746eb9c6bd23e542ff7d61f55d0d5acb64e49 100644 (file)
@@ -43,7 +43,7 @@ public abstract class ForwardingBindingRuntimeContext extends ForwardingObject i
     }
 
     @Override
-    public AugmentationSchemaNode getAugmentationDefinition(final Class<?> augClass) {
+    public <T extends Augmentation<?>> AugmentationSchemaNode getAugmentationDefinition(final Class<T> augClass) {
         return delegate().getAugmentationDefinition(augClass);
     }