org.apache.commons.betwixt.io
Class AbstractBeanWriter

java.lang.Object
  extended byorg.apache.commons.betwixt.io.AbstractBeanWriter
Direct Known Subclasses:
BeanWriter, SAXBeanWriter

public abstract class AbstractBeanWriter
extends java.lang.Object

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.

Author:
Robert Burrell Donkin

Nested Class Summary
private  class AbstractBeanWriter.ElementAttributes
          Attributes backed by attribute descriptors.
private  class AbstractBeanWriter.IDElementAttributes
          Attributes with generate ID/IDREF attributes //TODO: refactor the ID/REF generation so that it's fixed at introspection and the generators are placed into the Context.
private static class AbstractBeanWriter.WriteContextImpl
          Basic mutable implementation of WriteContext.
 
Field Summary
private  org.apache.commons.collections.ArrayStack beanStack
          Stack containing beans - used to detect cycles
private  BindingConfiguration bindingConfiguration
          Dynamic binding configuration settings
private  IDGenerator idGenerator
          Used to generate ID attribute values
private  XMLIntrospector introspector
          Introspector used
private  org.apache.commons.logging.Log log
          Log used for logging (Doh!)
private  java.util.Collection namespacesDeclared
          Collection of namespaces which have already been declared
private  AbstractBeanWriter.WriteContextImpl writeContext
          WriteContext implementation reused curing writing
private  boolean writeEmptyElements
          Should empty elements be written out?
 
Constructor Summary
AbstractBeanWriter()
           
 
Method Summary
private  org.xml.sax.Attributes addNamespaceDeclarations(org.xml.sax.Attributes attributes, java.lang.String elementNamespaceUri)
          Adds namespace declarations (if any are needed) to the given attributes.
protected  void bodyText(java.lang.String text)
          Deprecated. 0.5 use bodyText(WriteContext, String)
protected  void bodyText(WriteContext context, java.lang.String text)
          Writes body text
private  java.lang.String convertToString(java.lang.Object value, Descriptor descriptor, Context context)
          Converts an object to a string.
 void end()
          Marks the start of the bean writing.
protected  void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Deprecated. 0.5 use endElement(WriteContext, String, String, String)
protected  void endElement(WriteContext context, java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Writes the end tag for an element
protected  void expressAttribute(java.lang.String qualifiedName, java.lang.String value)
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void expressAttribute(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qualifiedName, java.lang.String value)
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void expressBodyText(java.lang.String text)
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void expressElementEnd()
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void expressElementEnd(java.lang.String qualifiedName)
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void expressElementEnd(java.lang.String uri, java.lang.String localName, java.lang.String qualifiedName)
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void expressElementStart(java.lang.String qualifiedName)
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void expressElementStart(java.lang.String uri, java.lang.String localName, java.lang.String qualifiedName)
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void expressTagClose()
          Deprecated. 0.5 replaced by new SAX inspired API
private  XMLBeanInfo findXMLBeanInfo(java.lang.Object bean, ElementDescriptor parentDescriptor)
          Finds the appropriate bean info for the given (hollow) element.
 org.apache.commons.logging.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 .
protected  int getIndentLevel()
          Deprecated. 0.5 replaced by new SAX inspired API
 boolean getWriteEmptyElements()
          Gets whether empty elements should be written into the output.
 boolean getWriteIDs()
          Deprecated. 0.5 use BindingConfiguration.getMapIDs()
 XMLIntrospector getXMLIntrospector()
          Gets the introspector used.
private  boolean ignoreElement(ElementDescriptor descriptor, java.lang.String namespaceUri, java.lang.String localName, java.lang.String qualifiedName, Context context)
          Should this element (and children) be written out?
private  boolean isEmptyElement(ElementDescriptor descriptor, Context context)
          Will evaluating this element against this context result in an empty element?
private  Context makeContext(java.lang.Object bean)
          Factory method for new contexts.
protected  java.lang.Object popBean()
          Pops the top bean off from the ancestry stack
protected  void pushBean(java.lang.Object bean)
          Pushes the bean onto the ancestry stack.
 void setAbstractBeanWriterLog(org.apache.commons.logging.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)
          Deprecated. 0.5 use BindingConfiguration.setMapIDs(boolean)
 void setXMLIntrospector(XMLIntrospector introspector)
          Sets the introspector to be used.
 void start()
          Marks the start of the bean writing.
protected  void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attr)
          Deprecated. 0.5 use startElement(WriteContext, String, String, String, Attributes)
protected  void startElement(WriteContext context, java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attr)
          Writes the start tag for an element.
 void write(java.lang.Object bean)
           Writes the given bean to the current stream using the XML introspector.
 void write(java.lang.Object bean, org.xml.sax.InputSource source)
          Writes the bean using the mapping specified in the InputSource.
protected  void write(java.lang.String qualifiedName, ElementDescriptor elementDescriptor, Context context)
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void write(java.lang.String qualifiedName, ElementDescriptor elementDescriptor, Context context, java.lang.String idAttribute, java.lang.String idValue)
          Deprecated. 0.5 replaced by new SAX inspired API
 void write(java.lang.String qualifiedName, java.lang.Object bean)
          Writes the given bean to the current stream using the given qualifiedName.
protected  void writeAttribute(AttributeDescriptor attributeDescriptor, Context context)
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void writeAttributes(ElementDescriptor elementDescriptor, Context context)
          Deprecated. 0.5 replaced by new SAX inspired API
private  void writeBean(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qualifiedName, java.lang.Object bean, Context context)
          Writes the given bean to the current stream using the given qualifiedName.
private  void writeBean(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qualifiedName, java.lang.Object bean, Context context, XMLBeanInfo beanInfo)
          Writes the given bean to the current stream using the given mapping.
private  void writeBean(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qualifiedName, java.lang.Object bean, ElementDescriptor parentDescriptor, Context context)
           
protected  boolean writeContent(ElementDescriptor elementDescriptor, Context context)
          Deprecated. 0.5 replaced by new SAX inspired API
private  void writeElement(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qualifiedName, ElementDescriptor elementDescriptor, Context context)
          Writes the given element
private  void writeElement(java.lang.String namespaceUri, java.lang.String localName, java.lang.String qualifiedName, ElementDescriptor elementDescriptor, Context context, java.lang.String idAttribute, java.lang.String idValue)
          Writes the given element adding an ID attribute
private  void writeElementContent(ElementDescriptor elementDescriptor, Context context)
          Writes the element content.
private  void writeIDREFElement(ElementDescriptor elementDescriptor, java.lang.String uri, java.lang.String localName, java.lang.String qualifiedName, java.lang.String idrefAttributeName, java.lang.String idrefAttributeValue)
          Writes an element with a IDREF attribute
protected  void writeIDREFElement(java.lang.String qualifiedName, java.lang.String idrefAttributeName, java.lang.String idrefAttributeValue)
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void writeIndent()
          Deprecated. 0.5 replaced by new BeanWriter API
protected  void writePrintln()
          Deprecated. 0.5 replaced by new SAX inspired API
protected  void writeRestOfElement(java.lang.String qualifiedName, ElementDescriptor elementDescriptor, Context context)
          Deprecated. 0.5 replaced by new SAX inspired API
private  void writeRestOfElement(java.lang.String uri, java.lang.String localName, java.lang.String qualifiedName, ElementDescriptor elementDescriptor, Context context)
          Write attributes, child elements and element end
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

introspector

private XMLIntrospector introspector
Introspector used


log

private org.apache.commons.logging.Log log
Log used for logging (Doh!)


beanStack

private org.apache.commons.collections.ArrayStack beanStack
Stack containing beans - used to detect cycles


idGenerator

private IDGenerator idGenerator
Used to generate ID attribute values


writeEmptyElements

private boolean writeEmptyElements
Should empty elements be written out?


bindingConfiguration

private BindingConfiguration bindingConfiguration
Dynamic binding configuration settings


writeContext

private AbstractBeanWriter.WriteContextImpl writeContext
WriteContext implementation reused curing writing


namespacesDeclared

private java.util.Collection namespacesDeclared
Collection of namespaces which have already been declared

Constructor Detail

AbstractBeanWriter

public AbstractBeanWriter()
Method Detail

start

public void start()
           throws java.io.IOException,
                  org.xml.sax.SAXException
Marks the start of the bean writing. By default doesn't do anything, but can be used to do extra start processing

Throws:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

end

public void end()
         throws java.io.IOException,
                org.xml.sax.SAXException
Marks the start of the bean writing. By default doesn't do anything, but can be used to do extra end processing

Throws:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

write

public void write(java.lang.Object bean)
           throws java.io.IOException,
                  org.xml.sax.SAXException,
                  java.beans.IntrospectionException

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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

write

public void write(java.lang.String qualifiedName,
                  java.lang.Object bean)
           throws java.io.IOException,
                  org.xml.sax.SAXException,
                  java.beans.IntrospectionException

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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

write

public void write(java.lang.Object bean,
                  org.xml.sax.InputSource source)
           throws java.io.IOException,
                  org.xml.sax.SAXException,
                  java.beans.IntrospectionException

Writes the bean using the mapping specified in the InputSource.

Note: that the custom mapping will not be registered for later use. Please use XMLIntrospector.register(org.xml.sax.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:
java.io.IOException
org.xml.sax.SAXException
java.beans.IntrospectionException
Since:
0.7
See Also:
since the standard notes also apply

writeBean

private void writeBean(java.lang.String namespaceUri,
                       java.lang.String localName,
                       java.lang.String qualifiedName,
                       java.lang.Object bean,
                       Context context)
                throws java.io.IOException,
                       org.xml.sax.SAXException,
                       java.beans.IntrospectionException

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:
namespaceUri - the namespace uri
localName - the local name
qualifiedName - the string naming root element
bean - the Object to write out as xml
context - not null
Throws:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

writeBean

private void writeBean(java.lang.String namespaceUri,
                       java.lang.String localName,
                       java.lang.String qualifiedName,
                       java.lang.Object bean,
                       ElementDescriptor parentDescriptor,
                       Context context)
                throws java.io.IOException,
                       org.xml.sax.SAXException,
                       java.beans.IntrospectionException
Throws:
java.io.IOException
org.xml.sax.SAXException
java.beans.IntrospectionException

findXMLBeanInfo

private XMLBeanInfo findXMLBeanInfo(java.lang.Object bean,
                                    ElementDescriptor parentDescriptor)
                             throws java.beans.IntrospectionException
Finds the appropriate bean info for the given (hollow) element.

Parameters:
bean -
parentDescriptor - ElementDescriptor, not null
Returns:
XMLBeanInfo, not null
Throws:
java.beans.IntrospectionException

writeBean

private void writeBean(java.lang.String namespaceUri,
                       java.lang.String localName,
                       java.lang.String qualifiedName,
                       java.lang.Object bean,
                       Context context,
                       XMLBeanInfo beanInfo)
                throws java.io.IOException,
                       org.xml.sax.SAXException,
                       java.beans.IntrospectionException

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

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:
namespaceUri - the namespace uri, or null to use the automatic binding
localName - the local name or null to use the automatic binding
qualifiedName - the String naming the root element or null to use the automatic binding
bean - Object to be written, not null
context - Context, not null
beanInfo - XMLBeanInfo, not null
Throws:
java.io.IOException
org.xml.sax.SAXException
java.beans.IntrospectionException

getIdGenerator

public IDGenerator getIdGenerator()
Get IDGenerator implementation used to generate ID attribute values .

Returns:
implementation used for ID attribute generation

setIdGenerator

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

getBindingConfiguration

public BindingConfiguration getBindingConfiguration()
Gets the dynamic configuration setting to be used for bean reading.

Returns:
the BindingConfiguration settings, not null
Since:
0.5

setBindingConfiguration

public void setBindingConfiguration(BindingConfiguration bindingConfiguration)
Sets the dynamic configuration setting to be used for bean reading.

Parameters:
bindingConfiguration - the BindingConfiguration settings, not null
Since:
0.5

getWriteIDs

public boolean getWriteIDs()
Deprecated. 0.5 use BindingConfiguration.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

setWriteIDs

public void setWriteIDs(boolean writeIDs)
Deprecated. 0.5 use BindingConfiguration.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

getWriteEmptyElements

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
Since:
0.5

setWriteEmptyElements

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
Since:
0.5

getXMLIntrospector

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

setXMLIntrospector

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

getAbstractBeanWriterLog

public final org.apache.commons.logging.Log getAbstractBeanWriterLog()

Gets the current logging implementation.

Returns:
the Log implementation which this class logs to

setAbstractBeanWriterLog

public final void setAbstractBeanWriterLog(org.apache.commons.logging.Log log)

Set the current logging implementation.

Parameters:
log - Log implementation to use

startElement

protected void startElement(WriteContext context,
                            java.lang.String uri,
                            java.lang.String localName,
                            java.lang.String qName,
                            org.xml.sax.Attributes attr)
                     throws java.io.IOException,
                            org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
Since:
0.5

endElement

protected void endElement(WriteContext context,
                          java.lang.String uri,
                          java.lang.String localName,
                          java.lang.String qName)
                   throws java.io.IOException,
                          org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
Since:
0.5

bodyText

protected void bodyText(WriteContext context,
                        java.lang.String text)
                 throws java.io.IOException,
                        org.xml.sax.SAXException
Writes body text

Parameters:
text - the body text to be written
Throws:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
Since:
0.5

startElement

protected void startElement(java.lang.String uri,
                            java.lang.String localName,
                            java.lang.String qName,
                            org.xml.sax.Attributes attr)
                     throws java.io.IOException,
                            org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

endElement

protected void endElement(java.lang.String uri,
                          java.lang.String localName,
                          java.lang.String qName)
                   throws java.io.IOException,
                          org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

bodyText

protected void bodyText(java.lang.String text)
                 throws java.io.IOException,
                        org.xml.sax.SAXException
Deprecated. 0.5 use bodyText(WriteContext, String)

Writes body text

Parameters:
text - the body text to be written
Throws:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

writeElement

private void writeElement(java.lang.String namespaceUri,
                          java.lang.String localName,
                          java.lang.String qualifiedName,
                          ElementDescriptor elementDescriptor,
                          Context context)
                   throws java.io.IOException,
                          org.xml.sax.SAXException,
                          java.beans.IntrospectionException
Writes the given element

Parameters:
namespaceUri - the namespace uri
localName - the local name
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

addNamespaceDeclarations

private org.xml.sax.Attributes addNamespaceDeclarations(org.xml.sax.Attributes attributes,
                                                        java.lang.String elementNamespaceUri)
Adds namespace declarations (if any are needed) to the given attributes.

Parameters:
attributes - Attributes, not null
elementNamespaceUri - the URI for the enclosing element, possibly null
Returns:
Attributes, not null

writeElement

private void writeElement(java.lang.String namespaceUri,
                          java.lang.String localName,
                          java.lang.String qualifiedName,
                          ElementDescriptor elementDescriptor,
                          Context context,
                          java.lang.String idAttribute,
                          java.lang.String idValue)
                   throws java.io.IOException,
                          org.xml.sax.SAXException,
                          java.beans.IntrospectionException
Writes the given element adding an ID attribute

Parameters:
namespaceUri - the namespace uri
localName - the local name
qualifiedName - the qualified name
elementDescriptor - the ElementDescriptor describing this element
context - the context being evaliated against
idAttribute - the qualified name of the ID attribute
idValue - the value for the ID attribute
Throws:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

writeRestOfElement

private void writeRestOfElement(java.lang.String uri,
                                java.lang.String localName,
                                java.lang.String qualifiedName,
                                ElementDescriptor elementDescriptor,
                                Context context)
                         throws java.io.IOException,
                                org.xml.sax.SAXException,
                                java.beans.IntrospectionException
Write attributes, child elements and element end

Parameters:
uri - the element namespace uri
localName - the local name of the element
qualifiedName - the qualified name of the element
elementDescriptor - the descriptor for this element
context - evaluate against this context
Throws:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

writeIDREFElement

private void writeIDREFElement(ElementDescriptor elementDescriptor,
                               java.lang.String uri,
                               java.lang.String localName,
                               java.lang.String qualifiedName,
                               java.lang.String idrefAttributeName,
                               java.lang.String idrefAttributeValue)
                        throws java.io.IOException,
                               org.xml.sax.SAXException,
                               java.beans.IntrospectionException
Writes an element with a IDREF attribute

Parameters:
uri - the namespace uri
localName - the local name
qualifiedName - of the element with IDREF attribute
idrefAttributeName - the qualified name of the IDREF attribute
idrefAttributeValue - the value for the IDREF attribute
Throws:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

writeElementContent

private void writeElementContent(ElementDescriptor elementDescriptor,
                                 Context context)
                          throws java.io.IOException,
                                 org.xml.sax.SAXException,
                                 java.beans.IntrospectionException
Writes the element content.

Parameters:
elementDescriptor - the ElementDescriptor to write as xml
context - the Context to use to evaluate the bean expressions
Throws:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

pushBean

protected void pushBean(java.lang.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

popBean

protected java.lang.Object popBean()
Pops the top bean off from the ancestry stack

Returns:
the last object pushed onto the ancester stack

ignoreElement

private boolean ignoreElement(ElementDescriptor descriptor,
                              java.lang.String namespaceUri,
                              java.lang.String localName,
                              java.lang.String qualifiedName,
                              Context context)
                       throws java.beans.IntrospectionException
Should this element (and children) be written out?

Parameters:
descriptor - the ElementDescriptor to evaluate
context - the Context against which the element will be evaluated
Returns:
true if this element should be written out
Throws:
java.beans.IntrospectionException

isEmptyElement

private boolean isEmptyElement(ElementDescriptor descriptor,
                               Context context)
                        throws java.beans.IntrospectionException

Will evaluating this element against this context result in an empty element?

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:
descriptor - the ElementDescriptor to evaluate
context - the Context against which the element will be evaluated
Returns:
true if this element is empty on evaluation
Throws:
java.beans.IntrospectionException

getIndentLevel

protected int getIndentLevel()
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

expressElementStart

protected void expressElementStart(java.lang.String qualifiedName)
                            throws java.io.IOException,
                                   org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

expressElementStart

protected void expressElementStart(java.lang.String uri,
                                   java.lang.String localName,
                                   java.lang.String qualifiedName)
                            throws java.io.IOException,
                                   org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

expressTagClose

protected void expressTagClose()
                        throws java.io.IOException,
                               org.xml.sax.SAXException
Deprecated. 0.5 replaced by new SAX inspired API

Express a closing tag.

Throws:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

expressElementEnd

protected void expressElementEnd(java.lang.String qualifiedName)
                          throws java.io.IOException,
                                 org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

expressElementEnd

protected void expressElementEnd(java.lang.String uri,
                                 java.lang.String localName,
                                 java.lang.String qualifiedName)
                          throws java.io.IOException,
                                 org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

expressElementEnd

protected void expressElementEnd()
                          throws java.io.IOException,
                                 org.xml.sax.SAXException
Deprecated. 0.5 replaced by new SAX inspired API

Express an empty element end.

Throws:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

expressBodyText

protected void expressBodyText(java.lang.String text)
                        throws java.io.IOException,
                               org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

expressAttribute

protected void expressAttribute(java.lang.String qualifiedName,
                                java.lang.String value)
                         throws java.io.IOException,
                                org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

expressAttribute

protected void expressAttribute(java.lang.String namespaceUri,
                                java.lang.String localName,
                                java.lang.String qualifiedName,
                                java.lang.String value)
                         throws java.io.IOException,
                                org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

write

protected void write(java.lang.String qualifiedName,
                     ElementDescriptor elementDescriptor,
                     Context context)
              throws java.io.IOException,
                     org.xml.sax.SAXException,
                     java.beans.IntrospectionException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

write

protected void write(java.lang.String qualifiedName,
                     ElementDescriptor elementDescriptor,
                     Context context,
                     java.lang.String idAttribute,
                     java.lang.String idValue)
              throws java.io.IOException,
                     org.xml.sax.SAXException,
                     java.beans.IntrospectionException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

writeRestOfElement

protected void writeRestOfElement(java.lang.String qualifiedName,
                                  ElementDescriptor elementDescriptor,
                                  Context context)
                           throws java.io.IOException,
                                  org.xml.sax.SAXException,
                                  java.beans.IntrospectionException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

writeIDREFElement

protected void writeIDREFElement(java.lang.String qualifiedName,
                                 java.lang.String idrefAttributeName,
                                 java.lang.String idrefAttributeValue)
                          throws java.io.IOException,
                                 org.xml.sax.SAXException,
                                 java.beans.IntrospectionException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

writeContent

protected boolean writeContent(ElementDescriptor elementDescriptor,
                               Context context)
                        throws java.io.IOException,
                               org.xml.sax.SAXException,
                               java.beans.IntrospectionException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing
java.beans.IntrospectionException - if a java beans introspection problem occurs

writeAttributes

protected void writeAttributes(ElementDescriptor elementDescriptor,
                               Context context)
                        throws java.io.IOException,
                               org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

writeAttribute

protected void writeAttribute(AttributeDescriptor attributeDescriptor,
                              Context context)
                       throws java.io.IOException,
                              org.xml.sax.SAXException
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:
java.io.IOException - if an IO problem occurs during writing
org.xml.sax.SAXException - if an SAX problem occurs during writing

writePrintln

protected void writePrintln()
                     throws java.io.IOException
Deprecated. 0.5 replaced by new SAX inspired API

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

Throws:
java.io.IOException - if the line cannot be written

writeIndent

protected void writeIndent()
                    throws java.io.IOException
Deprecated. 0.5 replaced by new BeanWriter API

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

Throws:
java.io.IOException - if the indent cannot be written

convertToString

private java.lang.String convertToString(java.lang.Object value,
                                         Descriptor descriptor,
                                         Context context)
Converts an object to a string.

Parameters:
value - the Object to represent as a String, possibly null
descriptor - writing out this descriptor not null
context - not null
Returns:
String representation, not null

makeContext

private Context makeContext(java.lang.Object bean)
Factory method for new contexts. Ensure that they are correctly configured.

Parameters:
bean - make a new Context for this bean
Returns:
not null