From 9779f4b3ffe24bb2338630c66169da92c880ffbb Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Fri, 3 Nov 2017 13:33:53 +0100 Subject: HONEYCOMB-359 - Wildcarded writers Adds option to specify subtree writer that can handle whole subtree of nodes without having whole subtree specified. Its checking if node is children at runtime, rather than having pre-computed tree Change-Id: Ic46f2bd6de84f0dd14865825399f5a90a1f80859 Signed-off-by: Jan Srnicek --- .../ModifiableSubtreeManagerRegistryBuilder.java | 24 +++++++++++++++++++--- .../io/fd/honeycomb/translate/write/Writer.java | 11 +++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'infra/translate-api') diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/ModifiableSubtreeManagerRegistryBuilder.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/ModifiableSubtreeManagerRegistryBuilder.java index 4e6b2d805..ad9cd2b6f 100644 --- a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/ModifiableSubtreeManagerRegistryBuilder.java +++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/ModifiableSubtreeManagerRegistryBuilder.java @@ -16,12 +16,13 @@ package io.fd.honeycomb.translate; -import java.util.Collection; -import java.util.Set; -import javax.annotation.Nonnull; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import javax.annotation.Nonnull; +import java.util.Collection; +import java.util.Set; + /** * Registry builder where {@link SubtreeManager}s can be added with or without relationships between them. * The relationships express what the order of execution should be. @@ -41,6 +42,11 @@ public interface ModifiableSubtreeManagerRegistryBuilder subtreeAdd(@Nonnull Set> handledChildren, @Nonnull S handler); + /** + * Add a handler responsible for writing all complex nodes within a subtree its responsible for. + */ + ModifiableSubtreeManagerRegistryBuilder wildcardedSubtreeAdd(@Nonnull S handler); + /** * Add a handler and make sure it will be executed before handler identifier by relatedType is executed. */ @@ -50,6 +56,12 @@ public interface ModifiableSubtreeManagerRegistryBuilder addBefore(@Nonnull S handler, @Nonnull Collection> relatedTypes); + ModifiableSubtreeManagerRegistryBuilder wildcardedSubtreeAddBefore(@Nonnull S handler, + @Nonnull InstanceIdentifier relatedType); + + ModifiableSubtreeManagerRegistryBuilder wildcardedSubtreeAddBefore(@Nonnull S handler, + @Nonnull Collection> relatedTypes); + ModifiableSubtreeManagerRegistryBuilder subtreeAddBefore(@Nonnull Set> handledChildren, @Nonnull S handler, @Nonnull InstanceIdentifier relatedType); @@ -67,6 +79,12 @@ public interface ModifiableSubtreeManagerRegistryBuilder addAfter(@Nonnull S handler, @Nonnull Collection> relatedTypes); + ModifiableSubtreeManagerRegistryBuilder wildcardedSubtreeAddAfter(@Nonnull S handler, + @Nonnull InstanceIdentifier relatedType); + + ModifiableSubtreeManagerRegistryBuilder wildcardedSubtreeAddAfter(@Nonnull S handler, + @Nonnull Collection> relatedTypes); + ModifiableSubtreeManagerRegistryBuilder subtreeAddAfter(@Nonnull Set> handledChildren, @Nonnull S handler, @Nonnull InstanceIdentifier relatedType); diff --git a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Writer.java b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Writer.java index 1a16b72e6..18573e58a 100644 --- a/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Writer.java +++ b/infra/translate-api/src/main/java/io/fd/honeycomb/translate/write/Writer.java @@ -47,8 +47,17 @@ public interface Writer extends SubtreeManager { @Nonnull final WriteContext ctx) throws WriteFailedException; /** - * Indicates whether there is direct support for updating nodes handled by this writer, + * Indicates whether there is direct support for updating nodes handled by writer, * or they must be broken up to individual deletes and creates. */ boolean supportsDirectUpdate(); + + /** + * Returns true if node identified by this identifier can be processes by this writer + * + * @param instanceIdentifier identifier to be checked + */ + default boolean canProcess(@Nonnull final InstanceIdentifier instanceIdentifier) { + return getManagedDataObjectType().equals(instanceIdentifier); + } } -- cgit 1.2.3-korg