From 62e17ed95de8c1e62848ba2949994bd372128ddc Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 22 Aug 2014 19:27:48 +0200 Subject: [PATCH] BUG-1605: Fixup yang-data-api interface Now that the binding interface is ready to handle IOExceptions, adjust the data-api interface and implementations. At the same time we update the binding world to forward calls to flush(). Change-Id: I8a4cff13123d618634dcd61587a2432d3d49ae8b Signed-off-by: Robert Varga --- .../impl/BindingToNormalizedStreamWriter.java | 2 + .../stream/NormalizedNodeStreamWriter.java | 68 ++++++++++++------- .../ImmutableNormalizedNodeStreamWriter.java | 20 ++++-- 3 files changed, 61 insertions(+), 29 deletions(-) diff --git a/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingToNormalizedStreamWriter.java b/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingToNormalizedStreamWriter.java index 3c9a960eac..9c12bbd42a 100644 --- a/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingToNormalizedStreamWriter.java +++ b/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingToNormalizedStreamWriter.java @@ -187,9 +187,11 @@ class BindingToNormalizedStreamWriter implements BindingStreamEventWriter, Deleg @Override public void flush() throws IOException { + getDelegate().flush(); } @Override public void close() throws IOException { + getDelegate().close(); } } diff --git a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamWriter.java b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamWriter.java index 96b5c15e91..13d314282a 100644 --- a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamWriter.java +++ b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizedNodeStreamWriter.java @@ -7,6 +7,10 @@ */ package org.opendaylight.yangtools.yang.data.api.schema.stream; +import java.io.Closeable; +import java.io.Flushable; +import java.io.IOException; + import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; @@ -34,13 +38,13 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent * and finished using {@link #endNode()}. * *
  • UnkeyedList - Unkeyed list represent list without keys, - * unkeyed list start is emmited using {@link #startUnkeyedList(NodeIdentifier, int)} list - * end is emmited using {@link #endNode()}. Each list item is emmited using + * unkeyed list start is emitted using {@link #startUnkeyedList(NodeIdentifier, int)} list + * end is emitted using {@link #endNode()}. Each list item is emitted using * {@link #startUnkeyedListItem(NodeIdentifier, int)} and ended using {@link #endNode()}.
  • * * *
  • leaf - Leaf node event is emitted using - * {@link #leafNode(NodeIdentifier, Object)}. {@link #endNode()} MUST NOT BE emmited for + * {@link #leafNode(NodeIdentifier, Object)}. {@link #endNode()} MUST NOT BE emitted for * leaf node.
  • * *
  • leaf-list - Leaf list start is emitted using @@ -49,7 +53,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent * {@link #leafSetEntryNode(Object). * *
  • anyxml - Anyxml node event is emitted using - * {@link #leafNode(NodeIdentifier, Object)}. {@link #endNode()} MUST NOT BE emmited + * {@link #leafNode(NodeIdentifier, Object)}. {@link #endNode()} MUST NOT BE emitted * for anyxml node.
  • * * @@ -70,11 +74,11 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent * and resources needlessly. * */ -public interface NormalizedNodeStreamWriter { +public interface NormalizedNodeStreamWriter extends Closeable, Flushable { /** * Methods in this interface allow users to hint the underlying - * implementation about the sizing of container-like constructurs + * implementation about the sizing of container-like constructors * (leafLists, containers, etc.). These hints may be taken into account by a * particular implementation to improve performance, but clients are not * required to provide hints. This constant should be used by clients who @@ -105,8 +109,9 @@ public interface NormalizedNodeStreamWriter { * @throws IllegalStateException * If node was emitted inside map, * choice unkeyed list node. + * @throws IOException if an underlying IO error occurs */ - void leafNode(NodeIdentifier name, Object value) throws IllegalArgumentException; + void leafNode(NodeIdentifier name, Object value) throws IOException, IllegalArgumentException; /** * @@ -130,8 +135,9 @@ public interface NormalizedNodeStreamWriter { * @throws IllegalStateException * If node was emitted inside map, * choice unkeyed list node. + * @throws IOException if an underlying IO error occurs */ - void startLeafSet(NodeIdentifier name, int childSizeHint) throws IllegalArgumentException; + void startLeafSet(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; /** * Emits a leaf set entry node @@ -142,8 +148,9 @@ public interface NormalizedNodeStreamWriter { * If emitted leaf node has invalid value. * @throws IllegalStateException * If node was emitted outside leaf set node. + * @throws IOException if an underlying IO error occurs */ - void leafSetEntryNode(Object value) throws IllegalArgumentException; + void leafSetEntryNode(Object value) throws IOException, IllegalArgumentException; /** * @@ -161,8 +168,8 @@ public interface NormalizedNodeStreamWriter { *
  • {@link #startLeafSet(NodeIdentifier, int)}
  • *
  • {@link #startMapNode(NodeIdentifier, int)}
  • *
  • {@link #startUnkeyedList(NodeIdentifier, int)}
  • - *
  • {@link #startAugmentationNode(AugmentationIdentifier)}
  • - * + *
  • {@link #startAugmentationNode(AugmentationIdentifier)}
  • + * * * @param name * name of node as defined in schema, namespace and revision are @@ -178,8 +185,9 @@ public interface NormalizedNodeStreamWriter { * @throws IllegalStateException * If node was emitted inside map, * choice unkeyed list node. + * @throws IOException if an underlying IO error occurs */ - void startContainerNode(NodeIdentifier name, int childSizeHint) throws IllegalArgumentException; + void startContainerNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; /** * @@ -204,8 +212,9 @@ public interface NormalizedNodeStreamWriter { * @throws IllegalStateException * If node was emitted inside map, * choice unkeyed list node. + * @throws IOException if an underlying IO error occurs */ - void startUnkeyedList(NodeIdentifier name, int childSizeHint) throws IllegalArgumentException; + void startUnkeyedList(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; /** * Emits start of new unkeyed list item. @@ -231,8 +240,9 @@ public interface NormalizedNodeStreamWriter { * events than count. * @throws IllegalStateException * If node was emitted outside unkeyed list node. + * @throws IOException if an underlying IO error occurs */ - void startUnkeyedListItem(NodeIdentifier name, int childSizeHint) throws IllegalStateException; + void startUnkeyedListItem(NodeIdentifier name, int childSizeHint) throws IOException, IllegalStateException; /** * @@ -252,8 +262,9 @@ public interface NormalizedNodeStreamWriter { * @throws IllegalStateException * If node was emitted inside map, * choice unkeyed list node. + * @throws IOException if an underlying IO error occurs */ - void startMapNode(NodeIdentifier name, int childSizeHint) throws IllegalArgumentException; + void startMapNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; /** * @@ -281,8 +292,9 @@ public interface NormalizedNodeStreamWriter { * If key contains incorrect value. * @throws IllegalStateException * If node was emitted outside map entry node. + * @throws IOException if an underlying IO error occurs */ - void startMapEntryNode(NodeIdentifierWithPredicates identifier, int childSizeHint) throws IllegalArgumentException; + void startMapEntryNode(NodeIdentifierWithPredicates identifier, int childSizeHint) throws IOException, IllegalArgumentException; /** * @@ -301,8 +313,9 @@ public interface NormalizedNodeStreamWriter { * @throws IllegalStateException * If node was emitted inside map, * choice unkeyed list node. + * @throws IOException if an underlying IO error occurs */ - void startOrderedMapNode(NodeIdentifier name, int childSizeHint) throws IllegalArgumentException; + void startOrderedMapNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; /** * @@ -316,8 +329,9 @@ public interface NormalizedNodeStreamWriter { * @throws IllegalStateException * If node was emitted inside map, * choice unkeyed list node. + * @throws IOException if an underlying IO error occurs */ - void startChoiceNode(NodeIdentifier name, int childSizeHint) throws IllegalArgumentException; + void startChoiceNode(NodeIdentifier name, int childSizeHint) throws IOException, IllegalArgumentException; /** * Emits start of augmentation node. @@ -341,28 +355,34 @@ public interface NormalizedNodeStreamWriter { * Augmentation identifier * @throws IllegalArgumentException * If augmentation is invalid in current context. + * @throws IOException if an underlying IO error occurs */ - void startAugmentationNode(AugmentationIdentifier identifier) throws IllegalArgumentException; + void startAugmentationNode(AugmentationIdentifier identifier) throws IOException, IllegalArgumentException; /** * Emits anyxml node event. * - * * @param name * @param value * @throws IllegalArgumentException * @throws IllegalStateException * If node was emitted inside map, * choice unkeyed list node. + * @throws IOException if an underlying IO error occurs */ - void anyxmlNode(NodeIdentifier name, Object value) throws IllegalArgumentException; + void anyxmlNode(NodeIdentifier name, Object value) throws IOException, IllegalArgumentException; /** * Emits end event for node. * - * @throws IllegalStateException If there is no start* event to be closed.B - * + * @throws IllegalStateException If there is no start* event to be closed. + * @throws IOException if an underlying IO error occurs */ - void endNode() throws IllegalStateException; + void endNode() throws IOException, IllegalStateException; + + @Override + void close() throws IOException; + @Override + void flush() throws IOException; } diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriter.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriter.java index a0b54900be..c39c2ecd78 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriter.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNormalizedNodeStreamWriter.java @@ -8,9 +8,12 @@ package org.opendaylight.yangtools.yang.data.impl.schema; import com.google.common.base.Preconditions; + +import java.io.IOException; import java.util.ArrayDeque; import java.util.Deque; import java.util.List; + import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; @@ -43,15 +46,11 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUn */ public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStreamWriter { - - @SuppressWarnings("rawtypes") - private final Deque builders; - + private final Deque builders = new ArrayDeque<>(); @SuppressWarnings("rawtypes") private ImmutableNormalizedNodeStreamWriter( final NormalizedNodeContainerBuilder topLevelBuilder) { - builders = new ArrayDeque<>(); builders.push(topLevelBuilder); } @@ -252,4 +251,15 @@ public class ImmutableNormalizedNodeStreamWriter implements NormalizedNodeStream } + @Override + public void flush() { + // no-op + } + + @Override + public void close() throws IOException { + // TODO Auto-generated method stub + + } + } -- 2.36.6