com.threerings.export
Class XMLImporter

java.lang.Object
  extended by com.threerings.export.Importer
      extended by com.threerings.export.XMLImporter
All Implemented Interfaces:
Closeable

public class XMLImporter
extends Importer

Imports from the XML format generated by XMLExporter.


Field Summary
protected  Document _document
          The parsed XML document.
protected  Element _element
          The element associated with the current object.
protected  InputStream _in
          The source stream.
protected  HashMap<String,Object> _objects
          Mappings from ids to referenced objects.
 
Fields inherited from class com.threerings.export.Importer
_marshaller, _object
 
Constructor Summary
XMLImporter(InputStream in)
          Creates an importer to read from the specified stream.
 
Method Summary
 void close()
          Closes the underlying stream.
protected  int countEntries()
          Returns the number of entries under the current element.
protected static Element findElement(Node first, String name)
          Finds the first element in the sibling chain with the given name.
protected  String getValue(String name)
          For simple text fields, retrieves the value from a child element.
protected  void putObject(String id, Object value)
          Stores an object in the map, logging a warning if we overwrite an existing entry.
protected  Object read(Element element, Class<?> clazz)
          Reads an object of the supplied type from the given element.
 boolean read(String name, boolean defvalue)
          Reads a boolean value associated with the current object.
 byte read(String name, byte defvalue)
          Reads a byte value associated with the current object.
 char read(String name, char defvalue)
          Reads a character value associated with the current object.
 double read(String name, double defvalue)
          Reads a double value associated with the current object.
 float read(String name, float defvalue)
          Reads a float value associated with the current object.
 int read(String name, int defvalue)
          Reads an integer value associated with the current object.
 long read(String name, long defvalue)
          Reads a long value associated with the current object.
 short read(String name, short defvalue)
          Reads a short value associated with the current object.
<T> T
read(String name, T defvalue, Class<T> clazz)
          Reads an object value associated with the current object.
protected  Collection<Object> readEntries(Collection<Object> collection)
          Populates the supplied collection with the entries under the current element.
protected  Map<Object,Object> readEntries(Map<Object,Object> map)
          Populates the supplied map with the entries under the current element.
protected  void readEntries(Object[] array, Class<?> cclazz)
          Populates the supplied array with the entries under the current element.
 Object readObject()
          Imports an object from the underlying stream.
protected  Object readValue(Element element, Class<?> clazz)
          Reads an object value of the specified class from the given element.
 
Methods inherited from class com.threerings.export.Importer
defaultReadFields, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, read, readFields
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_in

protected InputStream _in
The source stream.


_document

protected Document _document
The parsed XML document.


_element

protected Element _element
The element associated with the current object.


_objects

protected HashMap<String,Object> _objects
Mappings from ids to referenced objects.

Constructor Detail

XMLImporter

public XMLImporter(InputStream in)
Creates an importer to read from the specified stream.

Method Detail

readObject

public Object readObject()
                  throws IOException
Description copied from class: Importer
Imports an object from the underlying stream.

Specified by:
readObject in class Importer
Throws:
IOException

read

public boolean read(String name,
                    boolean defvalue)
             throws IOException
Description copied from class: Importer
Reads a boolean value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public byte read(String name,
                 byte defvalue)
          throws IOException
Description copied from class: Importer
Reads a byte value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public char read(String name,
                 char defvalue)
          throws IOException
Description copied from class: Importer
Reads a character value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public double read(String name,
                   double defvalue)
            throws IOException
Description copied from class: Importer
Reads a double value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public float read(String name,
                  float defvalue)
           throws IOException
Description copied from class: Importer
Reads a float value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public int read(String name,
                int defvalue)
         throws IOException
Description copied from class: Importer
Reads an integer value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public long read(String name,
                 long defvalue)
          throws IOException
Description copied from class: Importer
Reads a long value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public short read(String name,
                  short defvalue)
           throws IOException
Description copied from class: Importer
Reads a short value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

read

public <T> T read(String name,
                  T defvalue,
                  Class<T> clazz)
       throws IOException
Description copied from class: Importer
Reads an object value associated with the current object.

Specified by:
read in class Importer
Throws:
IOException

close

public void close()
           throws IOException
Description copied from class: Importer
Closes the underlying stream.

Specified by:
close in interface Closeable
Specified by:
close in class Importer
Throws:
IOException

read

protected Object read(Element element,
                      Class<?> clazz)
               throws IOException
Reads an object of the supplied type from the given element.

Throws:
IOException

readValue

protected Object readValue(Element element,
                           Class<?> clazz)
                    throws IOException
Reads an object value of the specified class from the given element.

Throws:
IOException

putObject

protected void putObject(String id,
                         Object value)
Stores an object in the map, logging a warning if we overwrite an existing entry.


countEntries

protected int countEntries()
Returns the number of entries under the current element.


readEntries

protected void readEntries(Object[] array,
                           Class<?> cclazz)
                    throws IOException
Populates the supplied array with the entries under the current element.

Throws:
IOException

readEntries

protected Collection<Object> readEntries(Collection<Object> collection)
                                  throws IOException
Populates the supplied collection with the entries under the current element.

Returns:
a reference to the collection passed, for chaining.
Throws:
IOException

readEntries

protected Map<Object,Object> readEntries(Map<Object,Object> map)
                                  throws IOException
Populates the supplied map with the entries under the current element.

Returns:
a reference to the map passed, for chaining.
Throws:
IOException

getValue

protected String getValue(String name)
For simple text fields, retrieves the value from a child element.


findElement

protected static Element findElement(Node first,
                                     String name)
Finds the first element in the sibling chain with the given name.