|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
The Document interface represents an entire XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
Listeners may be registered at the Document level to hear changes in the entire document.
The Document has a map of id to Element for every Element. Therefore it is able to provide efficient hash based element lookup by id.
Documents may be obtained from Parser objects.
IMPORTANT:
Nexaweb's Document Object Model (DOM) is a data structure. As with most data structures (such as List, Set, Map, etc.) Nexaweb's DOM is not thread safe. You must obtain the DOM lock before accessing the DOM.
In the case of the UI Document, you must ALWAYS get the DOM lock before manipulating the DOM because Nexaweb's client code accesses the DOM too. Failure to obtain the lock when accessing and manipulating the DOM can cause the client to freeze.
With other documents (such as local datasets) where your code is the only code that accesses the data structure, if you are operating in a single thread there is no need to obtain the lock. Note that synchronized or shared datasets are accessed by Nexaweb's synchronization threads and the lock must be obtained.
EXAMPLE:
When modifying the client side DOM from an MCO developers MUST wrap their changes in a synchronized block in the following way.
ClientSession session = getClientSession();
Document uiDoc = session.getDocumentRegistry()
.findDocument(DocumentRegistry.UI_DOCUMENT_NAME);
synchronized ( uiDoc.getDomSynchronizationObject() ) {
// MAKE ALL UI DOM OR NFC CHANGES HERE
// Any and all changes to any shared document
// should be done inside the synchronized block.
}
DocumentRegistry,
Element,
Parser,
ParserFactory| Method Summary | |
void |
addAttributeChangeListener(AttributeChangeListener listener)
Adds a listener to this document for attribute changes. |
void |
addStructureChangeListener(StructureChangeListener listener)
Adds a listener to this document for DOM structure changes. |
Element |
createElement(java.lang.String localName)
Creates an element with the specified local name. |
Element |
createElement(java.lang.String localName,
java.lang.String ns)
Creates an element with the specified local name and namespace URI. |
Element |
createElement(java.lang.String localName,
java.lang.String prefix,
java.lang.String ns)
Creates an element with the specified local name, prefix, and namespace URI. |
java.lang.Object |
getDomSynchronizationObject()
Returns an object that users of this document should synchronized on. |
Element |
getElementById(java.lang.String id)
Returns the Element contained in this document with the specified ID. |
java.lang.String |
getEncoding()
Returns the encoding for this document. |
Element |
getRootElement()
Returns the root Element of this Document. |
boolean |
removeAttributeChangeListener(AttributeChangeListener listener)
Removes an AttributeChangeListener from this Document. |
boolean |
removeStructureChangeListener(StructureChangeListener listener)
Removes an StructureChangeListener from this Document. |
void |
setRootElement(Element root)
Sets this Document's root element. |
java.lang.String |
toXml(boolean prettyPrint)
Returns a String representation of this Document with any Nexaweb-generated XML ID attributes. |
java.lang.String |
toXmlWithoutAutoAssignedIds(boolean prettyPrint)
Returns a String representation of this Document without any Nexaweb-generated XML ID attributes. |
| Method Detail |
public Element createElement(java.lang.String localName)
throws java.lang.IllegalArgumentException
localName - The local name of the new element.
java.lang.IllegalArgumentException - Thrown if the specified local name
is not a legal xml localname or null.
public Element createElement(java.lang.String localName,
java.lang.String ns)
throws java.lang.IllegalArgumentException
localName - The local name of the new element.ns - The namespace URI for the new element.
java.lang.IllegalArgumentException - Thrown if the specified local name
is not a legal xml localname, or any of the arguments are null.
public Element createElement(java.lang.String localName,
java.lang.String prefix,
java.lang.String ns)
throws java.lang.IllegalArgumentException
localName - The local name of the new element.prefix - The prefix for the new element.ns - The namespace URI for the new element.
java.lang.IllegalArgumentException - Thrown if the specified local name
is not a legal xml localname, or any of the arguments are null.public Element getRootElement()
Elementpublic java.lang.String getEncoding()
public void addAttributeChangeListener(AttributeChangeListener listener)
listener - - the listener to registerAttributeChangeListener,
AttributeChangeEventpublic boolean removeAttributeChangeListener(AttributeChangeListener listener)
listener - - the listener to remove
AttributeChangeListener,
AttributeChangeEventpublic void addStructureChangeListener(StructureChangeListener listener)
listener - - the listener to registerStructureChangeListener,
StructureChangeEventpublic boolean removeStructureChangeListener(StructureChangeListener listener)
listener - - the listener to remove
StructureChangeListener,
StructureChangeEventpublic Element getElementById(java.lang.String id)
id - the id of the Element to return.
public void setRootElement(Element root)
root - the new root element of this Document.public java.lang.String toXml(boolean prettyPrint)
prettyPrint - If true, newlines and tabs will be present in the
resulting string to make it more readable.
public java.lang.String toXmlWithoutAutoAssignedIds(boolean prettyPrint)
prettyPrint - If true, newlines and tabs will be present in the
resulting string to make it more readable.
public java.lang.Object getDomSynchronizationObject()
IMPORTANT:
Nexaweb's Document Object Model (DOM) is a data structure. As with most data structures (such as List, Set, Map, etc.) Nexaweb's DOM is not thread safe. You must obtain the DOM lock before accessing the DOM.
In the case of the UI Document, you must ALWAYS get the DOM lock before manipulating the DOM because Nexaweb's client code accesses the DOM too. Failure to obtain the lock when accessing and manipulating the DOM can cause the client to freeze.
With other documents (such as local datasets) where your code is the only code that accesses the data structure, if you are operating in a single thread there is no need to obtain the lock. Note that synchronized or shared datasets are accessed by Nexaweb's synchronization threads and the lock must be obtained.
EXAMPLE:
When modifying the client side DOM from an MCO developers MUST wrap their changes in a synchronized block in the following way.
ClientSession session = getClientSession();
Document uiDoc = session.getDocumentRegistry()
.findDocument(DocumentRegistry.UI_DOCUMENT_NAME);
synchronized ( uiDoc.getDomSynchronizationObject() ) {
// MAKE ALL UI DOM OR NFC CHANGES HERE
// Any and all changes to shared documents
// should be done inside the synchronized block.
}
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||