Move NormalizedNode builders
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / stream / NormalizedNodeStreamWriter.java
index f819f082b9d831a410dfa9a4b872e360615a87b9..9a800ec2366ad09755169e0a485881c1db096091 100644 (file)
@@ -9,9 +9,11 @@ package org.opendaylight.yangtools.yang.data.api.schema.stream;
 
 import static java.util.Objects.requireNonNull;
 
+import com.google.common.annotations.Beta;
 import java.io.Closeable;
 import java.io.Flushable;
 import java.io.IOException;
+import javax.xml.transform.dom.DOMSource;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.concepts.ExtensibleObject;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
@@ -23,7 +25,7 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 /**
  * Event Stream Writer based on Normalized Node tree representation.
  *
- * <h3>Writing Event Stream</h3>
+ * <h2>Writing Event Stream</h2>
  * Each entity is emitted by invoking its corresponding {@code start*} event, optionally followed by interior events and
  * invoking {@link #endNode()}. Some entities supported nested entities, some do not, see below for restrictions.
  *
@@ -51,13 +53,13 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
  * </li>
  *
  * <li>{@code leaf} - Leaf node start event is emitted using {@link #startLeafNode(NodeIdentifier)}. Leaf node values
- * need to be emitted through {@link #nodeValue(Object)}.
+ * need to be emitted through {@link #scalarValue(Object)}.
  * </li>
  *
  * <li>{@code leaf-list} - Leaf list start is emitted using {@link #startLeafSet(NodeIdentifier, int)}. Individual
  * leaf-list entries are emitted using {@link #startLeafSetEntryNode(NodeWithValue)}.
  *
- * <li>{@code anyxml} - An anyxml node event is emitted using {@link #startAnyxmlNode(NodeIdentifier)}.</li>
+ * <li>{@code anyxml} - An anyxml node event is emitted using {@link #startAnyxmlNode(NodeIdentifier, Class)}.</li>
  *
  * <li>{@code choice} - Choice node event is emitted by {@link #startChoiceNode(NodeIdentifier, int)} event.</li>
  *
@@ -152,7 +154,7 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable,
      * Emits start of new container. Valid sub-events are:
      * <ul>
      * <li>{@link #startLeafNode}</li>
-     * <li>{@link #startAnyxmlNode(NodeIdentifier)}</li>
+     * <li>{@link #startAnyxmlNode(NodeIdentifier, Class)}</li>
      * <li>{@link #startContainerNode(NodeIdentifier, int)}</li>
      * <li>{@link #startChoiceNode(NodeIdentifier, int)}</li>
      * <li>{@link #startLeafSet(NodeIdentifier, int)}</li>
@@ -299,41 +301,46 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable,
      */
     void startAugmentationNode(AugmentationIdentifier identifier) throws IOException;
 
-    ////
+    /**
+     * Start emitting a new anydata node identified by name.
+     *
+     * @param name The name of the anydata element
+     * @param objectModel The object model of anydata content
+     * @return True if the specified object model is supported by this extension and the process of emitting the node
+     *         has started. False if the object model is not supported and the node has not started to be emitted.
+     * @throws NullPointerException if any argument is null
+     * @throws IOException if an underlying IO error occurs
+     */
+    @Beta
+    boolean startAnydataNode(NodeIdentifier name, Class<?> objectModel) throws IOException;
 
     /**
      * Emits a start of anyxml node event.
      *
      * @param name name of node as defined in schema, namespace and revision are derived from parent node.
-     * @throws NullPointerException if {@code name} is null
+     * @param objectModel The object model of anyxml content
+     * @return True if the specified object model is supported by this extension and the process of emitting the node
+     *         has started. False if the object model is not supported and the node has not started to be emitted.
+     * @throws NullPointerException if any argument is null
      * @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 choice} or a {@code unkeyed list}
      *                               node.
      * @throws IOException if an underlying IO error occurs
      */
-    void startAnyxmlNode(NodeIdentifier name) throws IOException;
+    boolean startAnyxmlNode(NodeIdentifier name, Class<?> objectModel) throws IOException;
 
     /**
-     * Emits start of new YANG-modeled anyxml node. Valid sub-events are:
-     * <ul>
-     * <li>{@link #startLeafNode}</li>
-     * <li>{@link #startContainerNode}</li>
-     * <li>{@link #startLeafSet}</li>
-     * <li>{@link #startMapNode}</li>
-     * <li>{@link #startUnkeyedList}</li>
-     * </ul>
+     * Set the value of current anyxml node. This call is only valid within the context in which an anyxml node is open.
      *
-     * @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 NullPointerException if {@code name} is null
-     * @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 choice} or a {@code unkeyed list}
-     *                               node.
+     * @param value node value
+     * @throws NullPointerException if the argument is null
+     * @throws IllegalArgumentException if the argument does not represents a valid value
+     * @throws IllegalStateException if an anyxml node is not open or if it's value has already been set and this
+     *                               implementation does not allow resetting the value.
      * @throws IOException if an underlying IO error occurs
      */
-    void startYangModeledAnyXmlNode(NodeIdentifier name, int childSizeHint) throws IOException;
+    // FIXME: 7.0.0: this probably should integrated with scalarValue()
+    void domSourceValue(DOMSource value) throws IOException;
 
     /**
      * Emits end event for node.
@@ -356,15 +363,16 @@ public interface NormalizedNodeStreamWriter extends Closeable, Flushable,
 
     /**
      * Set the value of current node. This call is only valid within the context in which a value-bearing node is open,
-     * such as a LeafNode, LeafSetEntryNode or AnyxmlNode.
+     * such as a LeafNode, LeafSetEntryNode.
      *
      * @param value node value, must be effectively immutable
      * @throws NullPointerException if the argument is null
      * @throws IllegalArgumentException if the argument does not represents a valid value
      * @throws IllegalStateException if a value-bearing node is not open or if it's value has already been set and this
      *                               implementation does not allow resetting the value.
+     * @throws IOException if an underlying IO error occurs
      */
-    void nodeValue(@NonNull Object value) throws IOException;
+    void scalarValue(@NonNull Object value) throws IOException;
 
     @Override
     void close() throws IOException;