com.wutka.jox
Class JOXBeanReader

java.lang.Object
  |
  +--java.io.Reader
        |
        +--java.io.FilterReader
              |
              +--com.wutka.jox.JOXBeanReader

public class JOXBeanReader
extends java.io.FilterReader

An Reader filter that reads XML into a bean. When you read an XML document, you must supply either a class or an object instance. The reader will attempt to match XML tags to bean attributes in the class/object you supply.

If you supply a class, the reader will automatically create a new object instance to hold the data.

The reader understands the basic Java data types and their object equivalents, plus strings and dates. Anything else must be a bean. It can also read arrays of any of the supported types or of beans if it tries to read a bean with an indexed property.

If there are XML fields that don't match the bean, it will ignore them. If the data types are not compatible, you will get an exception. At some point the reader will be smart enough to skip over incompatible fields. Note: JOXBeanInputStream and JOXBeanReader use the same underlying class to read the XML document, so their behaviour should be identical.


Fields inherited from class java.io.FilterReader
in
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
JOXBeanReader(java.io.Reader in)
          Creates a new JOXReader around an existing reader.
 
Method Summary
 java.lang.Object readObject(java.lang.Class obClass)
          Reads an XML document into a new instance of the given class, matching tag names to bean property names.
 void readObject(java.lang.Object ob)
          Reads an XML document into the object, matching tag names to bean property names.
 
Methods inherited from class java.io.FilterReader
close, mark, markSupported, read, read, ready, reset, skip
 
Methods inherited from class java.io.Reader
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JOXBeanReader

public JOXBeanReader(java.io.Reader in)
Creates a new JOXReader around an existing reader.
Parameters:
in - The reader to be read from
Method Detail

readObject

public void readObject(java.lang.Object ob)
                throws java.io.IOException
Reads an XML document into the object, matching tag names to bean property names.
Parameters:
ob - The object that will receive data from the XML document
Throws:
java.io.IOException - If there is an error reading the document

readObject

public java.lang.Object readObject(java.lang.Class obClass)
                            throws java.io.IOException
Reads an XML document into a new instance of the given class, matching tag names to bean property names.
Parameters:
obClass - The class for the object that will receive data from the XML document
Returns:
The new instance of the class containing the parsed data
Throws:
java.io.IOException - If there is an error reading the document