| java.lang.Object org.apache.commons.betwixt.io.AbstractBeanWriter org.apache.commons.betwixt.io.BeanWriter
BeanWriter | public class BeanWriter extends AbstractBeanWriter (Code) | | BeanWriter outputs beans as XML to an io stream.
The output for each bean is an xml fragment
(rather than a well-formed xml-document).
This allows bean representations to be appended to a document
by writing each in turn to the stream.
So to create a well formed xml document,
you'll need to write the prolog to the stream first.
If you append more than one bean to the stream,
then you'll need to add a wrapping root element as well.
The line ending to be used is set by
BeanWriter.setEndOfLine .
The output can be formatted (with whitespace) for easy reading
by calling
BeanWriter.enablePrettyPrint .
The output will be indented.
The indent string used is set by
BeanWriter.setIndent .
Bean graphs can sometimes contain cycles.
Care must be taken when serializing cyclic bean graphs
since this can lead to infinite recursion.
The approach taken by BeanWriter is to automatically
assign an ID attribute value to beans.
When a cycle is encountered,
an element is written that has the IDREF attribute set to the
id assigned earlier.
The names of the ID and IDREF attributes used
can be customized by the XMLBeanInfo .
The id's used can also be customized by the user
via IDGenerator subclasses.
The implementation used can be set by the IdGenerator property.
BeanWriter defaults to using SequentialIDGenerator
which supplies id values in numeric sequence.
If generated ID attribute values are not acceptable in the output,
then this can be disabled by setting the WriteIDs property to false.
If a cyclic reference is encountered in this case then a
CyclicReferenceException will be thrown.
When the WriteIDs property is set to false,
it is recommended that this exception is caught by the caller.
author: James Strachan author: Martin van den Bemt |
BeanWriter | public BeanWriter()(Code) | | Constructor uses System.out for output.
|
BeanWriter | public BeanWriter(OutputStream out)(Code) | | Constuctor uses given OutputStream for output.
Parameters: out - write out representations to this stream |
BeanWriter | public BeanWriter(OutputStream out, String enc) throws UnsupportedEncodingException(Code) | | Constuctor uses given OutputStream for output
and allows encoding to be set.
Parameters: out - write out representations to this stream Parameters: enc - the name of the encoding to be used. This should be compatiblewith the encoding types described in java.io throws: UnsupportedEncodingException - if the given encoding is not supported |
BeanWriter | public BeanWriter(Writer writer)(Code) | | Constructor sets writer used for output.
Parameters: writer - write out representations to this writer |
enablePrettyPrint | public void enablePrettyPrint()(Code) | | Switch on formatted output.
This sets the end of line and the indent.
The default is adding 2 spaces and a newline
|
endElement | protected void endElement(WriteContext context, String uri, String localName, String qualifiedName) throws IOException, SAXException(Code) | | Writes the end tag for an element
Parameters: uri - the element's namespace uri Parameters: localName - the element's local name Parameters: qualifiedName - the element's qualified name throws: IOException - if an IO problem occurs during writing throws: SAXException - if an SAX problem occurs during writing since: 0.5 |
escapeAttributeValue | protected String escapeAttributeValue(Object value)(Code) | | Escape the toString of the given object.
For use in an attribute value.
Parameters: value - escape value.toString() text with characters restricted (for use in attributes) escapedXMLUtils.escapeAttributeValue |
escapeBodyValue | protected String escapeBodyValue(Object value)(Code) | | Escape the toString of the given object.
For use as body text.
Parameters: value - escape value.toString() text with escaped delimiters XMLUtils.escapeBodyValue |
expressAttribute | protected void expressAttribute(String qualifiedName, String value) throws IOException(Code) | | Writes an attribute to the stream.
Parameters: qualifiedName - fully qualified attribute name Parameters: value - attribute value throws: IOException - when the stream write fails |
expressBodyText | protected void expressBodyText(String text) throws IOException(Code) | | Write element body text
Parameters: text - write out this body text throws: IOException - when the stream write fails |
expressElementEnd | protected void expressElementEnd(String qualifiedName) throws IOException(Code) | | Write an element end tag to the stream
Parameters: qualifiedName - the name of the element throws: IOException - when stream write fails |
expressElementEnd | protected void expressElementEnd() throws IOException(Code) | | Write an empty element end to the stream
throws: IOException - when stream write fails |
expressElementStart | protected void expressElementStart(String qualifiedName) throws IOException(Code) | | Express an element tag start using given qualified name
Parameters: qualifiedName - the fully qualified name of the element to write throws: IOException - when stream write fails |
expressTagClose | protected void expressTagClose() throws IOException(Code) | | Write a tag close to the stream
throws: IOException - when stream write fails |
flush | public void flush() throws IOException(Code) | | Allows output to be flushed on the underlying output stream
throws: IOException - when the flush cannot be completed |
getEndOfLine | public String getEndOfLine()(Code) | | Gets the string used to mark end of lines.
the string used for end of lines |
getIndent | public String getIndent()(Code) | | Gets the indent string
the string used for indentation |
getInitialIndentLevel | public int getInitialIndentLevel()(Code) | | Gets the initial indent level
the initial level for indentation since: 0.8 |
getLog | public Log getLog()(Code) | | Set the log implementation used.
a org.apache.commons.logging.Log level constant |
getMixedContentEncodingStrategy | public MixedContentEncodingStrategy getMixedContentEncodingStrategy()(Code) | | Gets the encoding strategy for mixed content.
This is used to process body content
before it is written to the textual output.
the MixedContentEncodingStrategy , not null since: 0.5 |
isEndTagForEmptyElement | public boolean isEndTagForEmptyElement()(Code) | | Should an end tag be added for each empty element?
When this property is false then empty elements will
be written as <element-name/gt; .
When this property is true then empty elements will
be written as <element-namegt;
</element-namegt; .
true if an end tag should be added |
setEndOfLine | public void setEndOfLine(String endOfLine)(Code) | | Sets the string used for end of lines
Produces a warning the specified value contains an invalid whitespace character
Parameters: endOfLine - the String |
setEndTagForEmptyElement | public void setEndTagForEmptyElement(boolean addEndTagForEmptyElement)(Code) | | Sets when an an end tag be added for each empty element.
When this property is false then empty elements will
be written as <element-name/gt; .
When this property is true then empty elements will
be written as <element-namegt;
</element-namegt; .
Parameters: addEndTagForEmptyElement - true if an end tag should be written for each empty element, false otherwise |
setIndent | public void setIndent(String indent)(Code) | | Sets the string used for pretty print indents
Parameters: indent - use this string for indents |
setInitialIndentLevel | public void setInitialIndentLevel(int initialIndentLevel)(Code) | | Sets the initial indent level used for pretty print indents
Parameters: initialIndentLevel - use this int to start with since: 0.8 |
setLog | public void setLog(Log log)(Code) | | Set the log implementation used.
Parameters: log - Log implementation to use |
setMixedContentEncodingStrategy | public void setMixedContentEncodingStrategy(MixedContentEncodingStrategy strategy)(Code) | | Sets the encoding strategy for mixed content.
This is used to process body content
before it is written to the textual output.
Parameters: strategy - the MixedContentEncodingStrategy used to process body content, not null since: 0.5 |
startElement | protected void startElement(WriteContext context, String uri, String localName, String qualifiedName, Attributes attr) throws IOException, SAXException(Code) | | Writes the start tag for an element.
Parameters: uri - the element's namespace uri Parameters: localName - the element's local name Parameters: qualifiedName - the element's qualified name Parameters: attr - the element's attributes throws: IOException - if an IO problem occurs during writing throws: SAXException - if an SAX problem occurs during writing since: 0.5 |
writeIndent | protected void writeIndent() throws IOException(Code) | | Writes out indent 's to the current indentLevel
throws: IOException - when stream write fails |
writePrintln | protected void writePrintln() throws IOException(Code) | | Writes out an empty line.
Uses current endOfLine .
throws: IOException - when stream write fails |
writeXmlDeclaration | public void writeXmlDeclaration(String xmlDeclaration) throws IOException(Code) | | A helper method that allows you to write the XML Declaration.
This should only be called once before you output any beans.
Parameters: xmlDeclaration - is the XML declaration string typically ofthe form "<xml version='1.0' encoding='UTF-8' ?> throws: IOException - when declaration cannot be written |
Methods inherited from org.apache.commons.betwixt.io.AbstractBeanWriter | protected void bodyText(WriteContext context, String text) throws IOException, SAXException(Code)(Java Doc) protected void bodyText(String text) throws IOException, SAXException(Code)(Java Doc) public void end() throws IOException, SAXException(Code)(Java Doc) protected void endElement(WriteContext context, String uri, String localName, String qName) throws IOException, SAXException(Code)(Java Doc) protected void endElement(String uri, String localName, String qName) throws IOException, SAXException(Code)(Java Doc) protected void expressAttribute(String qualifiedName, String value) throws IOException, SAXException(Code)(Java Doc) protected void expressAttribute(String namespaceUri, String localName, String qualifiedName, String value) throws IOException, SAXException(Code)(Java Doc) protected void expressBodyText(String text) throws IOException, SAXException(Code)(Java Doc) protected void expressElementEnd(String qualifiedName) throws IOException, SAXException(Code)(Java Doc) protected void expressElementEnd(String uri, String localName, String qualifiedName) throws IOException, SAXException(Code)(Java Doc) protected void expressElementEnd() throws IOException, SAXException(Code)(Java Doc) protected void expressElementStart(String qualifiedName) throws IOException, SAXException(Code)(Java Doc) protected void expressElementStart(String uri, String localName, String qualifiedName) throws IOException, SAXException(Code)(Java Doc) protected void expressTagClose() throws IOException, SAXException(Code)(Java Doc) final public Log getAbstractBeanWriterLog()(Code)(Java Doc) public BindingConfiguration getBindingConfiguration()(Code)(Java Doc) public IDGenerator getIdGenerator()(Code)(Java Doc) protected int getIndentLevel()(Code)(Java Doc) public boolean getWriteEmptyElements()(Code)(Java Doc) public boolean getWriteIDs()(Code)(Java Doc) public XMLIntrospector getXMLIntrospector()(Code)(Java Doc) protected Object popBean()(Code)(Java Doc) protected void pushBean(Object bean)(Code)(Java Doc) final public void setAbstractBeanWriterLog(Log log)(Code)(Java Doc) public void setBindingConfiguration(BindingConfiguration bindingConfiguration)(Code)(Java Doc) public void setIdGenerator(IDGenerator idGenerator)(Code)(Java Doc) public void setWriteEmptyElements(boolean writeEmptyElements)(Code)(Java Doc) public void setWriteIDs(boolean writeIDs)(Code)(Java Doc) public void setXMLIntrospector(XMLIntrospector introspector)(Code)(Java Doc) public void start() throws IOException, SAXException(Code)(Java Doc) protected void startElement(WriteContext context, String uri, String localName, String qName, Attributes attr) throws IOException, SAXException(Code)(Java Doc) protected void startElement(String uri, String localName, String qName, Attributes attr) throws IOException, SAXException(Code)(Java Doc) public void write(Object bean) throws IOException, SAXException, IntrospectionException(Code)(Java Doc) public void write(String qualifiedName, Object bean) throws IOException, SAXException, IntrospectionException(Code)(Java Doc) public void write(Object bean, InputSource source) throws IOException, SAXException, IntrospectionException(Code)(Java Doc) protected void write(String qualifiedName, ElementDescriptor elementDescriptor, Context context) throws IOException, SAXException, IntrospectionException(Code)(Java Doc) protected void write(String qualifiedName, ElementDescriptor elementDescriptor, Context context, String idAttribute, String idValue) throws IOException, SAXException, IntrospectionException(Code)(Java Doc) protected void writeAttribute(AttributeDescriptor attributeDescriptor, Context context) throws IOException, SAXException(Code)(Java Doc) protected void writeAttributes(ElementDescriptor elementDescriptor, Context context) throws IOException, SAXException(Code)(Java Doc) protected boolean writeContent(ElementDescriptor elementDescriptor, Context context) throws IOException, SAXException, IntrospectionException(Code)(Java Doc) protected void writeIDREFElement(String qualifiedName, String idrefAttributeName, String idrefAttributeValue) throws IOException, SAXException, IntrospectionException(Code)(Java Doc) protected void writeIndent() throws IOException(Code)(Java Doc) protected void writePrintln() throws IOException(Code)(Java Doc) protected void writeRestOfElement(String qualifiedName, ElementDescriptor elementDescriptor, Context context) throws IOException, SAXException, IntrospectionException(Code)(Java Doc)
|
|
|