com.google.gdata.wireformats
Class XmlGenerator

java.lang.Object
  extended by com.google.gdata.wireformats.XmlGenerator
All Implemented Interfaces:
ElementVisitor, WireFormatGenerator

public class XmlGenerator
extends java.lang.Object
implements WireFormatGenerator, ElementVisitor

XML generator that outputs a tree of Element objects using the XML wire format.


Nested Class Summary
static interface XmlGenerator.ElementGenerator
          The ElementGenerator interface is implemented by helper classes that will generate the start element, text content, and end element syntax for an Element to an XmlWriter.
static class XmlGenerator.XmlElementGenerator
          The XmlElementGenerator class provides the default implementation of the interface.
 
Nested classes/interfaces inherited from interface com.google.gdata.model.ElementVisitor
ElementVisitor.StoppedException
 
Field Summary
protected  ElementMetadata<?,?> rootMetadata
          Metadata for the root element
protected  XmlWriter xw
          XML writer used by this generator.
 
Constructor Summary
XmlGenerator(StreamProperties props, java.io.Writer w, java.nio.charset.Charset cs, boolean prettyPrint)
          Creates a new xml generator for generating xml output.
XmlGenerator(StreamProperties props, java.io.Writer w, java.nio.charset.Charset cs, boolean prettyPrint, XmlNamespace defaultNamespace)
          Creates a new xml generator for generating xml output, using the given namespace as the default namespace.
 
Method Summary
 void generate(Element element)
          Generate wire content for tree rooted at root.
 void generate(Element element, ElementMetadata<?,?> metadata)
           
 boolean visit(Element parent, Element e, ElementMetadata<?,?> metadata)
          Called during Element tree traversal to allow the visitor instance to process an element in the tree.
 void visitComplete(Element parent, Element e, ElementMetadata<?,?> metadata)
          The visitComplete method is called when traversal for an Element and all of its nested children has been completed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rootMetadata

protected final ElementMetadata<?,?> rootMetadata
Metadata for the root element


xw

protected final XmlWriter xw
XML writer used by this generator.

Constructor Detail

XmlGenerator

public XmlGenerator(StreamProperties props,
                    java.io.Writer w,
                    java.nio.charset.Charset cs,
                    boolean prettyPrint)
Creates a new xml generator for generating xml output. This constructor will use the namespace of the root element as the default namespace of the output. Callers that would like to change the default namespace should call #XmlGenerator(OutputProperties, Writer, Charset, boolean, XmlNamespace) with the namespace that should be used as the default.


XmlGenerator

public XmlGenerator(StreamProperties props,
                    java.io.Writer w,
                    java.nio.charset.Charset cs,
                    boolean prettyPrint,
                    XmlNamespace defaultNamespace)
Creates a new xml generator for generating xml output, using the given namespace as the default namespace.

Method Detail

generate

public void generate(Element element)
              throws java.io.IOException
Description copied from interface: WireFormatGenerator
Generate wire content for tree rooted at root.

Specified by:
generate in interface WireFormatGenerator
Parameters:
element - root of tree
Throws:
java.io.IOException - if content generation failed

generate

public void generate(Element element,
                     ElementMetadata<?,?> metadata)
              throws java.io.IOException
Throws:
java.io.IOException

visit

public boolean visit(Element parent,
                     Element e,
                     ElementMetadata<?,?> metadata)
              throws ElementVisitor.StoppedException
Description copied from interface: ElementVisitor
Called during Element tree traversal to allow the visitor instance to process an element in the tree.

Specified by:
visit in interface ElementVisitor
Parameters:
parent - the parent of the target element
e - the target element being visited
metadata - the metadata for the target element
Returns:
boolean value indicating whether child elements (if any) should be visited.
Throws:
ElementVisitor.StoppedException - if the data model traversal should be stopped immediately. This may be the result of an unexpected error, or some visitor implementations may extend this exception type to signal specific exit conditions.

visitComplete

public void visitComplete(Element parent,
                          Element e,
                          ElementMetadata<?,?> metadata)
                   throws ElementVisitor.StoppedException
Description copied from interface: ElementVisitor
The visitComplete method is called when traversal for an Element and all of its nested children has been completed.

Specified by:
visitComplete in interface ElementVisitor
Parameters:
parent - the parent of the target element
e - the visited element
metadata - the metadata for the target element
Throws:
ElementVisitor.StoppedException - if the data model traversal should be stopped immediately. This may be the result of an unexpected error, or some visitor implementations may extend this exception type to signal specific exit conditions.