Java Doc for BeanWriter.java in  » Library » Apache-commons-betwixt-0.8-src » org » apache » commons » betwixt » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons betwixt 0.8 src » org.apache.commons.betwixt.io 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


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




Constructor Summary
public  BeanWriter()
    
public  BeanWriter(OutputStream out)
    
public  BeanWriter(OutputStream out, String enc)
    

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.
public  BeanWriter(Writer writer)
    

Method Summary
protected  voidbodyText(WriteContext context, String text)
    
public  voidclose()
    
public  voidenablePrettyPrint()
    

Switch on formatted output.

protected  voidendElement(WriteContext context, String uri, String localName, String qualifiedName)
    
protected  StringescapeAttributeValue(Object value)
    

Escape the toString of the given object.

protected  StringescapeBodyValue(Object value)
    

Escape the toString of the given object.

protected  voidexpressAttribute(String qualifiedName, String value)
     Writes an attribute to the stream.
protected  voidexpressBodyText(String text)
    
protected  voidexpressElementEnd(String qualifiedName)
    
protected  voidexpressElementEnd()
    
protected  voidexpressElementStart(String qualifiedName)
    
protected  voidexpressTagClose()
    
public  voidflush()
    
public  StringgetEndOfLine()
     Gets the string used to mark end of lines.
public  StringgetIndent()
    
public  intgetInitialIndentLevel()
    
public  LoggetLog()
    

Set the log implementation used.

public  MixedContentEncodingStrategygetMixedContentEncodingStrategy()
     Gets the encoding strategy for mixed content.
public  booleanisEndTagForEmptyElement()
    

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;.

public  voidsetEndOfLine(String endOfLine)
    
public  voidsetEndTagForEmptyElement(boolean addEndTagForEmptyElement)
     Sets when an an end tag be added for each empty element.
public  voidsetIndent(String indent)
    
public  voidsetInitialIndentLevel(int initialIndentLevel)
    
public  voidsetLog(Log log)
    

Set the log implementation used.

public  voidsetMixedContentEncodingStrategy(MixedContentEncodingStrategy strategy)
     Sets the encoding strategy for mixed content.
protected  voidstartElement(WriteContext context, String uri, String localName, String qualifiedName, Attributes attr)
     Writes the start tag for an element.
public  voidwrite(Object bean)
     Write the given object to the stream (and then flush).
protected  voidwriteIndent()
    
protected  voidwritePrintln()
     Writes out an empty line.
public  voidwriteXmlDeclaration(String xmlDeclaration)
     A helper method that allows you to write the XML Declaration.


Constructor Detail
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




Method Detail
bodyText
protected void bodyText(WriteContext context, String text) throws IOException(Code)
Write element body text
Parameters:
  text - write out this body text
throws:
  IOException - when the stream write fails
since:
   0.5



close
public void close() throws IOException(Code)
Closes the underlying output stream
throws:
  IOException - when writer cannot be closed



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 MixedContentEncodingStrategyused 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



write
public void write(Object bean) throws IOException, SAXException, IntrospectionException(Code)
Write the given object to the stream (and then flush).
Parameters:
  bean - write this Object to the stream
throws:
  IOException - if an IO problem causes failure
throws:
  SAXException - if a SAX problem causes failure
throws:
  IntrospectionException - if bean cannot be introspected



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)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.