org.xpresso.xml.concurrent
Class ConcurrentDocument

java.lang.Object
  extended by org.xpresso.xml.XmlContent
      extended by org.xpresso.xml.Document
          extended by org.xpresso.xml.concurrent.ConcurrentDocument
All Implemented Interfaces:
java.io.Serializable, java.lang.CharSequence, java.lang.Cloneable

public class ConcurrentDocument
extends Document

Thread-safe version of Document. Methods are synchronized and the stack can only contain ConcurrentElement.

This code is under the LGPL v3 licence.

Author:
Alexis Dufrenoy
See Also:
Serialized Form

Field Summary
protected  java.util.Deque<ConcurrentElement> stack
           
 
Fields inherited from class org.xpresso.xml.Document
header, open
 
Fields inherited from class org.xpresso.xml.XmlContent
content
 
Constructor Summary
ConcurrentDocument(ConcurrentElement root)
           
ConcurrentDocument(java.lang.String xmlVersion, ConcurrentElement root)
           
ConcurrentDocument(java.lang.String xmlVersion, ConcurrentElement root, java.lang.String dtdName, java.lang.String dtdFile)
           
ConcurrentDocument(java.lang.String xmlVersion, java.lang.String encoding, ConcurrentElement root)
           
ConcurrentDocument(java.lang.String xmlVersion, java.lang.String encoding, ConcurrentElement root, boolean standalone)
           
ConcurrentDocument(java.lang.String xmlVersion, java.lang.String encoding, ConcurrentElement root, boolean standalone, java.lang.String dtdName, java.lang.String dtdFile)
           
ConcurrentDocument(java.lang.String xmlVersion, java.lang.String encoding, ConcurrentElement root, java.lang.String dtdName, java.lang.String dtdFile)
           
 
Method Summary
 void add(XmlContent xmlContent)
          Add an XmlContent to the uppest Element of the stack.
static Document createDocument(Element root)
           
static Document createDocument(java.lang.String xmlVersion, Element root)
           
static Document createDocument(java.lang.String xmlVersion, Element root, java.lang.String dtdName, java.lang.String dtdFile)
           
static Document createDocument(java.lang.String xmlVersion, java.lang.String encoding, Element root)
           
static Document createDocument(java.lang.String xmlVersion, java.lang.String encoding, Element root, boolean standalone)
           
static Document createDocument(java.lang.String xmlVersion, java.lang.String encoding, Element root, boolean standalone, java.lang.String dtdName, java.lang.String dtdFile)
           
static Document createDocument(java.lang.String xmlVersion, java.lang.String encoding, Element root, java.lang.String dtdName, java.lang.String dtdFile)
           
static Element createElement(java.lang.String label)
           
 void finish()
          Unstack all Elements, which means the document is closed.
 java.lang.String getText()
          Return the Document as a String which can be added to another Document, which means it has to be
closed and that the header informations are discarded.
 java.lang.String getXmlText()
          Return the Document in its current state of completion.
static void main(java.lang.String[] args)
          For test purpose only !
 void stackElement(Element element)
          Adds a level of depth to the current branch of the document.
 void unstackElement()
          Unstack a level of depth from the current branch of the document.
 
Methods inherited from class org.xpresso.xml.Document
charAt, clone, createCdata, createComment, createProcessingInstruction, createText, getStringReader, length, subSequence
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.CharSequence
toString
 

Field Detail

stack

protected java.util.Deque<ConcurrentElement> stack
Constructor Detail

ConcurrentDocument

public ConcurrentDocument(ConcurrentElement root)

ConcurrentDocument

public ConcurrentDocument(java.lang.String xmlVersion,
                          ConcurrentElement root,
                          java.lang.String dtdName,
                          java.lang.String dtdFile)

ConcurrentDocument

public ConcurrentDocument(java.lang.String xmlVersion,
                          ConcurrentElement root)

ConcurrentDocument

public ConcurrentDocument(java.lang.String xmlVersion,
                          java.lang.String encoding,
                          ConcurrentElement root,
                          boolean standalone,
                          java.lang.String dtdName,
                          java.lang.String dtdFile)

ConcurrentDocument

public ConcurrentDocument(java.lang.String xmlVersion,
                          java.lang.String encoding,
                          ConcurrentElement root,
                          boolean standalone)

ConcurrentDocument

public ConcurrentDocument(java.lang.String xmlVersion,
                          java.lang.String encoding,
                          ConcurrentElement root,
                          java.lang.String dtdName,
                          java.lang.String dtdFile)

ConcurrentDocument

public ConcurrentDocument(java.lang.String xmlVersion,
                          java.lang.String encoding,
                          ConcurrentElement root)
Method Detail

add

public void add(XmlContent xmlContent)
         throws ClosedDocumentException
Description copied from class: Document
Add an XmlContent to the uppest Element of the stack.
If the content is an Element, it will be added as an empty element.

Overrides:
add in class Document
Parameters:
xmlContent - Content to be added
Throws:
ClosedDocumentException - Thrown if the method is added after the document was closed

finish

public void finish()
Description copied from class: Document
Unstack all Elements, which means the document is closed.

Overrides:
finish in class Document

getText

public java.lang.String getText()
                         throws IllegalContentException
Description copied from class: Document
Return the Document as a String which can be added to another Document, which means it has to be
closed and that the header informations are discarded.

Overrides:
getText in class Document
Returns:
String containing the XmlContent
Throws:
IllegalContentException - Thrown if the Document is not closed

getXmlText

public java.lang.String getXmlText()
Description copied from class: Document
Return the Document in its current state of completion. If Elements are left on the stack,
the result will not be a well-formed XML document.

Overrides:
getXmlText in class Document
Returns:
The document as a String

stackElement

public void stackElement(Element element)
                  throws ClosedDocumentException
Description copied from class: Document
Adds a level of depth to the current branch of the document. It adds an Element.
Further content will be added to the newly added element, until a new one is stacked or it is unstacked.

Overrides:
stackElement in class Document
Parameters:
element - The new Element to be stacked
Throws:
ClosedDocumentException - Thrown if the method is added after the document was closed

unstackElement

public void unstackElement()
                    throws ClosedDocumentException
Description copied from class: Document
Unstack a level of depth from the current branch of the document. Further XmlContent
will be added to the Element just below the one unstacked. If this one is the last in
the stack, the document is closed.

Overrides:
unstackElement in class Document
Throws:
ClosedDocumentException - Thrown if the method is added after the document was closed

createDocument

public static Document createDocument(Element root)

createDocument

public static Document createDocument(java.lang.String xmlVersion,
                                      Element root)

createDocument

public static Document createDocument(java.lang.String xmlVersion,
                                      Element root,
                                      java.lang.String dtdName,
                                      java.lang.String dtdFile)

createDocument

public static Document createDocument(java.lang.String xmlVersion,
                                      java.lang.String encoding,
                                      Element root)

createDocument

public static Document createDocument(java.lang.String xmlVersion,
                                      java.lang.String encoding,
                                      Element root,
                                      java.lang.String dtdName,
                                      java.lang.String dtdFile)

createDocument

public static Document createDocument(java.lang.String xmlVersion,
                                      java.lang.String encoding,
                                      Element root,
                                      boolean standalone)

createDocument

public static Document createDocument(java.lang.String xmlVersion,
                                      java.lang.String encoding,
                                      Element root,
                                      boolean standalone,
                                      java.lang.String dtdName,
                                      java.lang.String dtdFile)

createElement

public static Element createElement(java.lang.String label)

main

public static final void main(java.lang.String[] args)
For test purpose only !

Parameters:
args -