Interface DomElement
- All Known Implementing Classes:
DomElementImpl
public interface DomElement
Encapsulates
Element
. Implementations of this interface must be thread-safe.- Author:
- Sebastian Menski
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCDataSection
(String data) Adds a CDATA section to this element.void
appendChild
(DomElement childElement) Appends the element to the child elements of this element.getAttribute
(String attributeName) Returns the attribute value for the namespace of this element.getAttribute
(String namespaceUri, String localName) Returns the attribute value for the given namespace.Returns all child elements of this element.getChildElementsByNameNs
(String namespaceUris, String elementName) Returns all child elements of this element with a specific namespace + namegetChildElementsByNameNs
(Set<String> namespaceUris, String elementName) Returns all child elements of this element with specific namespaces + name.getChildElementsByType
(ModelInstanceImpl modelInstance, Class<? extends ModelElementInstance> elementType) Returns all child elements of this element with a specific type.Returns the DOM document which contains this element.Returns the local name of this element.Returns theModelElementInstance
which is associated with this element.Returns the namespace URI for this element.Returns the parent element of this element.Returns the prefix of this element.Returns the root element of the document which contains this element.Gets the text content of this element all its descendants.boolean
hasAttribute
(String localName) Checks if this element has a attribute under the namespace of this element.boolean
hasAttribute
(String namespaceUri, String localName) Checks if this element has a attribute with the given namespace.void
insertChildElementAfter
(DomElement elementToInsert, DomElement insertAfter) Inserts the new child element after another child element.lookupPrefix
(String namespaceUri) Returns the prefix of the namespace starting from this node upwards.registerNamespace
(String namespaceUri) Adds a new namespace with a generated prefix to this element.void
registerNamespace
(String prefix, String namespaceUri) Adds a new namespace with prefix to this element.void
removeAttribute
(String localName) Removes the attribute for the namespace of this element.void
removeAttribute
(String namespaceUri, String localName) Removes the attribute for the given namespace.boolean
removeChild
(DomElement domElement) Removes a child element of this element.void
replaceChild
(DomElement newChildDomElement, DomElement existingChildDomElement) Replaces a child element with a new element.void
setAttribute
(String localName, String value) Sets the attribute value for the namespace of this element.void
setAttribute
(String namespaceUri, String localName, String value) Sets the attribute value for the given namespace.void
setIdAttribute
(String localName, String value) Sets the value of a id attribute for the namespace of this element.void
setIdAttribute
(String namespaceUri, String localName, String value) Sets the value of a id attribute for the given namespace.void
setModelElementInstance
(ModelElementInstance modelElementInstance) Sets theModelElementInstance
which should be associated with this element.void
setTextContent
(String textContent) Sets the text content of this element.
-
Method Details
-
getNamespaceURI
String getNamespaceURI()Returns the namespace URI for this element.- Returns:
- the namespace URI
-
getLocalName
String getLocalName()Returns the local name of this element.- Returns:
- the local name
-
getPrefix
String getPrefix()Returns the prefix of this element.- Returns:
- the prefix
-
getDocument
DomDocument getDocument()Returns the DOM document which contains this element.- Returns:
- the DOM document or null if the element itself is a document
-
getRootElement
DomElement getRootElement()Returns the root element of the document which contains this element.- Returns:
- the root element of the document or null if non exists
-
getParentElement
DomElement getParentElement()Returns the parent element of this element.- Returns:
- the parent element or null if not part of a tree
-
getChildElements
List<DomElement> getChildElements()Returns all child elements of this element.- Returns:
- the list of child elements
-
getChildElementsByNameNs
Returns all child elements of this element with a specific namespace + name- Returns:
- the list of child elements
-
getChildElementsByNameNs
Returns all child elements of this element with specific namespaces + name.- Returns:
- the list of child elements
-
getChildElementsByType
List<DomElement> getChildElementsByType(ModelInstanceImpl modelInstance, Class<? extends ModelElementInstance> elementType) Returns all child elements of this element with a specific type.- Returns:
- the list of child elements matching the type
-
replaceChild
Replaces a child element with a new element.- Parameters:
newChildDomElement
- the new child elementexistingChildDomElement
- the existing child element- Throws:
ModelException
- if the child cannot be replaced
-
removeChild
Removes a child element of this element.- Parameters:
domElement
- the child element to remove- Returns:
- true if the child element was removed otherwise false
-
appendChild
Appends the element to the child elements of this element.- Parameters:
childElement
- the element to append
-
insertChildElementAfter
Inserts the new child element after another child element. If the child element to insert after is null the new child element will be inserted at the beginning.- Parameters:
elementToInsert
- the new element to insertinsertAfter
- the existing child element to insert after or null
-
hasAttribute
Checks if this element has a attribute under the namespace of this element.- Parameters:
localName
- the name of the attribute- Returns:
- true if the attribute exists otherwise false
-
hasAttribute
Checks if this element has a attribute with the given namespace.- Parameters:
namespaceUri
- the namespaceUri of the namespacelocalName
- the name of the attribute- Returns:
- true if the attribute exists otherwise false
-
getAttribute
Returns the attribute value for the namespace of this element.- Parameters:
attributeName
- the name of the attribute- Returns:
- the value of the attribute or the empty string
-
getAttribute
Returns the attribute value for the given namespace.- Parameters:
namespaceUri
- the namespaceUri of the namespacelocalName
- the name of the attribute- Returns:
- the value of the attribute or the empty string
-
setAttribute
Sets the attribute value for the namespace of this element.- Parameters:
localName
- the name of the attributevalue
- the value to set
-
setAttribute
Sets the attribute value for the given namespace.- Parameters:
namespaceUri
- the namespaceUri of the namespacelocalName
- the name of the attributevalue
- the value to set
-
setIdAttribute
Sets the value of a id attribute for the namespace of this element.- Parameters:
localName
- the name of the attributevalue
- the value to set
-
setIdAttribute
Sets the value of a id attribute for the given namespace.- Parameters:
namespaceUri
- the namespaceUri of the namespacelocalName
- the name of the attributevalue
- the value to set
-
removeAttribute
Removes the attribute for the namespace of this element.- Parameters:
localName
- the name of the attribute
-
removeAttribute
Removes the attribute for the given namespace.- Parameters:
namespaceUri
- the namespaceUri of the namespacelocalName
- the name of the attribute
-
getTextContent
String getTextContent()Gets the text content of this element all its descendants.- Returns:
- the text content
-
setTextContent
Sets the text content of this element.- Parameters:
textContent
- the text content to set
-
addCDataSection
Adds a CDATA section to this element.- Parameters:
textContent
- the CDATA content to set
-
getModelElementInstance
ModelElementInstance getModelElementInstance()Returns theModelElementInstance
which is associated with this element.- Returns:
- the
ModelElementInstance
or null if non is associated
-
setModelElementInstance
Sets theModelElementInstance
which should be associated with this element.- Parameters:
modelElementInstance
- theModelElementInstance
to associate
-
registerNamespace
Adds a new namespace with a generated prefix to this element.- Parameters:
namespaceUri
- the namespaceUri of the namespace- Returns:
- the generated prefix for the new namespace
-
registerNamespace
Adds a new namespace with prefix to this element.- Parameters:
prefix
- the prefix of the namespacenamespaceUri
- the namespaceUri of the namespace
-
lookupPrefix
Returns the prefix of the namespace starting from this node upwards. The default namespace has the prefixnull
.- Parameters:
namespaceUri
- the namespaceUri of the namespace- Returns:
- the prefix or null if non is defined
-