com.openharbor.beck.write
Class TentativeXMLWriter

java.lang.Object
  extended byjava.io.Writer
      extended bycom.openharbor.beck.write.XMLWriter
          extended bycom.openharbor.beck.write.TentativeXMLWriter

public class TentativeXMLWriter
extends XMLWriter

Optimizes empty elements out of a generated XML document. startElement events are held in a write-behind buffer. The buffer is flushed to a nested XMLWriter whenever text, an attribute or an ordinary element is written. But if no such event occurs before a matching endElement, the startElement/endElement pair are simply discarded.


Nested Class Summary
 
Nested classes inherited from class com.openharbor.beck.write.XMLWriter
XMLWriter.MapKey
 
Field Summary
protected  XMLWriter out
           
protected static XMLWriter.MapKey TENTATIVE
           
 
Fields inherited from class com.openharbor.beck.write.XMLWriter
CYCLES, DECLARED_NAMESPACES, ELEMENT_NAME, prefixer, SOURCE, TEXT_IS_SIGNIFICANT, XSI, XSI_TYPE
 
Fields inherited from class java.io.Writer
lock
 
Method Summary
 void attribute(XMLName name, java.lang.String value)
          Add an attribute to the current element.
 void close()
           
protected  void declareNamespace(java.lang.String prefix, java.lang.String namespaceURI)
           
static TentativeXMLWriter decorate(XMLWriter out)
           
 void endElement()
           
 void flush()
           
 java.util.HashMap getElementStackTop()
           
 java.lang.String namespace(java.lang.String uri)
          Add a namespace declaration to the current element.
 java.lang.String namespace(java.lang.String prefix, java.lang.String uri)
          Add a namespace declaration to the current element.
protected  java.lang.String prefixToNamespace(java.lang.String prefix)
          Find the namespace URI for a given XML name prefix.
 void startElement(XMLThing tag)
           
 void startElementTentatively(XMLThing tag)
           
 void write(char[] content, int off, int len)
          Add text content to the current element.
 void write(java.lang.String content)
           
 void write(java.lang.String content, int off, int len)
           
 
Methods inherited from class com.openharbor.beck.write.XMLWriter
attributes, choosePrefix, getDocumentState, getElementStack, newMapKey, resolveNamespace, setDocumentState, startElement
 
Methods inherited from class java.io.Writer
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TENTATIVE

protected static final XMLWriter.MapKey TENTATIVE

out

protected XMLWriter out
Method Detail

decorate

public static TentativeXMLWriter decorate(XMLWriter out)
                                   throws java.io.IOException
Throws:
java.io.IOException

getElementStackTop

public java.util.HashMap getElementStackTop()
Overrides:
getElementStackTop in class XMLWriter
Returns:
the HashMap at the top of the element stack, or null if the stack is empty.

startElementTentatively

public void startElementTentatively(XMLThing tag)
                             throws java.io.IOException
Throws:
java.io.IOException

endElement

public void endElement()
                throws java.io.IOException
Overrides:
endElement in class XMLWriter
Throws:
java.io.IOException

startElement

public void startElement(XMLThing tag)
                  throws java.io.IOException
Overrides:
startElement in class XMLWriter
Throws:
java.io.IOException

namespace

public java.lang.String namespace(java.lang.String uri)
                           throws java.io.IOException
Description copied from class: XMLWriter
Add a namespace declaration to the current element.

Overrides:
namespace in class XMLWriter
Returns:
the prefix assigned to the given uri.
Throws:
java.io.IOException - if text or sub-elements have already been written in this element.

namespace

public java.lang.String namespace(java.lang.String prefix,
                                  java.lang.String uri)
                           throws java.io.IOException
Description copied from class: XMLWriter
Add a namespace declaration to the current element. The given prefix will be used unless it's null or conflicts with a previous request; in which case another prefix will be used.

Overrides:
namespace in class XMLWriter
Returns:
the prefix assigned to the given uri.
Throws:
java.io.IOException - if text or sub-elements have already been written in this element.

declareNamespace

protected void declareNamespace(java.lang.String prefix,
                                java.lang.String namespaceURI)
                         throws java.io.IOException
Specified by:
declareNamespace in class XMLWriter
Throws:
java.io.IOException

prefixToNamespace

protected java.lang.String prefixToNamespace(java.lang.String prefix)
                                      throws UnknownNamespaceException
Description copied from class: XMLWriter
Find the namespace URI for a given XML name prefix.

Overrides:
prefixToNamespace in class XMLWriter
Throws:
UnknownNamespaceException

attribute

public void attribute(XMLName name,
                      java.lang.String value)
               throws java.io.IOException
Description copied from class: XMLWriter
Add an attribute to the current element. If it's an xsi:type attribute, set the Type of the current element accordingly.

Overrides:
attribute in class XMLWriter
Throws:
java.io.IOException - if text or sub-elements have already been written in this element.

write

public void write(java.lang.String content)
           throws java.io.IOException
Overrides:
write in class XMLWriter
Throws:
java.io.IOException

write

public void write(java.lang.String content,
                  int off,
                  int len)
           throws java.io.IOException
Overrides:
write in class XMLWriter
Throws:
java.io.IOException

write

public void write(char[] content,
                  int off,
                  int len)
           throws java.io.IOException
Description copied from class: XMLWriter
Add text content to the current element. Do nothing if len <= 0.

Specified by:
write in class XMLWriter
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException