|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
This is an interface to represent an element in an XML Document Object Model (DOM).
While Element objects can exist outside the context of a document, this is
an interface and therefore cannot be constructed directly. Therefore the
Document interface contains the factory methods needed to create
these objects. Element objects created with the various versions of the
Document.createElement(String) method will have no ownerDocument
until inserted in or appended to a Document.
All Element objects must have an ID (set as the "id" attribute). If you do not assign an ID, one will be auto-assigned when the Element is added to a Document. Once the Element is in a document, the ID may no longer be set.
There are several event listeners that may be registered on an element.
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 the client side DOM
// should be done inside the synchronized block.
}
DocumentRegistry,
Document,
Parser,
ParserFactory| Method Summary | |
void |
addAttributeChangeListener(AttributeChangeListener listener)
Adds a listener to this Element for attribute changes. |
void |
addDocumentOwnershipListener(DocumentOwnershipListener listener)
Adds a DocumentOwnershipListener to this element. |
void |
addStructureChangeListener(StructureChangeListener listener)
Adds a StructureChangeListener to this Element for DOM structure changes. |
java.lang.Object |
appendChild(Element e)
Appends a child element to the end of the child list. |
java.lang.Object |
appendChild(java.lang.String text)
This will append a "Text Node" to this element. |
java.lang.Object |
appendXml(java.lang.String text)
This will parse the specified XML to create an Element structure which will be appended to the child list of this Element. |
Element |
clone(boolean withIds)
Clones an Element. |
Element |
deepClone(boolean withIds)
Clones an Element. |
boolean |
equals(Element e,
boolean deep)
This will compare two elements to see if they are equal. |
java.lang.String |
getAttribute(java.lang.String name)
Returns the value of the attribute with the given name for this element. |
int |
getAttributeCount()
Returns the number of attributes this element contains. |
java.lang.String |
getAttributeNameAt(int index)
Returns the attribute name at the specified index in this element. |
java.util.Enumeration |
getAttributeNames()
Returns an Enumeration containing the names of the attributes on this element. |
java.lang.String |
getAttributeValueAt(int index)
Returns the attribute value at the specified index in this element. |
java.util.Enumeration |
getAttributeValues()
Returns an Enumeration containing the values of the attributes on this element. |
java.lang.Object |
getChildAt(int index)
Returns the child at a specified index in the child list. |
int |
getChildCount()
Returns the number of children this element has. |
java.util.Vector |
getChildren()
Returns a Vector containing all the children of this Element. |
java.lang.String |
getFirstTextChild()
This will return the first text node of this element. |
java.lang.String |
getLocalName()
Returns the local name (also known as tag name) for this Element. |
java.lang.String |
getNamespaceUri()
Returns the namespace URI for this Element. |
Document |
getOwnerDocument()
Returns the owner document of this element. |
Element |
getParent()
Returns the parent Element of this Element. |
java.lang.String |
getPrefix()
Returns the namespace prefix for this element. |
java.lang.String |
getQName()
Returns the QName for this element. |
int |
indexOfChild(Element child)
Returns the index of the specified child Element, or -1 if no such child Element exists. |
int |
indexOfChild(java.lang.String text)
Returns the index of the specified text node, or -1 if no such text node exists. |
java.lang.Object |
insertChildAt(int index,
Element e)
Inserts a child at the specified position in the child list. |
java.lang.Object |
insertChildAt(int index,
java.lang.String text)
Inserts a text node at the specified position in this element. |
void |
normalize()
This method is equivalent to the W3C normalize behavior. |
boolean |
removeAttribute(java.lang.String name)
Removes the attribute with the given name. |
java.lang.String |
removeAttributeAt(int index)
Removes the attribute at a specified index on this element. |
boolean |
removeAttributeChangeListener(AttributeChangeListener listener)
Removes an AttributeChangeListener from this Element. |
java.lang.Object |
removeChild(Element e)
Removes the specified Element from the child list. |
java.lang.Object |
removeChild(java.lang.String text)
Removes the specified text child from this Element if it exists. |
java.lang.Object |
removeChildAt(int index)
Removes the Element at the specified index. |
boolean |
removeDocumentOwnershipListener(DocumentOwnershipListener listener)
Removes a DocumentOwnershipListener from this element. |
boolean |
removeStructureChangeListener(StructureChangeListener listener)
Removes a StructureChangeListener from this Element |
java.lang.Object |
replaceChildAt(int index,
Element newValue)
Replaces the child at the specified index with the supplied element. |
java.lang.Object |
replaceChildAt(int index,
java.lang.String newValue)
Replaces the child at the specified index with the supplied text node. |
java.lang.String |
setAttribute(java.lang.String name,
java.lang.String value)
Sets an attribute on this element. |
java.lang.String |
setFirstTextChild(java.lang.String text)
This will replace the first text node of this element. |
java.lang.String |
toXml(boolean prettyPrint)
Returns a String representation of this XML Element including any Nexaweb-generated XML ID attributes. |
java.lang.String |
toXmlWithoutAutoAssignedIds(boolean prettyPrint)
Returns a String representation of this XML Element NOT including any Nexaweb-generated XML ID attributes. |
java.lang.String |
toXmlWithSimpleAttributeEncoding(boolean prettyPrint)
Returns a String representation of this XML Element, attributes will have only double quotes XML encoded and the elements will include any Nexaweb-generated XML ID attributes. |
java.lang.String |
toXmlWithSimpleAttributeEncodingWithoutAutoAssignedIds(boolean prettyPrint)
Returns a String representation of this XML Element, attributes will have only double quotes XML encoded and the elements will not include any Nexaweb-generated XML ID attributes. |
| Method Detail |
public Document getOwnerDocument()
Documentpublic java.lang.String getAttribute(java.lang.String name)
name - The name of the attribute to get the value of.
setAttribute(String, String),
getAttributeNameAt(int),
getAttributeValueAt(int)public int getAttributeCount()
public java.lang.String getAttributeNameAt(int index)
index - The index of the attribute you want the name of.
java.lang.ArrayIndexOutOfBoundsException - If the index given is not valid.getAttributeValueAt(int),
getAttribute(String)public java.lang.String getAttributeValueAt(int index)
index - The index of the attribute you want the value of.
java.lang.ArrayIndexOutOfBoundsException - If the index given is not valid.getAttributeNameAt(int),
getAttributeValueAt(int)public java.util.Enumeration getAttributeNames()
ConcurrentModificationException.
Enumeration,
getAttributeValues()public java.util.Enumeration getAttributeValues()
Enumeration,
getAttributeNames()
public java.lang.String setAttribute(java.lang.String name,
java.lang.String value)
throws ChangeRejectedException
name - The name of the attribute to set.value - The value of the attribute to be set.
ChangeRejectedException - If this operation was rejected by one of
the AttributeChangeListenersAttributeChangeListener,
getAttribute(String)
public java.lang.String removeAttributeAt(int index)
throws ChangeRejectedException
index - The index of the attribute to be removed.
java.lang.ArrayIndexOutOfBoundsException - If the specified index is not
valid.
ChangeRejectedException - If the removal was rejected by one of the
AttributeChangeListeners registered for this element.removeAttribute(String)
public boolean removeAttribute(java.lang.String name)
throws ChangeRejectedException
name - The name of the attribute to be removed.
ChangeRejectedException - If the removal was rejected by one of the
AttributeChangeListeners registered for this element.removeAttributeAt(int)public int getChildCount()
getChildren(),
getChildAt(int)public java.util.Vector getChildren()
getChildAt(int),
getChildCount()public java.lang.Object getChildAt(int index)
java.lang.String or an
Element.
Note: A valid index is in the range: [0, getChildCount()-1]
index - The index of the child to be returned.
java.lang.ArrayIndexOutOfBoundsException - If the index supplied is not
valid.indexOfChild(Element),
indexOfChild(String),
getChildCount()public int indexOfChild(Element child)
child - The element to get the index of.
indexOfChild(String)public int indexOfChild(java.lang.String text)
text - The text node to get the index of.
public java.lang.Object appendChild(Element e)
throws ChangeRejectedException
e - - the Element wishing to be appended.
ChangeRejectedException - - if the append was rejected by a
listener.
java.lang.IllegalStateException - if the element being added causes an ID
conflict with an element already existing in this element's document and
if the element being added has a prefix/namespace pair that conflicts
with an existing prefix/namespace pair in this document.
public java.lang.Object appendChild(java.lang.String text)
throws ChangeRejectedException
text - - the text wishing to be appended to this element.
ChangeRejectedException - - if the append was rejected by a
listener.
public java.lang.Object appendXml(java.lang.String text)
throws ChangeRejectedException,
ParserException
ChangeRejectedException - - if the append was rejected by a
listener.
ParserException
public java.lang.Object insertChildAt(int index,
Element e)
throws ChangeRejectedException
index - - the index for the Element to be inserted ate - - the element to be inserted.
java.lang.IllegalArgumentException - - if the specified index is not
valid
ChangeRejectedException - - if the insert was rejected by a
listener.
java.lang.IllegalStateException - if the element being added causes an ID
conflict with an element already existing in this element's document and
if the element being added has a prefix/namespace pair that conflicts
with an existing prefix/namespace pair in this document.getChildCount(),
insertChildAt(int, String)
public java.lang.Object insertChildAt(int index,
java.lang.String text)
throws ChangeRejectedException
index - - the index to be insertedtext - - the text to be inserted
ChangeRejectedException - - if the insert was rejected by a
listener.getChildCount(),
insertChildAt(int, Element)
public java.lang.Object removeChild(Element e)
throws ChangeRejectedException
e - - the Element to be removed.
ChangeRejectedException - - if the remove was rejected by a
listener.
public java.lang.Object removeChild(java.lang.String text)
throws ChangeRejectedException
text - The text to remove as the text child of this element.
ChangeRejectedException - - if the remove was rejected by a
listener.
public java.lang.Object removeChildAt(int index)
throws ChangeRejectedException
index - - the index of the Element to be removed.
java.lang.IllegalArgumentException - - if the specified index is
not valid.
ChangeRejectedException - - if the remove was rejected by a
listener.
public java.lang.Object replaceChildAt(int index,
java.lang.String newValue)
throws ChangeRejectedException
removeChildAt(index);
insertChildAt(index, newValue);
index - The index of the child to be replaced.newValue - The new child to be inserted at that position.
ChangeRejectedException - If the removing of the current value
or the addition of the supplied value was rejected by a
StructureChangeListener.
public java.lang.Object replaceChildAt(int index,
Element newValue)
throws ChangeRejectedException
removeChildAt(index);
insertChildAt(index, newValue);
index - The index of the child to be replaced.newValue - The new child to be inserted at that position.
ChangeRejectedException - If the removing of the current value
or the addition of the supplied value was rejected by a
StructureChangeListener.public Element getParent()
public java.lang.String getPrefix()
public java.lang.String getNamespaceUri()
public java.lang.String getLocalName()
public java.lang.String getQName()
public void addAttributeChangeListener(AttributeChangeListener listener)
listener - - the listener to addAttributeChangeListener,
AttributeChangeEventpublic boolean removeAttributeChangeListener(AttributeChangeListener listener)
listener - - the listener to remove
AttributeChangeListener,
AttributeChangeEventpublic void addStructureChangeListener(StructureChangeListener listener)
listener - - the listener to addStructureChangeListener,
StructureChangeEventpublic boolean removeStructureChangeListener(StructureChangeListener listener)
listener - - the listener to remove
StructureChangeListener,
StructureChangeEventpublic void addDocumentOwnershipListener(DocumentOwnershipListener listener)
listener - The listener to add.public boolean removeDocumentOwnershipListener(DocumentOwnershipListener listener)
listener - The listener to be removed from this element.
public java.lang.String getFirstTextChild()
normalize()
public java.lang.String setFirstTextChild(java.lang.String text)
throws ChangeRejectedException
text - The string representing what the first text node should
become.
ChangeRejectedException - If replacing the first text node was
rejected by a StructureChangeListener.public void normalize()
getFirstTextChild()public Element clone(boolean withIds)
deepClone
method.
withIds - - if this is true automatically generated IDs will get
cloned with the element. If this is false all IDs that were previously
generated will get re-assigned a new unique ID.
deepClone(boolean)public Element deepClone(boolean withIds)
withIds - - if this is true automatically generated IDs will get
cloned with the element. If this is false all IDs that were previously
generated will get re-assigned a new unique ID.
clone(boolean)
public boolean equals(Element e,
boolean deep)
e - - the element to compare this element to.deep - - whether the elements' children should be considered in the
comparison.
public java.lang.String toXml(boolean prettyPrint)
prettyPrint - If true, the generated string will contain newlines
and tabs to make the XML more readable.
toXmlWithoutAutoAssignedIds(boolean)public java.lang.String toXmlWithoutAutoAssignedIds(boolean prettyPrint)
prettyPrint - If true, the generated string will contain newlines
and tabs to make the XML more readable.
public java.lang.String toXmlWithSimpleAttributeEncoding(boolean prettyPrint)
prettyPrint - If true, the generated string will contain newlines
and tabs to make the XML more readable.
toXmlWithoutAutoAssignedIds(boolean)public java.lang.String toXmlWithSimpleAttributeEncodingWithoutAutoAssignedIds(boolean prettyPrint)
prettyPrint - If true, the generated string will contain newlines
and tabs to make the XML more readable.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||