public abstract class

AbstractBeanWriter

extends Object
java.lang.Object
   ↳ org.apache.commons.betwixt.io.AbstractBeanWriter
Known Direct Subclasses

Class Overview

Abstract superclass for bean writers. This class encapsulates the processing logic. Subclasses provide implementations for the actual expression of the xml.

SAX Inspired Writing API

This class is intended to be used by subclassing: concrete subclasses perform the actual writing by providing suitable implementations for the following methods inspired by SAX:

Note that this class contains many deprecated versions of the writing API. These will be removed soon so care should be taken to use the latest version.

Note that this class is designed to be used in a single threaded environment. When used in multi-threaded environments, use of a common XMLIntrospector and pooled writer instances should be considered.

Summary

Public Constructors
AbstractBeanWriter()
Public Methods
void end()
Marks the start of the bean writing.
final Log getAbstractBeanWriterLog()

Gets the current logging implementation.

BindingConfiguration getBindingConfiguration()
Gets the dynamic configuration setting to be used for bean reading.
IDGenerator getIdGenerator()
Get IDGenerator implementation used to generate ID attribute values .
boolean getWriteEmptyElements()

Gets whether empty elements should be written into the output.

boolean getWriteIDs()
This method is deprecated. 0.5 use getMapIDs()
XMLIntrospector getXMLIntrospector()

Gets the introspector used.

final void setAbstractBeanWriterLog(Log log)

Set the current logging implementation.

void setBindingConfiguration(BindingConfiguration bindingConfiguration)
Sets the dynamic configuration setting to be used for bean reading.
void setIdGenerator(IDGenerator idGenerator)
Set IDGenerator implementation used to generate ID attribute values.
void setWriteEmptyElements(boolean writeEmptyElements)

Sets whether empty elements should be written into the output.

void setWriteIDs(boolean writeIDs)
This method is deprecated. 0.5 use setMapIDs(boolean)
void setXMLIntrospector(XMLIntrospector introspector)

Sets the introspector to be used.

void start()
Marks the start of the bean writing.
void write(Object bean, InputSource source)

Writes the bean using the mapping specified in the InputSource.

void write(Object bean)

Writes the given bean to the current stream using the XML introspector.

void write(String qualifiedName, Object bean)

Writes the given bean to the current stream using the given qualifiedName.

Protected Methods
void bodyText(String text)
This method is deprecated. 0.5 use bodyText(WriteContext, String)
void bodyText(WriteContext context, String text)
Writes body text
void endElement(String uri, String localName, String qName)
This method is deprecated. 0.5 use endElement(WriteContext, String, String, String)
void endElement(WriteContext context, String uri, String localName, String qName)
Writes the end tag for an element
void expressAttribute(String qualifiedName, String value)
This method is deprecated. 0.5 replaced by new SAX inspired API
void expressAttribute(String namespaceUri, String localName, String qualifiedName, String value)
This method is deprecated. 0.5 replaced by new SAX inspired API
void expressBodyText(String text)
This method is deprecated. 0.5 replaced by new SAX inspired API
void expressElementEnd()
This method is deprecated. 0.5 replaced by new SAX inspired API
void expressElementEnd(String uri, String localName, String qualifiedName)
This method is deprecated. 0.5 replaced by new SAX inspired API
void expressElementEnd(String qualifiedName)
This method is deprecated. 0.5 replaced by new SAX inspired API
void expressElementStart(String uri, String localName, String qualifiedName)
This method is deprecated. 0.5 replaced by new SAX inspired API
void expressElementStart(String qualifiedName)
This method is deprecated. 0.5 replaced by new SAX inspired API
void expressTagClose()
This method is deprecated. 0.5 replaced by new SAX inspired API
int getIndentLevel()
This method is deprecated. 0.5 replaced by new SAX inspired API
Object popBean()
Pops the top bean off from the ancestry stack
void pushBean(Object bean)
Pushes the bean onto the ancestry stack.
void startElement(WriteContext context, String uri, String localName, String qName, Attributes attr)
Writes the start tag for an element.
void startElement(String uri, String localName, String qName, Attributes attr)
void write(String qualifiedName, ElementDescriptor elementDescriptor, Context context)
This method is deprecated. 0.5 replaced by new SAX inspired API
void write(String qualifiedName, ElementDescriptor elementDescriptor, Context context, String idAttribute, String idValue)
This method is deprecated. 0.5 replaced by new SAX inspired API
void writeAttribute(AttributeDescriptor attributeDescriptor, Context context)
This method is deprecated. 0.5 replaced by new SAX inspired API
void writeAttributes(ElementDescriptor elementDescriptor, Context context)
This method is deprecated. 0.5 replaced by new SAX inspired API
boolean writeContent(ElementDescriptor elementDescriptor, Context context)
This method is deprecated. 0.5 replaced by new SAX inspired API
void writeIDREFElement(String qualifiedName, String idrefAttributeName, String idrefAttributeValue)
This method is deprecated. 0.5 replaced by new SAX inspired API
void writeIndent()
This method is deprecated. 0.5 replaced by new BeanWriter API
void writePrintln()
This method is deprecated. 0.5 replaced by new SAX inspired API
void writeRestOfElement(String qualifiedName, ElementDescriptor elementDescriptor, Context context)
This method is deprecated. 0.5 replaced by new SAX inspired API
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public AbstractBeanWriter ()

Public Methods

public void end ()

Marks the start of the bean writing. By default doesn't do anything, but can be used to do extra end processing

Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

public final Log getAbstractBeanWriterLog ()

Gets the current logging implementation.

Returns
  • the Log implementation which this class logs to

public BindingConfiguration getBindingConfiguration ()

Gets the dynamic configuration setting to be used for bean reading.

Returns
  • the BindingConfiguration settings, not null

public IDGenerator getIdGenerator ()

Get IDGenerator implementation used to generate ID attribute values .

Returns
  • implementation used for ID attribute generation

public boolean getWriteEmptyElements ()

Gets whether empty elements should be written into the output.

An empty element is one that has no attributes, no child elements and no body text. For example, <element/> is an empty element but <element attr='value'/> is not.

Returns
  • true if empty elements will be written into the output

public boolean getWriteIDs ()

This method is deprecated.
0.5 use getMapIDs()

Should generated ID attribute values be added to the elements?

If IDs are not being written then if a cycle is encountered in the bean graph, then a CyclicReferenceException will be thrown by the write method.

Returns
  • true if ID and IDREF attributes are to be written

public XMLIntrospector getXMLIntrospector ()

Gets the introspector used.

The XMLBeanInfo used to map each bean is created by the XMLIntrospector. One way in which the mapping can be customized is by altering the XMLIntrospector.

Returns
  • the XMLIntrospector used for introspection

public final void setAbstractBeanWriterLog (Log log)

Set the current logging implementation.

Parameters
log Log implementation to use

public void setBindingConfiguration (BindingConfiguration bindingConfiguration)

Sets the dynamic configuration setting to be used for bean reading.

Parameters
bindingConfiguration the BindingConfiguration settings, not null

public void setIdGenerator (IDGenerator idGenerator)

Set IDGenerator implementation used to generate ID attribute values. This property can be used to customize the algorithm used for generation.

Parameters
idGenerator use this implementation for ID attribute generation

public void setWriteEmptyElements (boolean writeEmptyElements)

Sets whether empty elements should be written into the output.

An empty element is one that has no attributes, no child elements and no body text. For example, <element/> is an empty element but <element attr='value'/> is not.

Parameters
writeEmptyElements true if empty elements should be written into the output

public void setWriteIDs (boolean writeIDs)

This method is deprecated.
0.5 use setMapIDs(boolean)

Set whether generated ID attribute values should be added to the elements If this property is set to false, then CyclicReferenceException will be thrown whenever a cyclic occurs in the bean graph.

Parameters
writeIDs true if ID's and IDREF's should be written

public void setXMLIntrospector (XMLIntrospector introspector)

Sets the introspector to be used.

The XMLBeanInfo used to map each bean is created by the XMLIntrospector. One way in which the mapping can be customized is by altering the XMLIntrospector.

Parameters
introspector use this introspector

public void start ()

Marks the start of the bean writing. By default doesn't do anything, but can be used to do extra start processing

Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

public void write (Object bean, InputSource source)

Writes the bean using the mapping specified in the InputSource.

Note: that the custom mapping will not be registered for later use. Please use register(Class, InputSource) to register the custom mapping for the class and then call write(Object).

Parameters
bean Object to be written as xml, not null
source InputSource/code> containing an xml document specifying the mapping to be used (in the usual way), not null
Throws
IOException
SAXException
IntrospectionException
IOException
SAXException

public void write (Object bean)

Writes the given bean to the current stream using the XML introspector.

This writes an xml fragment representing the bean to the current stream.

This method will throw a CyclicReferenceException when a cycle is encountered in the graph only if the getMapIDs() setting of the BindingConfiguration is false.

Parameters
bean write out representation of this bean
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing
IntrospectionException if a java beans introspection problem occurs

public void write (String qualifiedName, Object bean)

Writes the given bean to the current stream using the given qualifiedName.

This method will throw a CyclicReferenceException when a cycle is encountered in the graph only if the getMapIDs() setting of the BindingConfiguration is false.

Parameters
qualifiedName the string naming root element
bean the Object to write out as xml
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing
IntrospectionException if a java beans introspection problem occurs

Protected Methods

protected void bodyText (String text)

This method is deprecated.
0.5 use bodyText(WriteContext, String)

Writes body text

Parameters
text the body text to be written
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void bodyText (WriteContext context, String text)

Writes body text

Parameters
text the body text to be written
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void endElement (String uri, String localName, String qName)

This method is deprecated.
0.5 use endElement(WriteContext, String, String, String)

Writes the end tag for an element

Parameters
uri the element's namespace uri
localName the element's local name
qName the element's qualified name
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void endElement (WriteContext context, String uri, String localName, String qName)

Writes the end tag for an element

Parameters
uri the element's namespace uri
localName the element's local name
qName the element's qualified name
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void expressAttribute (String qualifiedName, String value)

This method is deprecated.
0.5 replaced by new SAX inspired API

Express an attribute

Parameters
qualifiedName the qualified name of the attribute
value the attribute value
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void expressAttribute (String namespaceUri, String localName, String qualifiedName, String value)

This method is deprecated.
0.5 replaced by new SAX inspired API

Express an attribute

Parameters
namespaceUri the namespace uri
localName the local name
qualifiedName the qualified name of the attribute
value the attribute value
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void expressBodyText (String text)

This method is deprecated.
0.5 replaced by new SAX inspired API

Express body text

Parameters
text the string to write out as the body of the current element
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void expressElementEnd ()

This method is deprecated.
0.5 replaced by new SAX inspired API

Express an empty element end.

Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void expressElementEnd (String uri, String localName, String qualifiedName)

This method is deprecated.
0.5 replaced by new SAX inspired API

Express an element end tag (with given name)

Parameters
uri the namespace uri of the element close tag
localName the local name of the element close tag
qualifiedName the qualified name for the element to be closed
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void expressElementEnd (String qualifiedName)

This method is deprecated.
0.5 replaced by new SAX inspired API

Express an element end tag (with given name)

Parameters
qualifiedName the qualified name for the element to be closed
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void expressElementStart (String uri, String localName, String qualifiedName)

This method is deprecated.
0.5 replaced by new SAX inspired API

Express an element tag start using given qualified name.

Parameters
uri the namespace uri
localName the local name for this element
qualifiedName the qualified name of the element to be expressed
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void expressElementStart (String qualifiedName)

This method is deprecated.
0.5 replaced by new SAX inspired API

Express an element tag start using given qualified name.

Parameters
qualifiedName the qualified name of the element to be expressed
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void expressTagClose ()

This method is deprecated.
0.5 replaced by new SAX inspired API

Express a closing tag.

Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected int getIndentLevel ()

This method is deprecated.
0.5 replaced by new SAX inspired API

Get the indentation for the current element. Used for pretty priting.

Returns
  • the amount that the current element is indented

protected Object popBean ()

Pops the top bean off from the ancestry stack

Returns
  • the last object pushed onto the ancester stack

protected void pushBean (Object bean)

Pushes the bean onto the ancestry stack. If IDs are not being written, then check for cyclic references.

Parameters
bean push this bean onto the ancester stack

protected void startElement (WriteContext context, String uri, String localName, String qName, Attributes attr)

Writes the start tag for an element.

Parameters
uri the element's namespace uri
localName the element's local name
qName the element's qualified name
attr the element's attributes
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void startElement (String uri, String localName, String qName, Attributes attr)

This method is deprecated.
0.5 use startElement(WriteContext, String, String, String, Attributes)

Writes the start tag for an element.

Parameters
uri the element's namespace uri
localName the element's local name
qName the element's qualified name
attr the element's attributes
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void write (String qualifiedName, ElementDescriptor elementDescriptor, Context context)

This method is deprecated.
0.5 replaced by new SAX inspired API

Writes the given element

Parameters
qualifiedName qualified name to use for the element
elementDescriptor the ElementDescriptor describing the element
context the Context to use to evaluate the bean expressions
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing
IntrospectionException if a java beans introspection problem occurs

protected void write (String qualifiedName, ElementDescriptor elementDescriptor, Context context, String idAttribute, String idValue)

This method is deprecated.
0.5 replaced by new SAX inspired API

Writes the given element adding an ID attribute

Parameters
qualifiedName qualified name to use for the element
elementDescriptor the ElementDescriptor describing the element
context the Context to use to evaluate the bean expressions
idAttribute the qualified name of the ID attribute
idValue the value for the ID attribute
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing
IntrospectionException if a java beans introspection problem occurs

protected void writeAttribute (AttributeDescriptor attributeDescriptor, Context context)

This method is deprecated.
0.5 replaced by new SAX inspired API

Writes an attribute declaration

Parameters
attributeDescriptor the AttributeDescriptor to be written as xml
context the Context to use to evaluation bean expressions
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected void writeAttributes (ElementDescriptor elementDescriptor, Context context)

This method is deprecated.
0.5 replaced by new SAX inspired API

Writes the attribute declarations

Parameters
elementDescriptor the ElementDescriptor to be written out as xml
context the Context to use to evaluation bean expressions
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing

protected boolean writeContent (ElementDescriptor elementDescriptor, Context context)

This method is deprecated.
0.5 replaced by new SAX inspired API

Writes the element content.

Parameters
elementDescriptor the ElementDescriptor to write as xml
context the Context to use to evaluate the bean expressions
Returns
  • true if some content was written
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing
IntrospectionException if a java beans introspection problem occurs

protected void writeIDREFElement (String qualifiedName, String idrefAttributeName, String idrefAttributeValue)

This method is deprecated.
0.5 replaced by new SAX inspired API

Writes an element with a IDREF attribute

Parameters
qualifiedName of the element with IDREF attribute
idrefAttributeName the qualified name of the IDREF attribute
idrefAttributeValue the value for the IDREF attribute
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing
IntrospectionException if a java beans introspection problem occurs

protected void writeIndent ()

This method is deprecated.
0.5 replaced by new BeanWriter API

Writes an indentation. This implementation does nothing but can be overridden by subclasses.

Throws
IOException if the indent cannot be written

protected void writePrintln ()

This method is deprecated.
0.5 replaced by new SAX inspired API

Writes a empty line. This implementation does nothing but can be overridden by subclasses.

Throws
IOException if the line cannot be written

protected void writeRestOfElement (String qualifiedName, ElementDescriptor elementDescriptor, Context context)

This method is deprecated.
0.5 replaced by new SAX inspired API

Write attributes, child elements and element end

Parameters
qualifiedName qualified name to use for the element
elementDescriptor the ElementDescriptor describing the element
context the Context to use to evaluate the bean expressions
Throws
IOException if an IO problem occurs during writing
SAXException if an SAX problem occurs during writing
IntrospectionException if a java beans introspection problem occurs