|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.betwixt.io.AbstractBeanWriter
public abstract class AbstractBeanWriter
Abstract superclass for bean writers. This class encapsulates the processing logic. Subclasses provide implementations for the actual expression of the xml.
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:
start()
- called when processing beginsstartElement(WriteContext, String, String, String, Attributes)
- called when the start of an element
should be writtenbodyText(WriteContext, String)
- called when the start of an element
should be writtenendElement(WriteContext, String, String, String)
- called when the end of an element
should be writtenend()
- called when processing has been completedNote 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.
Constructor Summary | |
---|---|
AbstractBeanWriter()
|
Method Summary | |
---|---|
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 |
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 |
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. |
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 |
protected boolean |
writeContent(ElementDescriptor elementDescriptor,
Context context)
Deprecated. 0.5 replaced by new SAX inspired API |
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 |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractBeanWriter()
Method Detail |
---|
public void start() throws java.io.IOException, org.xml.sax.SAXException
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingpublic void end() throws java.io.IOException, org.xml.sax.SAXException
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingpublic 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.
bean
- write out representation of this bean
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 occurspublic 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.
qualifiedName
- the string naming root elementbean
- the Object
to write out as xml
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 occurspublic 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)
.
bean
- Object
to be written as xml, not nullsource
- 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
public IDGenerator getIdGenerator()
IDGenerator
implementation used to
generate ID
attribute values .
ID
attribute generationpublic 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 BindingConfiguration getBindingConfiguration()
public void setBindingConfiguration(BindingConfiguration bindingConfiguration)
bindingConfiguration
- the BindingConfiguration settings, not nullpublic boolean getWriteIDs()
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.
ID
and IDREF
attributes are to be writtenpublic void setWriteIDs(boolean writeIDs)
BindingConfiguration.setMapIDs(boolean)
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 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.
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.
writeEmptyElements
- true if empty elements should be written into the outputpublic 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 org.apache.commons.logging.Log getAbstractBeanWriterLog()
Gets the current logging implementation.
Log
implementation which this class logs topublic final void setAbstractBeanWriterLog(org.apache.commons.logging.Log log)
Set the current logging implementation.
log
- Log
implementation to useprotected 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
uri
- the element's namespace urilocalName
- the element's local nameqName
- the element's qualified nameattr
- the element's attributes
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void endElement(WriteContext context, java.lang.String uri, java.lang.String localName, java.lang.String qName) throws java.io.IOException, org.xml.sax.SAXException
uri
- the element's namespace urilocalName
- the element's local nameqName
- the element's qualified name
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void bodyText(WriteContext context, java.lang.String text) throws java.io.IOException, org.xml.sax.SAXException
text
- the body text to be written
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected 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
startElement(WriteContext, String, String, String, Attributes)
uri
- the element's namespace urilocalName
- the element's local nameqName
- the element's qualified nameattr
- the element's attributes
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName) throws java.io.IOException, org.xml.sax.SAXException
endElement(WriteContext, String, String, String)
uri
- the element's namespace urilocalName
- the element's local nameqName
- the element's qualified name
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void bodyText(java.lang.String text) throws java.io.IOException, org.xml.sax.SAXException
bodyText(WriteContext, String)
text
- the body text to be written
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void pushBean(java.lang.Object bean)
bean
- push this bean onto the ancester stackprotected java.lang.Object popBean()
protected int getIndentLevel()
protected void expressElementStart(java.lang.String qualifiedName) throws java.io.IOException, org.xml.sax.SAXException
qualifiedName
- the qualified name of the element to be expressed
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void expressElementStart(java.lang.String uri, java.lang.String localName, java.lang.String qualifiedName) throws java.io.IOException, org.xml.sax.SAXException
uri
- the namespace urilocalName
- the local name for this elementqualifiedName
- the qualified name of the element to be expressed
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void expressTagClose() throws java.io.IOException, org.xml.sax.SAXException
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void expressElementEnd(java.lang.String qualifiedName) throws java.io.IOException, org.xml.sax.SAXException
qualifiedName
- the qualified name for the element to be closed
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void expressElementEnd(java.lang.String uri, java.lang.String localName, java.lang.String qualifiedName) throws java.io.IOException, org.xml.sax.SAXException
uri
- the namespace uri of the element close taglocalName
- the local name of the element close tagqualifiedName
- the qualified name for the element to be closed
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void expressElementEnd() throws java.io.IOException, org.xml.sax.SAXException
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void expressBodyText(java.lang.String text) throws java.io.IOException, org.xml.sax.SAXException
text
- the string to write out as the body of the current element
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void expressAttribute(java.lang.String qualifiedName, java.lang.String value) throws java.io.IOException, org.xml.sax.SAXException
qualifiedName
- the qualified name of the attributevalue
- the attribute value
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected 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
namespaceUri
- the namespace urilocalName
- the local namequalifiedName
- the qualified name of the attributevalue
- the attribute value
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void write(java.lang.String qualifiedName, ElementDescriptor elementDescriptor, Context context) throws java.io.IOException, org.xml.sax.SAXException, java.beans.IntrospectionException
qualifiedName
- qualified name to use for the elementelementDescriptor
- the ElementDescriptor
describing the elementcontext
- the Context
to use to evaluate the bean expressions
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 occursprotected 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
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
attribute
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 occursprotected void writeRestOfElement(java.lang.String qualifiedName, ElementDescriptor elementDescriptor, Context context) throws java.io.IOException, org.xml.sax.SAXException, java.beans.IntrospectionException
qualifiedName
- qualified name to use for the elementelementDescriptor
- the ElementDescriptor
describing the elementcontext
- the Context
to use to evaluate the bean expressions
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 occursprotected 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
IDREF
attribute
qualifiedName
- of the element with IDREF
attributeidrefAttributeName
- the qualified name of the IDREF
attributeidrefAttributeValue
- the value for the IDREF
attribute
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 occursprotected boolean writeContent(ElementDescriptor elementDescriptor, Context context) throws java.io.IOException, org.xml.sax.SAXException, java.beans.IntrospectionException
elementDescriptor
- the ElementDescriptor
to write as xmlcontext
- the Context
to use to evaluate the bean expressions
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 occursprotected void writeAttributes(ElementDescriptor elementDescriptor, Context context) throws java.io.IOException, org.xml.sax.SAXException
elementDescriptor
- the ElementDescriptor
to be written out as xmlcontext
- the Context
to use to evaluation bean expressions
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void writeAttribute(AttributeDescriptor attributeDescriptor, Context context) throws java.io.IOException, org.xml.sax.SAXException
attributeDescriptor
- the AttributeDescriptor
to be written as xmlcontext
- the Context
to use to evaluation bean expressions
java.io.IOException
- if an IO problem occurs during writing
org.xml.sax.SAXException
- if an SAX problem occurs during writingprotected void writePrintln() throws java.io.IOException
java.io.IOException
- if the line cannot be writtenprotected void writeIndent() throws java.io.IOException
java.io.IOException
- if the indent cannot be written
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |