summaryrefslogtreecommitdiffstats
path: root/v3po/translate-impl/src/main/java
diff options
context:
space:
mode:
authorMaros Marsalek <mmarsale@cisco.com>2016-04-12 10:13:37 +0200
committerMaros Marsalek <mmarsale@cisco.com>2016-04-12 10:13:37 +0200
commit28208ac2b1b9e068c51eee79cf1bfedc6a818195 (patch)
tree4bb01d13f3a070ddb7b6b4bd22393a61a527dad8 /v3po/translate-impl/src/main/java
parent1c690387dcfe8730ca9c0d4fc5ea732b172ae249 (diff)
HONEYCOMB-9: Migrate Interface listener
Change-Id: Iffde1ee21b749a8c8efa96c243f7f8bb0811b4c7 Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/translate-impl/src/main/java')
-rw-r--r--v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/TraversalType.java37
-rw-r--r--v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/AbstractCompositeReader.java41
-rw-r--r--v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeChildReader.java21
-rw-r--r--v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeListReader.java20
-rw-r--r--v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeRootReader.java21
-rw-r--r--v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/AbstractCompositeWriter.java107
-rw-r--r--v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeChildWriter.java27
-rw-r--r--v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeListWriter.java33
-rw-r--r--v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeRootWriter.java24
9 files changed, 264 insertions, 67 deletions
diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/TraversalType.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/TraversalType.java
new file mode 100644
index 000000000..3fa0f8d24
--- /dev/null
+++ b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/TraversalType.java
@@ -0,0 +1,37 @@
+/*
+ * 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.impl;
+
+/**
+ * Type of traversal to be used by readers/writers in a tree
+ */
+public enum TraversalType {
+
+ /**
+ * Read current attributes before reading from children
+ */
+ PREORDER,
+
+ /**
+ * Read from children before reading current attributes
+ */
+ POSTORDER
+
+ // TODO implement different traversal types as injectable iterators
+ // TODO implement above traversal types in readers
+
+} \ No newline at end of file
diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/AbstractCompositeReader.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/AbstractCompositeReader.java
index f9fa0eeaa..e8d79c538 100644
--- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/AbstractCompositeReader.java
+++ b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/AbstractCompositeReader.java
@@ -22,6 +22,7 @@ import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
+import io.fd.honeycomb.v3po.translate.impl.TraversalType;
import io.fd.honeycomb.v3po.translate.util.ReflectionUtils;
import io.fd.honeycomb.v3po.translate.util.RWUtils;
import io.fd.honeycomb.v3po.translate.read.ChildReader;
@@ -52,10 +53,13 @@ abstract class AbstractCompositeReader<D extends DataObject, B extends Builder<D
private final Map<Class<? extends DataObject>, ChildReader<? extends ChildOf<D>>> childReaders;
private final Map<Class<? extends DataObject>, ChildReader<? extends Augmentation<D>>> augReaders;
private final InstanceIdentifier<D> instanceIdentifier;
+ private final TraversalType traversalType;
AbstractCompositeReader(final Class<D> managedDataObjectType,
final List<ChildReader<? extends ChildOf<D>>> childReaders,
- final List<ChildReader<? extends Augmentation<D>>> augReaders) {
+ final List<ChildReader<? extends Augmentation<D>>> augReaders,
+ final TraversalType traversalType) {
+ this.traversalType = traversalType;
this.childReaders = RWUtils.uniqueLinkedIndex(childReaders, RWUtils.MANAGER_CLASS_FUNCTION);
this.augReaders = RWUtils.uniqueLinkedIndex(augReaders, RWUtils.MANAGER_CLASS_AUG_FUNCTION);
this.instanceIdentifier = InstanceIdentifier.create(managedDataObjectType);
@@ -78,9 +82,31 @@ abstract class AbstractCompositeReader<D extends DataObject, B extends Builder<D
// Cache empty value to determine if anything has changed later TODO cache in a field
final D emptyValue = builder.build();
- LOG.trace("{}: Reading current attributes", this);
- readCurrentAttributes(id, builder, ctx);
+ switch (traversalType) {
+ case PREORDER: {
+ LOG.trace("{}: Reading current attributes", this);
+ readCurrentAttributes(id, builder, ctx);
+ readChildren(id, ctx, builder);
+ }
+ case POSTORDER: {
+ readChildren(id, ctx, builder);
+ LOG.trace("{}: Reading current attributes", this);
+ readCurrentAttributes(id, builder, ctx);
+ }
+ }
+
+ // Need to check whether anything was filled in to determine if data is present or not.
+ final D built = builder.build();
+ final Optional<D> read = built.equals(emptyValue)
+ ? Optional.<D>absent()
+ : Optional.of(built);
+
+ LOG.debug("{}: Current node read successfully. Result: {}", this, read);
+ return read;
+ }
+ private void readChildren(final InstanceIdentifier<D> id, final @Nonnull ReadContext ctx, final B builder)
+ throws ReadFailedException {
// TODO expect exceptions from reader
for (ChildReader<? extends ChildOf<D>> child : childReaders.values()) {
LOG.debug("{}: Reading child from: {}", this, child);
@@ -91,15 +117,6 @@ abstract class AbstractCompositeReader<D extends DataObject, B extends Builder<D
LOG.debug("{}: Reading augment from: {}", this, child);
child.read(id, builder, ctx);
}
-
- // Need to check whether anything was filled in to determine if data is present or not.
- final D built = builder.build();
- final Optional<D> read = built.equals(emptyValue)
- ? Optional.<D>absent()
- : Optional.of(built);
-
- LOG.debug("{}: Current node read successfully. Result: {}", this, read);
- return read;
}
@Nonnull
diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeChildReader.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeChildReader.java
index 46a59bb90..1984cd86d 100644
--- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeChildReader.java
+++ b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeChildReader.java
@@ -18,6 +18,7 @@ package io.fd.honeycomb.v3po.translate.impl.read;
import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
+import io.fd.honeycomb.v3po.translate.impl.TraversalType;
import io.fd.honeycomb.v3po.translate.read.ReadContext;
import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
import io.fd.honeycomb.v3po.translate.util.RWUtils;
@@ -56,7 +57,25 @@ public final class CompositeChildReader<C extends DataObject, B extends Builder<
@Nonnull final List<ChildReader<? extends ChildOf<C>>> childReaders,
@Nonnull final List<ChildReader<? extends Augmentation<C>>> augReaders,
@Nonnull final ChildReaderCustomizer<C, B> customizer) {
- super(managedDataObjectType, childReaders, augReaders);
+ this(managedDataObjectType, childReaders, augReaders, customizer, TraversalType.PREORDER);
+ }
+
+ /**
+ * Create new {@link CompositeChildReader}
+ *
+ * @param managedDataObjectType Class object for managed data type
+ * @param childReaders Child nodes(container, list) readers
+ * @param augReaders Child augmentations readers
+ * @param customizer Customizer instance to customize this generic reader
+ * @param traversalType Type of traversal to use in the tree of readers
+ *
+ */
+ public CompositeChildReader(@Nonnull final Class<C> managedDataObjectType,
+ @Nonnull final List<ChildReader<? extends ChildOf<C>>> childReaders,
+ @Nonnull final List<ChildReader<? extends Augmentation<C>>> augReaders,
+ @Nonnull final ChildReaderCustomizer<C, B> customizer,
+ @Nonnull final TraversalType traversalType) {
+ super(managedDataObjectType, childReaders, augReaders, traversalType);
this.customizer = customizer;
}
diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeListReader.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeListReader.java
index fd7b279ca..de32ee723 100644
--- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeListReader.java
+++ b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeListReader.java
@@ -20,6 +20,7 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
+import io.fd.honeycomb.v3po.translate.impl.TraversalType;
import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
import io.fd.honeycomb.v3po.translate.util.RWUtils;
import io.fd.honeycomb.v3po.translate.read.ChildReader;
@@ -68,7 +69,24 @@ public final class CompositeListReader<C extends DataObject & Identifiable<K>, K
@Nonnull final List<ChildReader<? extends ChildOf<C>>> childReaders,
@Nonnull final List<ChildReader<? extends Augmentation<C>>> augReaders,
@Nonnull final ListReaderCustomizer<C, K, B> customizer) {
- super(managedDataObjectType, childReaders, augReaders);
+ this(managedDataObjectType, childReaders, augReaders, customizer, TraversalType.PREORDER);
+ }
+
+ /**
+ * Create new {@link CompositeListReader}
+ *
+ * @param managedDataObjectType Class object for managed data type. Must come from a list node type.
+ * @param childReaders Child nodes(container, list) readers
+ * @param augReaders Child augmentations readers
+ * @param customizer Customizer instance to customize this generic reader
+ * @param traversalType Type of traversal to use in the tree of readers
+ */
+ public CompositeListReader(@Nonnull final Class<C> managedDataObjectType,
+ @Nonnull final List<ChildReader<? extends ChildOf<C>>> childReaders,
+ @Nonnull final List<ChildReader<? extends Augmentation<C>>> augReaders,
+ @Nonnull final ListReaderCustomizer<C, K, B> customizer,
+ @Nonnull final TraversalType traversalType) {
+ super(managedDataObjectType, childReaders, augReaders, traversalType);
this.customizer = customizer;
}
diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeRootReader.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeRootReader.java
index f297abb76..0abae70be 100644
--- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeRootReader.java
+++ b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/read/CompositeRootReader.java
@@ -17,6 +17,7 @@
package io.fd.honeycomb.v3po.translate.impl.read;
import com.google.common.annotations.Beta;
+import io.fd.honeycomb.v3po.translate.impl.TraversalType;
import io.fd.honeycomb.v3po.translate.read.ReadFailedException;
import io.fd.honeycomb.v3po.translate.util.RWUtils;
import io.fd.honeycomb.v3po.translate.read.ChildReader;
@@ -55,7 +56,25 @@ public final class CompositeRootReader<C extends DataObject, B extends Builder<C
@Nonnull final List<ChildReader<? extends ChildOf<C>>> childReaders,
@Nonnull final List<ChildReader<? extends Augmentation<C>>> augReaders,
@Nonnull final RootReaderCustomizer<C, B> customizer) {
- super(managedDataObjectType, childReaders, augReaders);
+ this(managedDataObjectType, childReaders, augReaders, customizer, TraversalType.PREORDER);
+ }
+
+ /**
+ * Create new {@link CompositeRootReader}
+ *
+ * @param managedDataObjectType Class object for managed data type
+ * @param childReaders Child nodes(container, list) readers
+ * @param augReaders Child augmentations readers
+ * @param customizer Customizer instance to customize this generic reader
+ * @param traversalType Type of traversal to use in the tree of readers
+ *
+ */
+ public CompositeRootReader(@Nonnull final Class<C> managedDataObjectType,
+ @Nonnull final List<ChildReader<? extends ChildOf<C>>> childReaders,
+ @Nonnull final List<ChildReader<? extends Augmentation<C>>> augReaders,
+ @Nonnull final RootReaderCustomizer<C, B> customizer,
+ @Nonnull final TraversalType traversalType) {
+ super(managedDataObjectType, childReaders, augReaders, traversalType);
this.customizer = customizer;
}
diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/AbstractCompositeWriter.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/AbstractCompositeWriter.java
index e971fbeff..1e4d1361a 100644
--- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/AbstractCompositeWriter.java
+++ b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/AbstractCompositeWriter.java
@@ -20,10 +20,11 @@ import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
-import io.fd.honeycomb.v3po.translate.TranslationException;
+import io.fd.honeycomb.v3po.translate.impl.TraversalType;
+import io.fd.honeycomb.v3po.translate.util.RWUtils;
import io.fd.honeycomb.v3po.translate.write.ChildWriter;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
-import io.fd.honeycomb.v3po.translate.util.RWUtils;
+import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
import io.fd.honeycomb.v3po.translate.write.Writer;
import java.util.ArrayList;
import java.util.Collection;
@@ -46,21 +47,42 @@ public abstract class AbstractCompositeWriter<D extends DataObject> implements W
private final Map<Class<? extends DataObject>, ChildWriter<? extends ChildOf<D>>> childWriters;
private final Map<Class<? extends DataObject>, ChildWriter<? extends Augmentation<D>>> augWriters;
private final InstanceIdentifier<D> instanceIdentifier;
+ private TraversalType traversalType;
public AbstractCompositeWriter(final Class<D> type,
final List<ChildWriter<? extends ChildOf<D>>> childWriters,
- final List<ChildWriter<? extends Augmentation<D>>> augWriters) {
+ final List<ChildWriter<? extends Augmentation<D>>> augWriters,
+ final TraversalType traversalType) {
+ this.traversalType = traversalType;
this.instanceIdentifier = InstanceIdentifier.create(type);
this.childWriters = RWUtils.uniqueLinkedIndex(childWriters, RWUtils.MANAGER_CLASS_FUNCTION);
this.augWriters = RWUtils.uniqueLinkedIndex(augWriters, RWUtils.MANAGER_CLASS_AUG_FUNCTION);
}
- protected void writeCurrent(final InstanceIdentifier<D> id, final D data, final WriteContext ctx) {
+ protected void writeCurrent(final InstanceIdentifier<D> id, final D data, final WriteContext ctx)
+ throws WriteFailedException {
LOG.debug("{}: Writing current: {} data: {}", this, id, data);
- LOG.trace("{}: Writing current attributes", this);
- writeCurrentAttributes(id, data, ctx);
+ switch (traversalType) {
+ case PREORDER: {
+ LOG.trace("{}: Writing current attributes", this);
+ writeCurrentAttributes(id, data, ctx);
+ writeChildren(id, data, ctx);
+ break;
+ }
+ case POSTORDER: {
+ writeChildren(id, data, ctx);
+ LOG.trace("{}: Writing current attributes", this);
+ writeCurrentAttributes(id, data, ctx);
+ break;
+ }
+ }
+ LOG.debug("{}: Current node written successfully", this);
+ }
+
+ private void writeChildren(final InstanceIdentifier<D> id, final D data, final WriteContext ctx)
+ throws WriteFailedException {
for (ChildWriter<? extends ChildOf<D>> child : childWriters.values()) {
LOG.debug("{}: Writing child in: {}", this, child);
child.writeChild(id, data, ctx);
@@ -70,23 +92,38 @@ public abstract class AbstractCompositeWriter<D extends DataObject> implements W
LOG.debug("{}: Writing augment in: {}", this, child);
child.writeChild(id, data, ctx);
}
-
- LOG.debug("{}: Current node written successfully", this);
}
protected void updateCurrent(final InstanceIdentifier<D> id, final D dataBefore, final D dataAfter,
- final WriteContext ctx) {
+ final WriteContext ctx) throws WriteFailedException {
LOG.debug("{}: Updating current: {} dataBefore: {}, datAfter: {}", this, id, dataBefore, dataAfter);
- if(dataBefore.equals(dataAfter)) {
+ if (dataBefore.equals(dataAfter)) {
LOG.debug("{}: Skipping current(no update): {}", this, id);
// No change, ignore
return;
}
- LOG.trace("{}: Updating current attributes", this);
- updateCurrentAttributes(id, dataBefore, dataAfter, ctx);
+ switch (traversalType) {
+ case PREORDER: {
+ LOG.trace("{}: Updating current attributes", this);
+ updateCurrentAttributes(id, dataBefore, dataAfter, ctx);
+ updateChildren(id, dataBefore, dataAfter, ctx);
+ break;
+ }
+ case POSTORDER: {
+ updateChildren(id, dataBefore, dataAfter, ctx);
+ LOG.trace("{}: Updating current attributes", this);
+ updateCurrentAttributes(id, dataBefore, dataAfter, ctx);
+ break;
+ }
+ }
+
+ LOG.debug("{}: Current node updated successfully", this);
+ }
+ private void updateChildren(final InstanceIdentifier<D> id, final D dataBefore, final D dataAfter,
+ final WriteContext ctx) throws WriteFailedException {
for (ChildWriter<? extends ChildOf<D>> child : childWriters.values()) {
LOG.debug("{}: Updating child in: {}", this, child);
child.updateChild(id, dataBefore, dataAfter, ctx);
@@ -96,14 +133,30 @@ public abstract class AbstractCompositeWriter<D extends DataObject> implements W
LOG.debug("{}: Updating augment in: {}", this, child);
child.updateChild(id, dataBefore, dataAfter, ctx);
}
-
- LOG.debug("{}: Current node updated successfully", this);
}
- protected void deleteCurrent(final InstanceIdentifier<D> id, final D dataBefore, final WriteContext ctx) {
+ protected void deleteCurrent(final InstanceIdentifier<D> id, final D dataBefore, final WriteContext ctx)
+ throws WriteFailedException {
LOG.debug("{}: Deleting current: {} dataBefore: {}", this, id, dataBefore);
- // delete in reversed order
+ switch (traversalType) {
+ case PREORDER: {
+ deleteChildren(id, dataBefore, ctx);
+ LOG.trace("{}: Deleting current attributes", this);
+ deleteCurrentAttributes(id, dataBefore, ctx);
+ break;
+ }
+ case POSTORDER: {
+ LOG.trace("{}: Deleting current attributes", this);
+ deleteCurrentAttributes(id, dataBefore, ctx);
+ deleteChildren(id, dataBefore, ctx);
+ break;
+ }
+ }
+ }
+
+ private void deleteChildren(final InstanceIdentifier<D> id, final D dataBefore, final WriteContext ctx)
+ throws WriteFailedException {
for (ChildWriter<? extends Augmentation<D>> child : reverseCollection(augWriters.values())) {
LOG.debug("{}: Deleting augment in: {}", this, child);
child.deleteChild(id, dataBefore, ctx);
@@ -113,9 +166,6 @@ public abstract class AbstractCompositeWriter<D extends DataObject> implements W
LOG.debug("{}: Deleting child in: {}", this, child);
child.deleteChild(id, dataBefore, ctx);
}
-
- LOG.trace("{}: Deleting current attributes", this);
- deleteCurrentAttributes(id, dataBefore, ctx);
}
@SuppressWarnings("unchecked")
@@ -123,7 +173,7 @@ public abstract class AbstractCompositeWriter<D extends DataObject> implements W
public void update(@Nonnull final InstanceIdentifier<? extends DataObject> id,
@Nullable final DataObject dataBefore,
@Nullable final DataObject dataAfter,
- @Nonnull final WriteContext ctx) throws TranslationException {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
LOG.debug("{}: Updating : {}", this, id);
LOG.trace("{}: Updating : {}, from: {} to: {}", this, id, dataBefore, dataAfter);
@@ -168,7 +218,7 @@ public abstract class AbstractCompositeWriter<D extends DataObject> implements W
}
private void writeSubtree(final InstanceIdentifier<? extends DataObject> id,
- final DataObject dataAfter, final WriteContext ctx) throws TranslationException {
+ final DataObject dataAfter, final WriteContext ctx) throws WriteFailedException {
LOG.debug("{}: Writing subtree: {}", this, id);
final Writer<? extends ChildOf<D>> writer = getNextWriter(id);
@@ -190,9 +240,8 @@ public abstract class AbstractCompositeWriter<D extends DataObject> implements W
return id.getTargetType().equals(getManagedDataObjectType().getTargetType());
}
- @SuppressWarnings("unchecked")
private void deleteSubtree(final InstanceIdentifier<? extends DataObject> id,
- final DataObject dataBefore, final WriteContext ctx) throws TranslationException {
+ final DataObject dataBefore, final WriteContext ctx) throws WriteFailedException {
LOG.debug("{}: Deleting subtree: {}", this, id);
final Writer<? extends ChildOf<D>> writer = getNextWriter(id);
@@ -205,7 +254,8 @@ public abstract class AbstractCompositeWriter<D extends DataObject> implements W
}
@SuppressWarnings("unchecked")
- private void updateSubtreeFromCurrent(final InstanceIdentifier<? extends DataObject> id, final WriteContext ctx) {
+ private void updateSubtreeFromCurrent(final InstanceIdentifier<? extends DataObject> id, final WriteContext ctx)
+ throws WriteFailedException {
final InstanceIdentifier<D> currentId = RWUtils.cutId(id, getManagedDataObjectType());
Optional<DataObject> currentDataBefore = ctx.readBefore(currentId);
Optional<DataObject> currentDataAfter = ctx.readAfter(currentId);
@@ -215,11 +265,10 @@ public abstract class AbstractCompositeWriter<D extends DataObject> implements W
castToManaged(currentDataAfter.orNull()), ctx);
}
- @SuppressWarnings("unchecked")
private void updateSubtree(final InstanceIdentifier<? extends DataObject> id,
final DataObject dataBefore,
final DataObject dataAfter,
- final WriteContext ctx) throws TranslationException {
+ final WriteContext ctx) throws WriteFailedException {
LOG.debug("{}: Updating subtree: {}", this, id);
final Writer<? extends ChildOf<D>> writer = getNextWriter(id);
@@ -245,16 +294,16 @@ public abstract class AbstractCompositeWriter<D extends DataObject> implements W
protected abstract void writeCurrentAttributes(@Nonnull final InstanceIdentifier<D> id,
@Nonnull final D data,
- @Nonnull final WriteContext ctx);
+ @Nonnull final WriteContext ctx) throws WriteFailedException;
protected abstract void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<D> id,
@Nonnull final D dataBefore,
- @Nonnull final WriteContext ctx);
+ @Nonnull final WriteContext ctx) throws WriteFailedException;
protected abstract void updateCurrentAttributes(@Nonnull final InstanceIdentifier<D> id,
@Nonnull final D dataBefore,
@Nonnull final D dataAfter,
- @Nonnull final WriteContext ctx);
+ @Nonnull final WriteContext ctx) throws WriteFailedException;
@Nonnull
@Override
diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeChildWriter.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeChildWriter.java
index fbfeffbdb..512eb44d9 100644
--- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeChildWriter.java
+++ b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeChildWriter.java
@@ -17,10 +17,12 @@
package io.fd.honeycomb.v3po.translate.impl.write;
import com.google.common.base.Optional;
+import io.fd.honeycomb.v3po.translate.impl.TraversalType;
import io.fd.honeycomb.v3po.translate.write.ChildWriter;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.util.RWUtils;
import io.fd.honeycomb.v3po.translate.spi.write.ChildWriterCustomizer;
+import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
import java.util.List;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.binding.Augmentation;
@@ -37,7 +39,16 @@ public class CompositeChildWriter<D extends DataObject> extends AbstractComposit
@Nonnull final List<ChildWriter<? extends ChildOf<D>>> childWriters,
@Nonnull final List<ChildWriter<? extends Augmentation<D>>> augWriters,
@Nonnull final ChildWriterCustomizer<D> customizer) {
- super(type, childWriters, augWriters);
+ this(type, childWriters, augWriters, customizer, TraversalType.PREORDER);
+ }
+
+
+ public CompositeChildWriter(@Nonnull final Class<D> type,
+ @Nonnull final List<ChildWriter<? extends ChildOf<D>>> childWriters,
+ @Nonnull final List<ChildWriter<? extends Augmentation<D>>> augWriters,
+ @Nonnull final ChildWriterCustomizer<D> customizer,
+ @Nonnull final TraversalType traversalType) {
+ super(type, childWriters, augWriters, traversalType);
this.customizer = customizer;
}
@@ -54,25 +65,27 @@ public class CompositeChildWriter<D extends DataObject> extends AbstractComposit
@Override
protected void writeCurrentAttributes(@Nonnull final InstanceIdentifier<D> id, @Nonnull final D data,
- @Nonnull final WriteContext ctx) {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
customizer.writeCurrentAttributes(id, data, ctx.getContext());
}
@Override
protected void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<D> id, @Nonnull final D dataBefore,
- @Nonnull WriteContext ctx) {
+ @Nonnull WriteContext ctx) throws WriteFailedException {
customizer.deleteCurrentAttributes(id, dataBefore, ctx.getContext());
}
@Override
protected void updateCurrentAttributes(@Nonnull final InstanceIdentifier<D> id, @Nonnull final D dataBefore,
- @Nonnull final D dataAfter, @Nonnull WriteContext ctx) {
+ @Nonnull final D dataAfter, @Nonnull WriteContext ctx)
+ throws WriteFailedException {
customizer.updateCurrentAttributes(id, dataBefore, dataAfter, ctx.getContext());
}
@Override
public void writeChild(@Nonnull final InstanceIdentifier<? extends DataObject> parentId,
- @Nonnull final DataObject parentData, @Nonnull WriteContext ctx) {
+ @Nonnull final DataObject parentData, @Nonnull WriteContext ctx)
+ throws WriteFailedException {
final InstanceIdentifier<D> currentId = RWUtils.appendTypeToId(parentId, getManagedDataObjectType());
final Optional<D> currentData = customizer.extract(currentId, parentData);
if(currentData.isPresent()) {
@@ -83,7 +96,7 @@ public class CompositeChildWriter<D extends DataObject> extends AbstractComposit
@Override
public void deleteChild(@Nonnull final InstanceIdentifier<? extends DataObject> parentId,
@Nonnull final DataObject parentData,
- @Nonnull final WriteContext ctx) {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
final InstanceIdentifier<D> currentId = RWUtils.appendTypeToId(parentId, getManagedDataObjectType());
final Optional<D> currentData = customizer.extract(currentId, parentData);
if(currentData.isPresent()) {
@@ -94,7 +107,7 @@ public class CompositeChildWriter<D extends DataObject> extends AbstractComposit
@Override
public void updateChild(@Nonnull final InstanceIdentifier<? extends DataObject> parentId,
@Nonnull final DataObject parentDataBefore, @Nonnull final DataObject parentDataAfter,
- @Nonnull final WriteContext ctx) {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
final InstanceIdentifier<D> currentId = RWUtils.appendTypeToId(parentId, getManagedDataObjectType());
final Optional<D> before = customizer.extract(currentId, parentDataBefore);
final Optional<D> after = customizer.extract(currentId, parentDataAfter);
diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeListWriter.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeListWriter.java
index dc924fe39..967edb6a9 100644
--- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeListWriter.java
+++ b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeListWriter.java
@@ -20,10 +20,12 @@ import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import io.fd.honeycomb.v3po.translate.impl.TraversalType;
import io.fd.honeycomb.v3po.translate.spi.write.ListWriterCustomizer;
import io.fd.honeycomb.v3po.translate.write.ChildWriter;
import io.fd.honeycomb.v3po.translate.write.WriteContext;
import io.fd.honeycomb.v3po.translate.util.RWUtils;
+import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
@@ -54,7 +56,15 @@ public class CompositeListWriter<D extends DataObject & Identifiable<K>, K exten
@Nonnull final List<ChildWriter<? extends ChildOf<D>>> childWriters,
@Nonnull final List<ChildWriter<? extends Augmentation<D>>> augWriters,
@Nonnull final ListWriterCustomizer<D, K> customizer) {
- super(type, childWriters, augWriters);
+ this(type, childWriters, augWriters, customizer, TraversalType.PREORDER);
+ }
+
+ public CompositeListWriter(@Nonnull final Class<D> type,
+ @Nonnull final List<ChildWriter<? extends ChildOf<D>>> childWriters,
+ @Nonnull final List<ChildWriter<? extends Augmentation<D>>> augWriters,
+ @Nonnull final ListWriterCustomizer<D, K> customizer,
+ @Nonnull final TraversalType traversalType) {
+ super(type, childWriters, augWriters, traversalType);
this.customizer = customizer;
}
@@ -72,26 +82,27 @@ public class CompositeListWriter<D extends DataObject & Identifiable<K>, K exten
@Override
protected void writeCurrentAttributes(@Nonnull final InstanceIdentifier<D> id, @Nonnull final D data,
- @Nonnull final WriteContext ctx) {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
customizer.writeCurrentAttributes(id, data, ctx.getContext());
}
@Override
protected void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<D> id, @Nonnull final D dataBefore,
- @Nonnull final WriteContext ctx) {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
customizer.deleteCurrentAttributes(id, dataBefore, ctx.getContext());
}
@Override
protected void updateCurrentAttributes(@Nonnull final InstanceIdentifier<D> id, @Nonnull final D dataBefore,
- @Nonnull final D dataAfter, @Nonnull final WriteContext ctx) {
+ @Nonnull final D dataAfter, @Nonnull final WriteContext ctx)
+ throws WriteFailedException {
customizer.updateCurrentAttributes(id, dataBefore, dataAfter, ctx.getContext());
}
@Override
public void writeChild(@Nonnull final InstanceIdentifier<? extends DataObject> parentId,
@Nonnull final DataObject parentData,
- @Nonnull final WriteContext ctx) {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
final InstanceIdentifier<D> currentId = RWUtils.appendTypeToId(parentId, getManagedDataObjectType());
final List<D> currentData = customizer.extract(currentId, parentData);
for (D entry : currentData) {
@@ -102,7 +113,7 @@ public class CompositeListWriter<D extends DataObject & Identifiable<K>, K exten
@Override
public void deleteChild(@Nonnull final InstanceIdentifier<? extends DataObject> parentId,
@Nonnull final DataObject parentDataBefore,
- @Nonnull final WriteContext ctx) {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
final InstanceIdentifier<D> currentId = RWUtils.appendTypeToId(parentId, getManagedDataObjectType());
final List<D> dataBefore = customizer.extract(currentId, parentDataBefore);
for (D entry : dataBefore) {
@@ -113,7 +124,7 @@ public class CompositeListWriter<D extends DataObject & Identifiable<K>, K exten
@Override
public void updateChild(@Nonnull final InstanceIdentifier<? extends DataObject> parentId,
@Nonnull final DataObject parentDataBefore, @Nonnull final DataObject parentDataAfter,
- @Nonnull final WriteContext ctx) {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
final InstanceIdentifier<D> currentId = RWUtils.appendTypeToId(parentId, getManagedDataObjectType());
final ImmutableMap<Object, D>
dataBefore = Maps.uniqueIndex(customizer.extract(currentId, parentDataBefore), INDEX_FUNCTION);
@@ -138,7 +149,8 @@ public class CompositeListWriter<D extends DataObject & Identifiable<K>, K exten
}
@Override
- protected void writeCurrent(final InstanceIdentifier<D> id, final D data, final WriteContext ctx) {
+ protected void writeCurrent(final InstanceIdentifier<D> id, final D data, final WriteContext ctx)
+ throws WriteFailedException {
// Make sure the key is present
if(isWildcarded(id)) {
super.writeCurrent(getSpecificId(id, data), data, ctx);
@@ -149,7 +161,7 @@ public class CompositeListWriter<D extends DataObject & Identifiable<K>, K exten
@Override
protected void updateCurrent(final InstanceIdentifier<D> id, final D dataBefore, final D dataAfter,
- final WriteContext ctx) {
+ final WriteContext ctx) throws WriteFailedException {
// Make sure the key is present
if(isWildcarded(id)) {
super.updateCurrent(getSpecificId(id, dataBefore), dataBefore, dataAfter, ctx);
@@ -159,7 +171,8 @@ public class CompositeListWriter<D extends DataObject & Identifiable<K>, K exten
}
@Override
- protected void deleteCurrent(final InstanceIdentifier<D> id, final D dataBefore, final WriteContext ctx) {
+ protected void deleteCurrent(final InstanceIdentifier<D> id, final D dataBefore, final WriteContext ctx)
+ throws WriteFailedException {
// Make sure the key is present
if(isWildcarded(id)) {
super.deleteCurrent(getSpecificId(id, dataBefore), dataBefore, ctx);
diff --git a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeRootWriter.java b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeRootWriter.java
index acf2cfd2e..5e4ff86ad 100644
--- a/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeRootWriter.java
+++ b/v3po/translate-impl/src/main/java/io/fd/honeycomb/v3po/translate/impl/write/CompositeRootWriter.java
@@ -16,10 +16,12 @@
package io.fd.honeycomb.v3po.translate.impl.write;
-import io.fd.honeycomb.v3po.translate.write.WriteContext;
-import io.fd.honeycomb.v3po.translate.util.RWUtils;
+import io.fd.honeycomb.v3po.translate.impl.TraversalType;
import io.fd.honeycomb.v3po.translate.spi.write.RootWriterCustomizer;
+import io.fd.honeycomb.v3po.translate.util.RWUtils;
import io.fd.honeycomb.v3po.translate.write.ChildWriter;
+import io.fd.honeycomb.v3po.translate.write.WriteContext;
+import io.fd.honeycomb.v3po.translate.write.WriteFailedException;
import java.util.List;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.binding.Augmentation;
@@ -35,7 +37,15 @@ public class CompositeRootWriter<D extends DataObject> extends AbstractComposite
@Nonnull final List<ChildWriter<? extends ChildOf<D>>> childWriters,
@Nonnull final List<ChildWriter<? extends Augmentation<D>>> augWriters,
@Nonnull final RootWriterCustomizer<D> customizer) {
- super(type, childWriters, augWriters);
+ this(type, childWriters, augWriters, customizer, TraversalType.PREORDER);
+ }
+
+ public CompositeRootWriter(@Nonnull final Class<D> type,
+ @Nonnull final List<ChildWriter<? extends ChildOf<D>>> childWriters,
+ @Nonnull final List<ChildWriter<? extends Augmentation<D>>> augWriters,
+ @Nonnull final RootWriterCustomizer<D> customizer,
+ @Nonnull final TraversalType traversalType) {
+ super(type, childWriters, augWriters, traversalType);
this.customizer = customizer;
}
@@ -52,13 +62,15 @@ public class CompositeRootWriter<D extends DataObject> extends AbstractComposite
@Override
protected void writeCurrentAttributes(@Nonnull final InstanceIdentifier<D> id, @Nonnull final D data,
- @Nonnull final WriteContext ctx) {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
+ // TODO wrap all customizer invocations in try catch, and wrap runtime exceptions in ReadFailed
+ // TODO same for readers
customizer.writeCurrentAttributes(id, data, ctx.getContext());
}
@Override
protected void deleteCurrentAttributes(@Nonnull final InstanceIdentifier<D> id, @Nonnull final D dataBefore,
- @Nonnull final WriteContext ctx) {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
customizer.deleteCurrentAttributes(id, dataBefore, ctx.getContext());
}
@@ -66,7 +78,7 @@ public class CompositeRootWriter<D extends DataObject> extends AbstractComposite
protected void updateCurrentAttributes(@Nonnull final InstanceIdentifier<D> id,
@Nonnull final D dataBefore,
@Nonnull final D dataAfter,
- @Nonnull final WriteContext ctx) {
+ @Nonnull final WriteContext ctx) throws WriteFailedException {
customizer.updateCurrentAttributes(id, dataBefore, dataAfter, ctx.getContext());
}
}