com.wutka.jox
Class JOXBeanInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FilterInputStream
              |
              +--com.wutka.jox.JOXBeanInputStream

public class JOXBeanInputStream
extends java.io.FilterInputStream

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

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

The stream 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 stream 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.FilterInputStream
in
 
Constructor Summary
JOXBeanInputStream(java.io.InputStream in)
          Creates a new JOXInputStream around an existing input stream.
 
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.FilterInputStream
available, close, mark, markSupported, read, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JOXBeanInputStream

public JOXBeanInputStream(java.io.InputStream in)
Creates a new JOXInputStream around an existing input stream.
Parameters:
in - The input stream 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 with the populated data
Throws:
java.io.IOException - If there is an error reading the document