public abstract class AbstractBeanWriter extends Object
Abstract superclass for bean writers. This class encapsulates the processing logic. Subclasses provide implementations for the actual expression of the xml.
Modifier and Type | Field and Description |
---|---|
private ArrayStack |
beanStack
Stack containing beans - used to detect cycles
|
private IDGenerator |
idGenerator
Used to generate ID attribute values
|
private HashMap |
idMap
Map containing ID attribute values for beans
|
private int |
indentLevel
indentation level
|
private XMLIntrospector |
introspector
Introspector used
|
private Log |
log
Log used for logging (Doh!)
|
private boolean |
writeIDs
Should generated
ID attribute values be added to the elements? |
Constructor and Description |
---|
AbstractBeanWriter() |
Modifier and Type | Method and Description |
---|---|
void |
end()
Marks the start of the bean writing.
|
protected abstract void |
expressAttribute(String qualifiedName,
String value)
Express an attribute
|
protected abstract void |
expressBodyText(String text)
Express body text
|
protected abstract void |
expressElementEnd()
Express an empty element end.
|
protected abstract void |
expressElementEnd(String qualifiedName)
Express an element end tag (with given name)
|
protected abstract void |
expressElementStart(String qualifiedName)
Express an element tag start using given qualified name.
|
protected abstract void |
expressTagClose()
Express a closing tag.
|
Log |
getAbstractBeanWriterLog()
Gets the current logging implementation.
|
IDGenerator |
getIdGenerator()
Get
IDGenerator implementation used to
generate ID attribute values . |
protected int |
getIndentLevel()
Get the indentation for the current element.
|
boolean |
getWriteIDs()
Should generated
ID attribute values be added to the elements? |
XMLIntrospector |
getXMLIntrospector()
Gets the introspector used.
|
protected Object |
popBean()
Pops the top bean off from the ancestry stack
|
protected void |
pushBean(Object bean)
Pushes the bean onto the ancestry stack.
|
void |
setAbstractBeanWriterLog(Log log)
Set the current logging implementation.
|
void |
setIdGenerator(IDGenerator idGenerator)
Set
IDGenerator implementation
used to generate ID attribute values. |
void |
setWriteIDs(boolean writeIDs)
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. |
void |
setXMLIntrospector(XMLIntrospector introspector)
Sets the introspector to be used.
|
void |
start()
Marks the start of the bean writing.
|
void |
write(Object bean)
Writes the given bean to the current stream using the XML introspector.
|
protected void |
write(String qualifiedName,
ElementDescriptor elementDescriptor,
Context context)
Writes the given element
|
protected void |
write(String qualifiedName,
ElementDescriptor elementDescriptor,
Context context,
String idAttribute,
String idValue)
Writes the given element adding an ID attribute
|
void |
write(String qualifiedName,
Object bean)
Writes the given bean to the current stream
using the given
qualifiedName . |
protected void |
writeAttribute(AttributeDescriptor attributeDescriptor,
Context context)
Writes an attribute declaration
|
protected void |
writeAttributes(ElementDescriptor elementDescriptor,
Context context)
Writes the attribute declarations
|
protected boolean |
writeContent(ElementDescriptor elementDescriptor,
Context context)
Writes the element content.
|
protected void |
writeIDREFElement(String qualifiedName,
String idrefAttributeName,
String idrefAttributeValue)
Writes an element with a
IDREF attribute |
protected void |
writeIndent()
Writes an indentation.
|
protected void |
writePrintln()
Writes a empty line.
|
protected void |
writeRestOfElement(String qualifiedName,
ElementDescriptor elementDescriptor,
Context context)
Write attributes, child elements and element end
|
private XMLIntrospector introspector
private Log log
private HashMap idMap
private ArrayStack beanStack
private IDGenerator idGenerator
private boolean writeIDs
ID
attribute values be added to the elements?private int indentLevel
public void start() throws IOException, SAXException
IOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingpublic void end() throws IOException, SAXException
IOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingpublic void write(Object bean) throws IOException, SAXException, 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 WriteIDs
property is false.
bean
- write out representation of this beanCyclicReferenceException
- when a cyclic reference is encounteredIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingIntrospectionException
- if a java beans introspection problem occurspublic void write(String qualifiedName, Object bean) throws IOException, SAXException, 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 WriteIDs
property is false.
qualifiedName
- the string naming root elementbean
- the Object
to write out as xmlCyclicReferenceException
- when a cyclic reference is encounteredIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingIntrospectionException
- if a java beans introspection problem occurspublic IDGenerator getIdGenerator()
IDGenerator
implementation used to
generate ID
attribute values .ID
attribute generationprotected int getIndentLevel()
public void setIdGenerator(IDGenerator idGenerator)
IDGenerator
implementation
used to generate ID
attribute values.
This property can be used to customize the algorithm used for generation.idGenerator
- use this implementation for ID
attribute generationpublic boolean getWriteIDs()
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.
ID
and IDREF
attributes are to be writtenpublic void setWriteIDs(boolean writeIDs)
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.writeIDs
- true if ID
's and IDREF
's should be writtenpublic 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
.
XMLIntrospector
used for introspectionpublic 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
.
introspector
- use this introspectorpublic final Log getAbstractBeanWriterLog()
Gets the current logging implementation.
Log
implementation which this class logs topublic final void setAbstractBeanWriterLog(Log log)
Set the current logging implementation.
log
- Log
implementation to useprotected abstract void expressElementStart(String qualifiedName) throws IOException, SAXException
qualifiedName
- the qualified name of the element to be expressedIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingprotected abstract void expressTagClose() throws IOException, SAXException
IOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingprotected abstract void expressElementEnd(String qualifiedName) throws IOException, SAXException
qualifiedName
- the qualified name for the element to be closedIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingprotected abstract void expressElementEnd() throws IOException, SAXException
IOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingprotected abstract void expressBodyText(String text) throws IOException, SAXException
text
- the string to write out as the body of the current elementIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingprotected abstract void expressAttribute(String qualifiedName, String value) throws IOException, SAXException
qualifiedName
- the qualified name of the attributevalue
- the attribute valueIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingprotected void write(String qualifiedName, ElementDescriptor elementDescriptor, Context context) throws IOException, SAXException, IntrospectionException
qualifiedName
- qualified name to use for the elementelementDescriptor
- the ElementDescriptor
describing the elementcontext
- the Context
to use to evaluate the bean expressionsIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingIntrospectionException
- if a java beans introspection problem occursprotected void write(String qualifiedName, ElementDescriptor elementDescriptor, Context context, String idAttribute, String idValue) throws IOException, SAXException, IntrospectionException
qualifiedName
- qualified name to use for the elementelementDescriptor
- the ElementDescriptor
describing the elementcontext
- the Context
to use to evaluate the bean expressionsidAttribute
- the qualified name of the ID
attributeidValue
- the value for the ID
attributeIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingIntrospectionException
- if a java beans introspection problem occursprotected void writeRestOfElement(String qualifiedName, ElementDescriptor elementDescriptor, Context context) throws IOException, SAXException, IntrospectionException
qualifiedName
- qualified name to use for the elementelementDescriptor
- the ElementDescriptor
describing the elementcontext
- the Context
to use to evaluate the bean expressionsIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingIntrospectionException
- if a java beans introspection problem occursprotected void writeIDREFElement(String qualifiedName, String idrefAttributeName, String idrefAttributeValue) throws IOException, SAXException, IntrospectionException
IDREF
attributequalifiedName
- of the element with IDREF
attributeidrefAttributeName
- the qualified name of the IDREF
attributeidrefAttributeValue
- the value for the IDREF
attributeIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingIntrospectionException
- if a java beans introspection problem occursprotected boolean writeContent(ElementDescriptor elementDescriptor, Context context) throws IOException, SAXException, IntrospectionException
elementDescriptor
- the ElementDescriptor
to write as xmlcontext
- the Context
to use to evaluate the bean expressionsIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingIntrospectionException
- if a java beans introspection problem occursprotected void writeAttributes(ElementDescriptor elementDescriptor, Context context) throws IOException, SAXException
elementDescriptor
- the ElementDescriptor
to be written out as xmlcontext
- the Context
to use to evaluation bean expressionsIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingprotected void writeAttribute(AttributeDescriptor attributeDescriptor, Context context) throws IOException, SAXException
attributeDescriptor
- the AttributeDescriptor
to be written as xmlcontext
- the Context
to use to evaluation bean expressionsIOException
- if an IO problem occurs during writingSAXException
- if an SAX problem occurs during writingprotected void writePrintln() throws IOException
IOException
- if the line cannot be writtenprotected void writeIndent() throws IOException
IOException
- if the indent cannot be writtenprotected void pushBean(Object bean)
bean
- push this bean onto the ancester stackCyclicReferenceException
- if there is an identical bean already on the stackprotected Object popBean()