import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.gson.stream.JsonWriter;
-
import java.io.IOException;
import java.io.Writer;
import java.net.URI;
import java.util.ArrayDeque;
import java.util.Deque;
-
import org.opendaylight.yangtools.concepts.Codec;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
/**
* This implementation will create JSON output as output stream.
this.tracker = SchemaTracker.create(schemaContext);
}
+ private JSONNormalizedNodeStreamWriter(final SchemaContext schemaContext, final SchemaPath path,
+ final Writer writer, final int indentSize) {
+ this.schemaContext = Preconditions.checkNotNull(schemaContext);
+ this.writer = Preconditions.checkNotNull(writer);
+
+ Preconditions.checkArgument(indentSize >= 0, "Indent size must be non-negative");
+ if (indentSize != 0) {
+ indent = Strings.repeat(" ", indentSize);
+ } else {
+ indent = null;
+ }
+
+ this.codecs = CodecFactory.create(schemaContext);
+ this.tracker = SchemaTracker.create(schemaContext,path);
+ }
+
/**
* Create a new stream writer, which writes to the specified {@link Writer}.
*
return new JSONNormalizedNodeStreamWriter(schemaContext, writer, 0);
}
+ /**
+ * Create a new stream writer, which writes to the specified {@link Writer}.
+ *
+ * @param schemaContext Schema context
+ * @param writer Output writer
+ * @return A stream writer instance
+ */
+ public static NormalizedNodeStreamWriter create(final SchemaContext schemaContext, SchemaPath path,final Writer writer) {
+ return new JSONNormalizedNodeStreamWriter(schemaContext, path, writer, 0);
+ }
+
/**
* Create a new stream writer, which writes to the specified output stream.
*
public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint)
throws IOException {
tracker.startListItem(identifier);
-
- stack.push(new TypeInfo(NodeType.OBJECT, identifier.getNodeType().getNamespace()));
separateElementFromPreviousElement();
+ stack.push(new TypeInfo(NodeType.OBJECT, identifier.getNodeType().getNamespace()));
+
+
writeStartObject();
indentRight();
}