> A serializer can implement DOM printing faster than walking the DOM and
> producing SAX events.

OK, good point.

> I'm not following you on that one. Can you just write down how you think
> the interface should look?

Sorry.  Something along the lines of...

public interface DOMSerializer
{
  /**
   * Serialized the DOM element. Throws an exception only
   * if an I/O exception occured while serializing.
   *
   * @param node The node to serialize
   * @throws IOException An I/O exception occured while
   *   serializing
   */
  public void serialize( Node node )
    throws IOException;

  /**
   * Serializes the DOM document. Throws an exception only
   * if an I/O exception occured while serializing.
   *
   * @param doc The document to serialize
   * @throws IOException An I/O exception occured while
   *   serializing
   */
  public void serialize( Document doc )
    throws IOException;
}


public interface Serializer
{
    /**
     * Re-initialize the serializer with the given
     * OutputFormat.  This does not use the method
     * property of the OutputFormat, since the method
     * should have already been determined.
     */
    void reinit( OutputFormat format );

    /**
     * Reset out output stream.
     */
    void setOutputByteStream(OutputStream output)
      throws UnsupportedEncodingException;

    /**
     * Reset the ouput character stream.
     */
    void setOutputCharStream(Writer output);

    /**
     * Return a DocumentHandler interface, if this
     * object support this.  This method may return null.
     */
    DocumentHandler getDocumentHandler();

    /**
     * Return a DOMSerializer interface, if this
     * object supports this.  This method may return null.
     */
    DOMSerializer getDOMSerializer();
}

public abstract class SerializerFactory
{
  /**
   * Register a serializer factory, keyed by the given
   * method string.
   */
  public static void registerSerializerFactory( String method,
                                  SerializerFactory factory )
  {
    ...
  }

  /**
   * Register a serializer factory, keyed by the given
   * method string.
   */
  public static SerializerFactory getSerializerFactory( String method )
  {
    ...
  }

  /**
   * Create a new serializer, based on the OutputFormat.  If this
   * method is used to create the Serializer, the setOutputByteStream
   * or setOutputCharStream methods on the Serializer will need
   * to be called.
   */
  public abstract Serializer makeSerializer(OutputFormat format);

  /**
   * Create a new serializer, based on the OutputFormat, and
   * using the writer as the output character stream.  If this
   * method is used, the encoding property will be ignored.
   */
  public abstract Serializer makeSerializer(Writer writer,
                                            OutputFormat format);

  /**
   * Create a new serializer, based on the
   */
  public abstract Serializer makeSerializer(OutputStream output,
                                            OutputFormat format)
    throws UnsupportedEncodingException;

}

-scott





Reply via email to