/** * Create a new writer with the specified context as its root. * * @param context Associated {@link SchemaContext}. * @return A new {@link NormalizedNodeStreamWriter} */ public static SchemaTracker create(final SchemaContext context) { return create(context, SchemaPath.ROOT); }
JSONNormalizedNodeStreamWriter(final JSONCodecFactory codecFactory, final SchemaPath path, final JsonWriter writer, final JSONStreamWriterRootContext rootContext) { this.writer = requireNonNull(writer); this.codecs = requireNonNull(codecFactory); this.tracker = SchemaTracker.create(codecFactory.getSchemaContext(), path); this.context = requireNonNull(rootContext); }
/** * Create a new writer with the specified context and rooted at the specified node. * * @param writer Output {@link XMLStreamWriter} * @param context Associated {@link SchemaContext}. * @param rootNode Root node * @return A new {@link NormalizedNodeStreamWriter} */ public static @NonNull NormalizedNodeStreamWriter create(final XMLStreamWriter writer, final SchemaContext context, final DataNodeContainer rootNode) { return new SchemaAwareXMLStreamNormalizedNodeStreamWriter(writer, context, SchemaTracker.create(rootNode)); }
/** * Create a new writer with the specified context and rooted in the specified schema path. * * @param writer Output {@link XMLStreamWriter} * @param context Associated {@link SchemaContext}. * @param path path * @return A new {@link NormalizedNodeStreamWriter} */ public static @NonNull NormalizedNodeStreamWriter create(final XMLStreamWriter writer, final SchemaContext context, final SchemaPath path) { return new SchemaAwareXMLStreamNormalizedNodeStreamWriter(writer, context, SchemaTracker.create(context, path)); }
/** * Create a new stream writer, which writes to the specified output stream. * * <p> * The codec factory can be reused between multiple writers. * * <p> * Returned writer is exclusive user of JsonWriter, which means it will start * top-level JSON element and ends it. * * <p> * This instance of writer can be used only to emit one top level element, * otherwise it will produce incorrect JSON. Closing this instance will close * the writer too. * * @param codecFactory JSON codec factory * @param rootNode Root node * @param initialNs Initial namespace * @param jsonWriter JsonWriter * @return A stream writer instance */ public static NormalizedNodeStreamWriter createExclusiveWriter(final JSONCodecFactory codecFactory, final DataNodeContainer rootNode, final URI initialNs, final JsonWriter jsonWriter) { return new Exclusive(codecFactory, SchemaTracker.create(rootNode), jsonWriter, new JSONStreamWriterExclusiveRootContext(initialNs)); }
/** * Create a new stream writer, which writes to the specified output stream. * * <p> * The codec factory can be reused between multiple writers. * * <p> * Returned writer can be used emit multiple top level element, * but does not start / close parent JSON object, which must be done * by user providing {@code jsonWriter} instance in order for * JSON to be valid. Closing this instance <strong>will not</strong> * close the wrapped writer; the caller must take care of that. * * @param codecFactory JSON codec factory * @param rootNode Root node * @param initialNs Initial namespace * @param jsonWriter JsonWriter * @return A stream writer instance */ public static NormalizedNodeStreamWriter createNestedWriter(final JSONCodecFactory codecFactory, final DataNodeContainer rootNode, final URI initialNs, final JsonWriter jsonWriter) { return new Nested(codecFactory, SchemaTracker.create(rootNode), jsonWriter, new JSONStreamWriterSharedRootContext(initialNs)); }
/** * Create a new stream writer, which writes to the specified output stream. * * <p> * The codec factory can be reused between multiple writers. * * <p> * Returned writer is exclusive user of JsonWriter, which means it will start * top-level JSON element and ends it. * * <p> * This instance of writer can be used only to emit one top level element, * otherwise it will produce incorrect JSON. Closing this instance will close * the writer too. * * @param codecFactory JSON codec factory * @param path Schema Path * @param initialNs Initial namespace * @param jsonWriter JsonWriter * @return A stream writer instance */ public static NormalizedNodeStreamWriter createExclusiveWriter(final JSONCodecFactory codecFactory, final SchemaPath path, final URI initialNs, final JsonWriter jsonWriter) { return new Exclusive(codecFactory, SchemaTracker.create(codecFactory.getSchemaContext(), path), jsonWriter, new JSONStreamWriterExclusiveRootContext(initialNs)); }
/** * Create a new stream writer, which writes to the specified output stream. * * <p> * The codec factory can be reused between multiple writers. * * <p> * Returned writer can be used emit multiple top level element, * but does not start / close parent JSON object, which must be done * by user providing {@code jsonWriter} instance in order for * JSON to be valid. Closing this instance <strong>will not</strong> * close the wrapped writer; the caller must take care of that. * * @param codecFactory JSON codec factory * @param path Schema Path * @param initialNs Initial namespace * @param jsonWriter JsonWriter * @return A stream writer instance */ public static NormalizedNodeStreamWriter createNestedWriter(final JSONCodecFactory codecFactory, final SchemaPath path, final URI initialNs, final JsonWriter jsonWriter) { return new Nested(codecFactory, SchemaTracker.create(codecFactory.getSchemaContext(), path), jsonWriter, new JSONStreamWriterSharedRootContext(initialNs)); }