summaryrefslogtreecommitdiffstats
path: root/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read
diff options
context:
space:
mode:
Diffstat (limited to 'v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read')
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ChildReader.java50
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ListReader.java29
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/Reader.java31
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReaderFactory.java33
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/registry/ModifiableReaderRegistryBuilder.java41
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/registry/ReaderRegistry.java (renamed from v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReaderRegistry.java)23
-rw-r--r--v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/registry/ReaderRegistryBuilder.java27
7 files changed, 174 insertions, 60 deletions
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ChildReader.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ChildReader.java
deleted file mode 100644
index 02b6b8d26..000000000
--- a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ChildReader.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco and/or its affiliates.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.fd.honeycomb.v3po.translate.read;
-
-import com.google.common.annotations.Beta;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.concepts.Builder;
-import org.opendaylight.yangtools.yang.binding.DataObject;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-
-/**
- * Child reader allowing its parent to pass the builder object
- *
- * @param <C> Specific DataObject derived type, that is handled by this reader
- */
-@Beta
-public interface ChildReader<C extends DataObject> extends Reader<C> {
-
- /**
- * Reads subtree starting from node managed by this reader and place the subtree within parent builder object if the
- * data exists.
- *
- * @param id Unique identifier pointing to the node managed by this reader. Useful when necessary to
- * determine the exact position within more complex subtrees.
- * @param parentBuilder Builder of parent DataObject. Objects read on this level (if any) must be placed into the
- * parent builder.
- * @param ctx Read context
- *
- * @throws ReadFailedException if read was unsuccessful
- */
- void read(@Nonnull final InstanceIdentifier<? extends DataObject> id,
- @Nonnull final Builder<? extends DataObject> parentBuilder,
- @Nonnull final ReadContext ctx) throws ReadFailedException;
-
-}
-
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ListReader.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ListReader.java
index faf6f0a19..13a7a55da 100644
--- a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ListReader.java
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ListReader.java
@@ -17,23 +17,26 @@
package io.fd.honeycomb.v3po.translate.read;
import com.google.common.annotations.Beta;
+import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
+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;
/**
- * List reader, allowing read of all the elements
+ * List reader, allowing read of all the elements.
*
* @param <D> Specific DataObject derived type, that is handled by this reader
*/
@Beta
-public interface ListReader<D extends DataObject & Identifiable<K>, K extends Identifier<D>> extends Reader<D> {
+public interface ListReader
+ <D extends DataObject & Identifiable<K>, K extends Identifier<D>, B extends Builder<D>> extends Reader<D, B> {
/**
- * Read all elements in this list
+ * Read all elements in this list.
*
* @param id Wildcarded identifier of list managed by this reader
* @param ctx Read context
@@ -42,6 +45,22 @@ public interface ListReader<D extends DataObject & Identifiable<K>, K extends Id
* @throws ReadFailedException if read was unsuccessful
*/
@Nonnull
- List<D> readList(@Nonnull final InstanceIdentifier<D> id,
- @Nonnull final ReadContext ctx) throws ReadFailedException;
+ List<D> readList(@Nonnull final InstanceIdentifier<D> id, @Nonnull final ReadContext ctx)
+ throws ReadFailedException;
+
+ /**
+ * Get IDs for all entries in the list.
+ */
+ List<K> getAllIds(@Nonnull InstanceIdentifier<D> id, @Nonnull ReadContext ctx)
+ throws ReadFailedException;
+
+ /**
+ * Merge read data into provided parent builder.
+ */
+ void merge(@Nonnull final Builder<? extends DataObject> builder, @Nonnull final List<D> readData);
+
+ @Override
+ default void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final D readValue) {
+ merge(parentBuilder, Collections.singletonList(readValue));
+ }
}
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/Reader.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/Reader.java
index 122263cb3..d0bf0dea1 100644
--- a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/Reader.java
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/Reader.java
@@ -20,16 +20,17 @@ import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
import io.fd.honeycomb.v3po.translate.SubtreeManager;
import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.concepts.Builder;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
- * Base reader, responsible for translation between DataObjects and any other side
+ * Base reader, responsible for translation between DataObjects and any other side.
*
* @param <D> Specific DataObject derived type, that is handled by this reader
*/
@Beta
-public interface Reader<D extends DataObject> extends SubtreeManager<D> {
+public interface Reader<D extends DataObject, B extends Builder<D>> extends SubtreeManager<D> {
// TODO make async
@@ -45,7 +46,31 @@ public interface Reader<D extends DataObject> extends SubtreeManager<D> {
* @throws ReadFailedException if read was unsuccessful
*/
@Nonnull
- Optional<? extends DataObject> read(@Nonnull final InstanceIdentifier<? extends DataObject> id,
+ Optional<? extends DataObject> read(@Nonnull InstanceIdentifier<? extends DataObject> id,
@Nonnull ReadContext ctx) throws ReadFailedException;
+ /**
+ * Fill in current node's attributes
+ *
+ * @param id {@link InstanceIdentifier} pointing to current node. In case of keyed list, key must be present.
+ * @param builder Builder object for current node where the read attributes must be placed
+ * @param ctx Current read context
+ */
+ void readCurrentAttributes(@Nonnull InstanceIdentifier<D> id,
+ @Nonnull B builder,
+ @Nonnull ReadContext ctx) throws ReadFailedException;
+
+ /**
+ * Return new instance of a builder object for current node
+ *
+ * @param id {@link InstanceIdentifier} pointing to current node. In case of keyed list, key must be present.
+ * @return Builder object for current node type
+ */
+ @Nonnull
+ B getBuilder(InstanceIdentifier<D> id);
+
+ /**
+ * Merge read data into provided parent builder.
+ */
+ void merge(@Nonnull final Builder<? extends DataObject> parentBuilder, @Nonnull final D readValue);
}
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReaderFactory.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReaderFactory.java
new file mode 100644
index 000000000..6d6d52acc
--- /dev/null
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReaderFactory.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.v3po.translate.read;
+
+import com.google.common.annotations.Beta;
+import io.fd.honeycomb.v3po.translate.read.registry.ModifiableReaderRegistryBuilder;
+import javax.annotation.Nonnull;
+
+/**
+ * Factory producing readers for {@link ModifiableReaderRegistryBuilder}.
+ */
+@Beta
+public interface ReaderFactory {
+
+ /**
+ * Initialize 1 or more readers and add them to provided registry.
+ */
+ void init(@Nonnull ModifiableReaderRegistryBuilder registry);
+}
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/registry/ModifiableReaderRegistryBuilder.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/registry/ModifiableReaderRegistryBuilder.java
new file mode 100644
index 000000000..c2eba4f72
--- /dev/null
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/registry/ModifiableReaderRegistryBuilder.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.v3po.translate.read.registry;
+
+import com.google.common.annotations.Beta;
+import io.fd.honeycomb.v3po.translate.ModifiableSubtreeManagerRegistryBuilder;
+import io.fd.honeycomb.v3po.translate.read.Reader;
+import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.concepts.Builder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Mutable registry that allows adding new readers.
+ */
+@Beta
+public interface ModifiableReaderRegistryBuilder
+ extends ModifiableSubtreeManagerRegistryBuilder<Reader<? extends DataObject, ? extends Builder<?>>> {
+
+ // TODO we should be able to add structural/reflexive readers automatically in the registry builder, we just need builder class
+ // We would need generated class loading strategy instance and then load builder classes relying on naming + package conventions of Binding spec
+ /**
+ * Add a structural reader that performs no read operation on its own, just fills in the hierarchy.
+ */
+ <D extends DataObject> void addStructuralReader(@Nonnull InstanceIdentifier<D> id,
+ @Nonnull Class<? extends Builder<D>> builderType);
+}
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReaderRegistry.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/registry/ReaderRegistry.java
index f34455a27..308ec238d 100644
--- a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/ReaderRegistry.java
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/registry/ReaderRegistry.java
@@ -14,10 +14,13 @@
* limitations under the License.
*/
-package io.fd.honeycomb.v3po.translate.read;
+package io.fd.honeycomb.v3po.translate.read.registry;
import com.google.common.annotations.Beta;
+import com.google.common.base.Optional;
import com.google.common.collect.Multimap;
+import io.fd.honeycomb.v3po.translate.read.ReadContext;
+import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
@@ -26,7 +29,7 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
* Simple delegating reader suitable as a holder for all other root readers, providing readAll feature.
*/
@Beta
-public interface ReaderRegistry extends Reader<DataObject> {
+public interface ReaderRegistry {
/**
* Performs read on all registered root readers and merges the results into a Multimap. Keys represent identifiers
@@ -40,4 +43,20 @@ public interface ReaderRegistry extends Reader<DataObject> {
@Nonnull
Multimap<InstanceIdentifier<? extends DataObject>, ? extends DataObject> readAll(@Nonnull final ReadContext ctx)
throws ReadFailedException;
+
+ /**
+ * Reads data identified by id.
+ *
+ * @param id unique identifier of subtree to be read. The subtree must contain managed data object type. For
+ * identifiers pointing below node managed by this reader, it's reader's responsibility to filter out the
+ * right node or to delegate the read to a child reader.
+ * @param ctx Read context
+ *
+ * @return List of DataObjects identified by id. If the ID points to a single node, it will be wrapped in a list
+ * @throws ReadFailedException if read was unsuccessful
+ */
+ @Nonnull
+ Optional<? extends DataObject> read(@Nonnull InstanceIdentifier<? extends DataObject> id,
+ @Nonnull ReadContext ctx)
+ throws ReadFailedException;
}
diff --git a/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/registry/ReaderRegistryBuilder.java b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/registry/ReaderRegistryBuilder.java
new file mode 100644
index 000000000..ff95d6248
--- /dev/null
+++ b/v3po/translate-api/src/main/java/io/fd/honeycomb/v3po/translate/read/registry/ReaderRegistryBuilder.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.v3po.translate.read.registry;
+
+import com.google.common.annotations.Beta;
+import io.fd.honeycomb.v3po.translate.SubtreeManagerRegistryBuilder;
+
+/**
+ * Builder for reader registries.
+ */
+@Beta
+public interface ReaderRegistryBuilder extends SubtreeManagerRegistryBuilder<ReaderRegistry> {
+}