Add CommonDataObjectCodecTreeNode.stream{Augmentation,DataObject}
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 20 Jun 2023 01:08:25 +0000 (03:08 +0200)
committerAnil Belur <abelur@linuxfoundation.org>
Wed, 19 Jun 2024 00:41:46 +0000 (10:41 +1000)
When we know we are streaming to a particular type, we can improve the
user experience by returning a friendly interface.

JIRA: MDSAL-820
Change-Id: I89d8dbed493919a72db7195213c5cf688b9ecb5a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-codec-api/src/main/java/org/opendaylight/mdsal/binding/dom/codec/api/BindingCodecTreeNode.java
binding/mdsal-binding-dom-codec-api/src/main/java/org/opendaylight/mdsal/binding/dom/codec/api/CommonDataObjectCodecTreeNode.java

index 8c4bc32193b41edd294c489d2d386ee7d2149ae1..85dd637415fff8c4b452573825afc29270a7e999 100644 (file)
@@ -16,11 +16,11 @@ import org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus;
  */
 @Beta
 public interface BindingCodecTreeNode {
-
     /**
      * Return the schema node associated with this node.
      *
      * @return A schema node.
      */
+    // FIXME: 12.0.0: we should be able to do better
     @NonNull WithStatus getSchema();
 }
index 997f9eb1483bb2f22e45dca8a14fc2af072c4e48..a0ffa04fa9379b4ba90edc0f210759e555d47f3c 100644 (file)
@@ -11,6 +11,7 @@ import com.google.common.annotations.Beta;
 import java.util.List;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.Empty;
@@ -22,7 +23,6 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
  *
  * @param <T> DataObject type
  */
-@Beta
 public interface CommonDataObjectCodecTreeNode<T extends DataObject>
         extends BindingDataObjectCodecTreeParent<Empty>, BindingObjectCodecTreeNode<T> {
     /**
@@ -49,6 +49,32 @@ public interface CommonDataObjectCodecTreeNode<T extends DataObject>
      */
     <E extends DataObject> @Nullable CommonDataObjectCodecTreeNode<E> streamChild(@NonNull Class<E> childClass);
 
+    default <A extends Augmentation<?>> @Nullable BindingAugmentationCodecTreeNode<A> streamAugmentation(
+            final @NonNull Class<A> childClass) {
+        final var result = streamChild(childClass);
+        if (result instanceof BindingAugmentationCodecTreeNode) {
+            return (BindingAugmentationCodecTreeNode<A>) result;
+        } else if (result == null) {
+            return null;
+        } else {
+            throw new IllegalArgumentException(
+                "Child " + childClass.getName() + " results in non-Augmentation " + result);
+        }
+    }
+
+    default <E extends DataObject> @Nullable BindingDataObjectCodecTreeNode<E> streamDataObject(
+            final @NonNull Class<E> childClass) {
+        final var result = streamChild(childClass);
+        if (result instanceof BindingDataObjectCodecTreeNode) {
+            return (BindingDataObjectCodecTreeNode<E>) result;
+        } else if (result == null) {
+            return null;
+        } else {
+            throw new IllegalArgumentException(
+                "Child " + childClass.getName() + " results in non-DataObject " + result);
+        }
+    }
+
     /**
      * Returns nested node context using supplied YANG Instance Identifier.
      *