Revert "Revert "Bug 3874: Support of yang modeled AnyXML - API""
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / stream / NormalizedNodeStreamWriter.java
index 96b5c15e91e933f0075c0eb9f1e6f446c332b4f9..983378703e57f72694db34748f7011b008484fd6 100644 (file)
@@ -7,6 +7,9 @@
  */
 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;
@@ -21,11 +24,11 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
  * <li><code>container</code> - Container node representation, start event is
  * emitted using {@link #startContainerNode(NodeIdentifier, int)} and node end event is
  * emitted using {@link #endNode()}. Container node is implementing
- * {@link DataObject} interface.
+ * the org.opendaylight.yangtools.yang.binding.DataObject interface.
  *
  * <li><code>list</code> - YANG list statement has two representation in event
  * stream - unkeyed list and map. Unkeyed list is YANG list which did not
- * specify key.</li>
+ * specify key.
  *
  * <ul>
  * <li><code>Map</code> - Map start event is emitted using
@@ -34,22 +37,22 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
  * and finished using {@link #endNode()}.</li>
  *
  * <li><code>UnkeyedList</code> - 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()}.</li>
- * </ul>
+ * </ul></li>
  *
  * <li><code>leaf</code> - 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.</li>
  *
  * <li><code>leaf-list</code> - Leaf list start is emitted using
  * {@link #startLeafSet(NodeIdentifier, int)}. Leaf list end is emitted using
  * {@link #endNode()}. Leaf list entries are emmited using
- * {@link #leafSetEntryNode(Object).
+ * {@link #leafSetEntryNode(Object)}.
  *
- * <li><code>anyxml - Anyxml node event is emitted using
- * {@link #leafNode(NodeIdentifier, Object)}. {@link #endNode()} MUST NOT BE emmited
+ * <li><code>anyxml - AN node event is emitted using
+ * {@link #leafNode(NodeIdentifier, Object)}. {@link #endNode()} MUST NOT BE emitted
  * for anyxml node.</code></li>
  *
  *
@@ -70,11 +73,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
@@ -88,7 +91,7 @@ public interface NormalizedNodeStreamWriter {
      * all other values will result, based on implementation preference, in the
      * hint being completely ignored or IllegalArgumentException being thrown.
      */
-    public final int UNKNOWN_SIZE = -1;
+    int UNKNOWN_SIZE = -1;
 
     /**
      *
@@ -105,8 +108,9 @@ public interface NormalizedNodeStreamWriter {
      * @throws IllegalStateException
      *             If node was emitted inside <code>map</code>,
      *             <code>choice</code> <code>unkeyed list</code> 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;
 
     /**
      *
@@ -130,8 +134,9 @@ public interface NormalizedNodeStreamWriter {
      * @throws IllegalStateException
      *             If node was emitted inside <code>map</code>,
      *             <code>choice</code> <code>unkeyed list</code> 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;
 
     /**
      * Emits a leaf set entry node
@@ -142,8 +147,9 @@ public interface NormalizedNodeStreamWriter {
      *             If emitted leaf node has invalid value.
      * @throws IllegalStateException
      *             If node was emitted outside <code>leaf set</code> node.
+     * @throws IOException if an underlying IO error occurs
      */
-    void leafSetEntryNode(Object value) throws IllegalArgumentException;
+    void leafSetEntryNode(Object value) throws IOException;
 
     /**
      *
@@ -161,8 +167,8 @@ public interface NormalizedNodeStreamWriter {
      * <li>{@link #startLeafSet(NodeIdentifier, int)}</li>
      * <li>{@link #startMapNode(NodeIdentifier, int)}</li>
      * <li>{@link #startUnkeyedList(NodeIdentifier, int)}</li>
-    * <li>{@link #startAugmentationNode(AugmentationIdentifier)}</li>
-    * </ul>
+     * <li>{@link #startAugmentationNode(AugmentationIdentifier)}</li>
+     * </ul>
      *
      * @param name
      *            name of node as defined in schema, namespace and revision are
@@ -178,8 +184,9 @@ public interface NormalizedNodeStreamWriter {
      * @throws IllegalStateException
      *             If node was emitted inside <code>map</code>,
      *             <code>choice</code> <code>unkeyed list</code> 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;
 
     /**
      *
@@ -204,8 +211,9 @@ public interface NormalizedNodeStreamWriter {
      * @throws IllegalStateException
      *             If node was emitted inside <code>map</code>,
      *             <code>choice</code> <code>unkeyed list</code> 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;
 
     /**
      * Emits start of new unkeyed list item.
@@ -231,8 +239,9 @@ public interface NormalizedNodeStreamWriter {
      *            events than count.
      * @throws IllegalStateException
      *             If node was emitted outside <code>unkeyed list</code> 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;
 
     /**
      *
@@ -248,12 +257,19 @@ public interface NormalizedNodeStreamWriter {
      *            name of node as defined in schema, namespace and revision are
      *            derived from parent node.
      * @param childSizeHint
+     *            Non-negative count of expected direct child nodes or
+     *            {@link #UNKNOWN_SIZE} if count is unknown. This is only hint
+     *            and should not fail writing of child events, if there are more
+     *            events than count.
      * @throws IllegalArgumentException
+     *             If emitted node is invalid in current context or was emitted
+     *             multiple times.
      * @throws IllegalStateException
      *             If node was emitted inside <code>map</code>,
      *             <code>choice</code> <code>unkeyed list</code> 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;
 
     /**
      *
@@ -277,12 +293,18 @@ public interface NormalizedNodeStreamWriter {
      *
      * @param identifier
      *            QName to value pairs of keys of map entry node. Values  MUST BE constant over time.
+     * @param childSizeHint
+     *            Non-negative count of expected direct child nodes or
+     *            {@link #UNKNOWN_SIZE} if count is unknown. This is only hint
+     *            and should not fail writing of child events, if there are more
+     *            events than count.
      * @throws IllegalArgumentException
      *             If key contains incorrect value.
      * @throws IllegalStateException
      *             If node was emitted outside <code>map entry</code> 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;
 
     /**
      *
@@ -297,12 +319,20 @@ public interface NormalizedNodeStreamWriter {
      * @param name
      *            name of node as defined in schema, namespace and revision are
      *            derived from parent node.
+     * @param childSizeHint
+     *            Non-negative count of expected direct child nodes or
+     *            {@link #UNKNOWN_SIZE} if count is unknown. This is only hint
+     *            and should not fail writing of child events, if there are more
+     *            events than count.
      * @throws IllegalArgumentException
+     *             If emitted node is invalid in current context or was emitted
+     *             multiple times.
      * @throws IllegalStateException
      *             If node was emitted inside <code>map</code>,
      *             <code>choice</code> <code>unkeyed list</code> 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;
 
     /**
      *
@@ -312,12 +342,19 @@ public interface NormalizedNodeStreamWriter {
      *            name of node as defined in schema, namespace and revision are
      *            derived from parent node.
      * @param childSizeHint
+     *            Non-negative count of expected direct child nodes or
+     *            {@link #UNKNOWN_SIZE} if count is unknown. This is only hint
+     *            and should not fail writing of child events, if there are more
+     *            events than count.
      * @throws IllegalArgumentException
+     *             If emitted node is invalid in current context or was emitted
+     *             multiple times.
      * @throws IllegalStateException
      *             If node was emitted inside <code>map</code>,
      *             <code>choice</code> <code>unkeyed list</code> 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;
 
     /**
      * Emits start of augmentation node.
@@ -341,28 +378,74 @@ 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;
 
     /**
      * Emits anyxml node event.
      *
-     *
      * @param name
+     *            name of node as defined in schema, namespace and revision are
+     *            derived from parent node.
      * @param value
+     *             Value of AnyXml node.
      * @throws IllegalArgumentException
+     *             If emitted node is invalid in current context or was emitted
+     *             multiple times.
      * @throws IllegalStateException
      *             If node was emitted inside <code>map</code>,
      *             <code>choice</code> <code>unkeyed list</code> 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;
+
+    /**
+    *
+    * Emits start of new yang modeled anyXml node.
+    *
+    * <p>
+    * End of yang modeled anyXml node event is emitted by invoking {@link #endNode()}.
+    *
+    * <p>
+    * Valid sub-events are:
+    * <ul>
+    * <li>{@link #leafNode}</li>
+    * <li>{@link #startContainerNode}</li>
+    * <li>{@link #startLeafSet}</li>
+    * <li>{@link #startMapNode}</li>
+    * <li>{@link #startUnkeyedList}</li>
+    * </ul>
+    *
+    * @param name
+    *            name of node as defined in schema, namespace and revision are
+    *            derived from parent node.
+    * @param childSizeHint
+    *            Non-negative count of expected direct child nodes or
+    *            {@link #UNKNOWN_SIZE} if count is unknown. This is only hint
+    *            and should not fail writing of child events, if there are more
+    *            events than count.
+    * @throws IllegalArgumentException
+    *             If emitted node is invalid in current context or was emitted
+    *             multiple times.
+    * @throws IllegalStateException
+    *             If node was emitted inside <code>map</code>,
+    *             <code>choice</code> <code>unkeyed list</code> node.
+    * @throws IOException if an underlying IO error occurs
+    */
+    void startYangModeledAnyXmlNode(NodeIdentifier name, int childSizeHint) throws IOException;
 
     /**
      * 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;
+
+    @Override
+    void close() throws IOException;
 
+    @Override
+    void flush() throws IOException;
 }