summaryrefslogtreecommitdiffstats
path: root/infra/translate-impl/src/main/java/io
diff options
context:
space:
mode:
authorJan Srnicek <jsrnicek@cisco.com>2017-02-24 10:39:55 +0100
committerMarek Gradzki <mgradzki@cisco.com>2017-02-27 11:42:19 +0000
commitec78f178f542369fdfd696fdc6e4bb872780ac87 (patch)
tree129206bdf7bb3ad62257d5cfca776e264f70fad6 /infra/translate-impl/src/main/java/io
parent309d5e1561ba42ee491fa33c3b8c24849dc003fa (diff)
HONEYCOMB-344 - structural reader for list
Change-Id: Ia02ed73daaeea547d49c9ec2d4d7d10f4db85b5e Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'infra/translate-impl/src/main/java/io')
-rw-r--r--infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/GenericListReader.java9
-rw-r--r--infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/registry/CompositeReaderRegistryBuilder.java14
2 files changed, 19 insertions, 4 deletions
diff --git a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/GenericListReader.java b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/GenericListReader.java
index b06ac060f..9e2ccd7e5 100644
--- a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/GenericListReader.java
+++ b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/GenericListReader.java
@@ -23,12 +23,15 @@ import com.google.common.base.Optional;
import io.fd.honeycomb.translate.read.ListReader;
import io.fd.honeycomb.translate.read.ReadContext;
import io.fd.honeycomb.translate.read.ReadFailedException;
+import io.fd.honeycomb.translate.read.Reader;
import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
import io.fd.honeycomb.translate.util.RWUtils;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
+
+import io.fd.honeycomb.translate.util.read.ReflexiveListReaderCustomizer;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Identifiable;
@@ -97,4 +100,10 @@ public class GenericListReader<C extends DataObject & Identifiable<K>, K extends
public void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<C> readData) {
((ListReaderCustomizer<C, K, B>) customizer).merge(builder, readData);
}
+
+ public static <C extends DataObject & Identifiable<K>,K extends Identifier<C>, B extends Builder<C>> Reader<C, B> createReflexive(
+ final InstanceIdentifier<C> id, Class<B> builderClass,
+ final List<K> staticKeys) {
+ return new GenericListReader<>(id, new ReflexiveListReaderCustomizer<>(id.getTargetType(), builderClass, staticKeys));
+ }
}
diff --git a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/registry/CompositeReaderRegistryBuilder.java b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/registry/CompositeReaderRegistryBuilder.java
index dd6a838c6..9163e98de 100644
--- a/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/registry/CompositeReaderRegistryBuilder.java
+++ b/infra/translate-impl/src/main/java/io/fd/honeycomb/translate/impl/read/registry/CompositeReaderRegistryBuilder.java
@@ -17,6 +17,7 @@
package io.fd.honeycomb.translate.impl.read.registry;
import com.google.common.collect.ImmutableMap;
+import io.fd.honeycomb.translate.impl.read.GenericListReader;
import io.fd.honeycomb.translate.impl.read.GenericReader;
import io.fd.honeycomb.translate.read.InitReader;
import io.fd.honeycomb.translate.read.Initializer;
@@ -36,6 +37,7 @@ import javax.annotation.concurrent.NotThreadSafe;
import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -60,14 +62,18 @@ public final class CompositeReaderRegistryBuilder
@Override
public <D extends DataObject> void addStructuralReader(@Nonnull InstanceIdentifier<D> id,
@Nonnull Class<? extends Builder<D>> builderType) {
- // TODO https://jira.fd.io/browse/HONEYCOMB-344 provide variant of this method for list nodes
// prevent case to submit structural reader for list, which would cause fail because target setter consumes
- // List<TargetType>, not Target type. If node is static, customizer that handles it should return static list
- // of IDs.
- checkArgument(!Identifiable.class.isAssignableFrom(id.getTargetType()), "Structural readers cannot be used for keyed nodes[node type %s]", id.getTargetType());
+ // List<TargetType>, not Target type. If node is static list, addStructuralListReader should be used
+ checkArgument(!Identifiable.class.isAssignableFrom(id.getTargetType()), "Structural readers cannot be used for keyed nodes[node type %s], use addStructuralListReader()", id.getTargetType());
add(GenericReader.createReflexive(id, builderType));
}
+ @Override
+ public <D extends DataObject & Identifiable<K>, K extends Identifier<D>> void addStructuralListReader(@Nonnull InstanceIdentifier<D> id, @Nonnull Class<? extends Builder<D>> builderType, @Nonnull List<K> staticKeys) {
+ checkArgument(Identifiable.class.isAssignableFrom(id.getTargetType()), "Node %s is not keyed, use addStructuralReader()", id.getTargetType());
+ add(GenericListReader.createReflexive(id, builderType, staticKeys));
+ }
+
/**
* Create {@link CompositeReaderRegistry} with Readers ordered according to submitted relationships.
* <p/>