org.milyn.javabean.binding.xml
Class XMLBinding

java.lang.Object
  extended by org.milyn.javabean.binding.AbstractBinding
      extended by org.milyn.javabean.binding.xml.XMLBinding

public class XMLBinding
extends AbstractBinding

XML Binding class.

This class is designed specifically for reading and writing XML data (does not work for other data formats) to and from Java Object models using nothing more than standard <jb:bean> configurations i.e. no need to write a template for serializing the Java Objects to an output character based format, as with Smooks v1.4 and before.

Since:
1.5
Author:
tom.fennelly@gmail.com

Constructor Summary
XMLBinding()
          Public constructor.
XMLBinding(org.milyn.Smooks smooks)
          Public constructor.
 
Method Summary
 XMLBinding add(InputStream smooksConfigStream)
          Add Smooks binding configurations to the binding instance.
 XMLBinding add(String smooksConfigURI)
          Add Smooks binding configurations to the binding instance.
<T> T
fromXML(Source inputSource, Class<T> toType)
          Bind from the XML into the Java Object model.
<T> T
fromXML(String inputSource, Class<T> toType)
          Bind from the XML into the Java Object model.
 XMLBinding intiailize()
          Initialize the binding instance.
 XMLBinding setOmitXMLDeclaration(boolean omitXMLDeclaration)
          Turn on/off outputting of the XML declaration when executing the toXML(Object, java.io.Writer) method.
 XMLBinding setReportPath(String reportPath)
          Set the execution report output path.
 String toXML(Object object)
          Write the supplied Object instance to XML.
<W extends Writer>
W
toXML(Object object, W outputWriter)
          Write the supplied Object instance to XML.
 
Methods inherited from class org.milyn.javabean.binding.AbstractBinding
assertInitialized, assertNotAllConfigsAdded, assertNotInitialized, bind, constructContextualGetter, constructContextualGetter, getSmooks, getUserDefinedResourceList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLBinding

public XMLBinding()
Public constructor.

Must be followed by calls to the add(java.io.InputStream) (or add(String)) method and then the intiailize() method.


XMLBinding

public XMLBinding(org.milyn.Smooks smooks)
Public constructor.

Create an instance using a pre-configured Smooks instance.

Parameters:
smooks - The pre-configured Smooks instance.
Method Detail

add

public XMLBinding add(String smooksConfigURI)
               throws IOException,
                      SAXException
Description copied from class: AbstractBinding
Add Smooks binding configurations to the binding instance.

Overrides:
add in class AbstractBinding
Parameters:
smooksConfigURI - Smooks configuration.
Throws:
IOException - Error reading resource stream.
SAXException - Error parsing the resource stream.

add

public XMLBinding add(InputStream smooksConfigStream)
               throws IOException,
                      SAXException
Description copied from class: AbstractBinding
Add Smooks binding configurations to the binding instance.

Overrides:
add in class AbstractBinding
Parameters:
smooksConfigStream - Smooks configuration.
Throws:
IOException - Error reading resource stream.
SAXException - Error parsing the resource stream.

setReportPath

public XMLBinding setReportPath(String reportPath)
Description copied from class: AbstractBinding
Set the execution report output path.

Overrides:
setReportPath in class AbstractBinding
Parameters:
reportPath - The execution report output path.

intiailize

public XMLBinding intiailize()
Description copied from class: AbstractBinding
Initialize the binding instance.

Overrides:
intiailize in class AbstractBinding

setOmitXMLDeclaration

public XMLBinding setOmitXMLDeclaration(boolean omitXMLDeclaration)
Turn on/off outputting of the XML declaration when executing the toXML(Object, java.io.Writer) method.

Parameters:
omitXMLDeclaration - True if the order is to be omitted, otherwise false.
Returns:
this instance.

fromXML

public <T> T fromXML(String inputSource,
                     Class<T> toType)
Bind from the XML into the Java Object model.

Type Parameters:
T - The Java type to which the XML data is to be bound.
Parameters:
inputSource - The XML input.
toType - The Java type to which the XML data is to be bound.
Returns:
The populated Java instance.

fromXML

public <T> T fromXML(Source inputSource,
                     Class<T> toType)
          throws IOException
Bind from the XML into the Java Object model.

Type Parameters:
T - The Java type to which the XML data is to be bound.
Parameters:
inputSource - The XML input.
toType - The Java type to which the XML data is to be bound.
Returns:
The populated Java instance.
Throws:
IOException

toXML

public <W extends Writer> W toXML(Object object,
                                  W outputWriter)
                       throws BeanSerializationException,
                              IOException
Write the supplied Object instance to XML.

Type Parameters:
W - The Writer type.
Parameters:
object - The Object instance.
outputWriter - The output writer.
Returns:
The supplied Writer instance}.
Throws:
BeanSerializationException - Error serializing the bean.
IOException - Error writing to the supplied Writer instance.

toXML

public String toXML(Object object)
             throws BeanSerializationException
Write the supplied Object instance to XML.

This is a simple wrapper on the toXML(Object, java.io.Writer) method.

Parameters:
object - The Object instance.
Returns:
The XML as a String.
Throws:
BeanSerializationException - Error serializing the bean.


Copyright © 2018. All rights reserved.