de.vc.xml

## Class AbstractNode

- java.lang.Object
- - de.vc.xml.AbstractNode

- All Implemented Interfaces:
    Node, NodeElement, java.io.Serializable, java.lang.Cloneable
  Direct Known Subclasses:
    AbstractNodeWithAttributes

      public abstract class AbstractNode
      extends java.lang.Object
      implements Node

  This abstract class represents a XML node.
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `` | `AbstractNode(java.lang.String nodeName)` Constructs a node.
    `protected` | `AbstractNode(java.lang.String nodeName, Node parent)` Constructs a node.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addAttributeChangeListener(AttributeChangeListener l)` Adds an listener that is notified when an attribute was changed.
    `void` | `addElements(java.util.Collection<?> elements)` Adds some NodeElements to this FormattingObject.
    `void` | `addElements(java.lang.Object[] elements)` Adds some NodeElements to this FormattingObject.
    `void` | `clearEqualAttributes(Node node, boolean deep)` Clears all attributes of this node, that are defined in the given node with equal values.
    `boolean` | `clearInheratedAttribute(java.lang.String name)` Clears an attributed that was defined by a parent node and has same value.
    `void` | `clearInheratedAttributes()` Clears all attributes that were defined by a parent node and have same value.
    `void` | `clearValue(java.lang.String name)` Clears an attribute, this means they value becomes NULL.
    `java.lang.Object` | `clone()` Clones this element.
    `boolean` | `contains(Node child)` Tests if this node contains the given node directly.
    `boolean` | `contains(Node child, boolean deep)` Tests if this node contains the given node.
    `void` | `copyAttributes(Node node)` Copies all attributes of given node to this node.
    `protected static long` | `createID()` Creates a unique ID for a node.
    `protected abstract java.lang.Object` | `doGetAttribute(java.lang.String name)` Do implement this Method.
    `protected abstract boolean` | `doSetAttribute(java.lang.String name, java.lang.Object value)` Do implement this Method.
    `Node` | `findFirstNodeWithText(java.lang.String text, boolean deep)`
    `Node` | `findNode(java.lang.String nodeName, java.lang.String attrName, java.lang.String attrValue)` Searches for a node with a specific attribute in this node.
    `java.util.List<Node>` | `findNodesWithText(java.lang.String text, boolean deep)` Finds all elements that contains a specific text.
    `protected void` | `fire(ValueChangeEvent evt)` Fire a ValueChangeEvent.
    `void` | `fireSaxEvents(org.xml.sax.ContentHandler handler)` Fires SAX events to a SAX content handler.
    `java.lang.Object` | `firstElement()` Gets the first element of this node.
    `boolean` | `getAttrAsBoolean(java.lang.String name, boolean inherit, boolean defValue)` Gets an boolean attribute.
    `int` | `getAttrAsInteger(java.lang.String name, boolean inherit, int defaultValue)`
    `java.lang.String` | `getAttrAsString(java.lang.String name)` Gets an attribute as String.
    `java.lang.String` | `getAttrAsString(java.lang.String name, boolean inherit)` Gets the value of an attribute as String.
    `java.lang.Object` | `getAttribute(java.lang.String name)` Gets an attribute.
    `java.lang.Object` | `getAttribute(java.lang.String name, boolean inherit)` Gets the value of an attribute.
    `abstract java.util.Map<java.lang.String,java.lang.Object>` | `getAttributeMap()` Gets a map of all defined attributes.
    `java.util.Map<java.lang.String,java.lang.Object>` | `getAttributeMap(java.lang.String[] attributes)` Gets a map of a specific set of attributes.
    `java.lang.String` | `getContentText(boolean deep)` Gets only the text of this node.
    `java.lang.String` | `getContentText(boolean deep, int maxLength)` Gets only the text of this node.
    `java.util.Set<java.lang.String>` | `getDefinedAttributes(boolean deep)` Gets a Set of all defined attributes.
    `abstract java.util.List<java.lang.Object>` | `getElements()` Gets childreen of this node.
    `java.util.List<java.lang.Object>` | `getElements(java.lang.Class<?> type)` Gets all direct elements of this node that are instances of class `type`.
    `java.util.List<java.lang.Object>` | `getElements(java.lang.Class<?> type, boolean deep)` Finds all sub nodes of this node that are instance of class `type`.
    `java.util.List<Node>` | `getElements(java.lang.String name, boolean deep)` Finds all sub nodes of this node that have the given name.
    `java.lang.Object` | `getFirstElement(java.lang.Class<?> type)` Get the first direct element which is instance of class `type`
    `int` | `getIndex()`
    `java.lang.String` | `getLocalName()` Gets the local name of this node.
    `java.lang.String` | `getNamespacePrefix()` Gets the namespace prefix of this node.
    `java.util.Set<java.lang.String>` | `getNamespacePrefixes(boolean inherated)` Gets a set of all defined namespace prefixes.
    `java.lang.String` | `getNamespaceURI(java.lang.String prefix, boolean inherated)` Gets the URI of a namespace prefix.
    `Node` | `getParent()` Gets the parent of this node.
    `Node` | `getParent(java.lang.Class<?> clazz)` Gets the nearest parent node that is an instance of class `clazz`.
    `Node` | `getParent(java.lang.String qName)` Gets the nearest parent node with a specific name.
    `Node` | `getParentOrThis(java.lang.Class<?> clazz)` Equal to `getParent(Class)` but returns this node if this is already an instance of class `clazz`.
    `java.lang.String` | `getQName()` Gets the full qualified name of this node.
    `Node` | `getRoot()` Gets the root node of this node.
    `boolean` | `hasEqualAttrs(Node node)` Tests if this and given node have equal attributes (with same values).
    `int` | `indexOf(java.lang.Object child)` Gets the index of a child.
    `boolean` | `isEmpty()` Determinates if this node has no elements.
    `java.lang.Object` | `lastElement()` Gets the last element of this node.
    `void` | `liftInheritedAttribute(java.lang.String name)` Copies inherited value of attribute `name` to this node if attribute `name` is unset on this node and `name` is inherited by any parent node.
    `void` | `removeAttributeChangeListener(AttributeChangeListener l)` Removes a listener that was listener for attribute changes.
    `boolean` | `setAttribute(java.lang.String name, java.lang.Object value)` Sets the value of an attribute.
    `void` | `setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributeMap)` Sets all attributes that are contained in the map.
    `boolean` | `setAttrIfNotNull(java.lang.String name, java.lang.Object value)` Sets the value of an attribute, but only if the given value is not NULL.
    `void` | `setEnableAttributeChangeEvent(boolean enabled)` Sets, if value change events are fired, when setAttribute is called.
    `void` | `setNamespace(java.lang.String prefix, java.lang.String uri)` Sets a namespace.
    `void` | `setParent(Node parent)` Sets the parent of this node.
    `protected void` | `setQName(java.lang.String name)` Sets a new qualified node name.
    `void` | `setUndefinedAttributes(java.util.Map<java.lang.String,?> attributeMap)` Sets all attributes that are contained in the given map and that are not already defined by this node.
    `void` | `writeTo(java.io.File file)` Writes full XML-tree of this node into given file.
    `void` | `writeTo(java.io.OutputStream os)` Writes full XML-tree into give OutputStream as XML.
    `void` | `writeTo(java.lang.String file)` Writes full XML-tree of this node into given file.
    `void` | `writeTo(XMLWriter writer)` Writes this node through an XML-Writer.

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface de.vc.xml.Node

      `addElement, addElement, removeElement, removeElement, replaceElement, setElement`

- - ### Constructor Detail

    - #### AbstractNode

          public AbstractNode(java.lang.String nodeName)

      Constructs a node.
      Parameters:
        `nodeName` - XML-tag.

    - #### AbstractNode

          protected AbstractNode(java.lang.String nodeName,
                      Node parent)

      Constructs a node.
      Parameters:
        `nodeName` - XML-tag.
        `parent` - Parent node.

  - ### Method Detail

    - #### getElements

          public abstract java.util.List<java.lang.Object> getElements()

      Gets childreen of this node. A child is typical an instance of `NodeElement` or `String`.
      Specified by:
        `getElements` in interface `Node`
      Returns:
        Childreen.

    - #### addElements

          public void addElements(java.util.Collection<?> elements)

      Adds some NodeElements to this FormattingObject. You must ensure, that this FormattingObject can contain given elements.
      Parameters:
        `elements` - Collection of elements.

    - #### addElements

          public void addElements(java.lang.Object[] elements)

      Adds some NodeElements to this FormattingObject. You must ensure, that this FormattingObject can contain given elements.
      Parameters:
        `elements` - Collection of elements.

    - #### getAttributeMap

          public abstract java.util.Map<java.lang.String,java.lang.Object> getAttributeMap()

      Gets a map of all defined attributes.
      Specified by:
        `getAttributeMap` in interface `Node`
      Returns:
        Map of attributes.

    - #### getAttributeMap

          public java.util.Map<java.lang.String,java.lang.Object> getAttributeMap(java.lang.String[] attributes)

      Gets a map of a specific set of attributes.
      Parameters:
        `attributes` - Attributes.
      Returns:
        Map of attributes.

    - #### clone

          public java.lang.Object clone()
                                 throws java.lang.CloneNotSupportedException

      Description copied from interface: `NodeElement`
      Clones this element. Should return a deep copy!
      Specified by:
        `clone` in interface `NodeElement`
      Overrides:
        `clone` in class `java.lang.Object`
      Returns:
        Clone.
      Throws:
        `java.lang.CloneNotSupportedException`

    - #### getParent

          public Node getParent()

      Gets the parent of this node.
      Specified by:
        `getParent` in interface `NodeElement`
      Returns:
        Parent of this node or NULL if this is a root node.

    - #### getRoot

          public Node getRoot()

      Gets the root node of this node.
      Specified by:
        `getRoot` in interface `Node`
      Returns:
        Root node.

    - #### setParent

          public void setParent(Node parent)

      Sets the parent of this node. This should be called by subclasses when adding new children.
      Specified by:
        `setParent` in interface `NodeElement`
      Parameters:
        `parent` - Parent of this node.

    - #### writeTo

          public void writeTo(XMLWriter writer)

      Writes this node through an XML-Writer.
      Specified by:
        `writeTo` in interface `NodeElement`
      Parameters:
        `writer` - Writer.

    - #### addAttributeChangeListener

          public void addAttributeChangeListener(AttributeChangeListener l)

      Adds an listener that is notified when an attribute was changed.
      Specified by:
        `addAttributeChangeListener` in interface `Node`
      Parameters:
        `l` - Listener.

    - #### removeAttributeChangeListener

          public void removeAttributeChangeListener(AttributeChangeListener l)

      Removes a listener that was listener for attribute changes.
      Specified by:
        `removeAttributeChangeListener` in interface `Node`
      Parameters:
        `l` - Listener.

    - #### getQName

          public java.lang.String getQName()

      Gets the full qualified name of this node. Qualified name means name with namespace prefix.
      Specified by:
        `getQName` in interface `Node`
      Returns:
        Name of this node.

    - #### getLocalName

          public java.lang.String getLocalName()

      Gets the local name of this node. Local name means name without namespace prefix.
      Specified by:
        `getLocalName` in interface `Node`
      Returns:
        Local name of this node.

    - #### getParent

          public Node getParent(java.lang.String qName)

      Gets the nearest parent node with a specific name.
      Parameters:
        `qName` - Qualified name of parent node.
      Returns:
        Parent (or parent of parent...) of this node that has given name.

    - #### getParent

          public Node getParent(java.lang.Class<?> clazz)

      Gets the nearest parent node that is an instance of class `clazz`.
      Parameters:
        `clazz` - Class
      Returns:
        Parent node or null.

    - #### getParentOrThis

          public Node getParentOrThis(java.lang.Class<?> clazz)

      Equal to `getParent(Class)` but returns this node if this is already an instance of class `clazz`.
      Parameters:
        `clazz` - Class
      Returns:
        Object of class `clazz` or null.

    - #### indexOf

          public int indexOf(java.lang.Object child)

      Gets the index of a child.
      Specified by:
        `indexOf` in interface `Node`
      Parameters:
        `child` - Child.
      Returns:
        index or -1, if not found.

    - #### hasEqualAttrs

          public boolean hasEqualAttrs(Node node)

      Tests if this and given node have equal attributes (with same values).
      Parameters:
        `node` - Node
      Returns:
        `true` if this and given node have equal values.

    - #### lastElement

          public java.lang.Object lastElement()

      Gets the last element of this node.
      Specified by:
        `lastElement` in interface `Node`
      Returns:
        Last element or NULL if empty.

    - #### firstElement

          public java.lang.Object firstElement()

      Gets the first element of this node.
      Specified by:
        `firstElement` in interface `Node`
      Returns:
        First element or NULL if empty.

    - #### getAttribute

          public final java.lang.Object getAttribute(java.lang.String name)

      Gets an attribute. Note, an attribute may have another type than java.lang.String, e.g. de.vc.util.Measure.
      Specified by:
        `getAttribute` in interface `Node`
      Parameters:
        `name` - Attribute name.
      Returns:
        Value.

    - #### getAttrAsString

          public final java.lang.String getAttrAsString(java.lang.String name)

      Gets an attribute as String.
      Specified by:
        `getAttrAsString` in interface `Node`
      Parameters:
        `name` - Attribute name.
      Returns:
        Value as String.

    - #### getAttrAsString

          public final java.lang.String getAttrAsString(java.lang.String name,
                                         boolean inherit)

      Gets the value of an attribute as String.
      Specified by:
        `getAttrAsString` in interface `Node`
      Parameters:
        `name` - Name of attribute.
        `inherit` - True if attribute can be defined by a parent node.
      Returns:
        Value of attribute or NULL, if not defined.

    - #### getAttrAsBoolean

          public final boolean getAttrAsBoolean(java.lang.String name,
                                 boolean inherit,
                                 boolean defValue)

      Gets an boolean attribute.
      Parameters:
        `name` - Name of attribute.
        `inherit` - Inherit attribute.
        `defValue` - Default value if attribute is unset.
      Returns:
        true if value if attribute is "true".

    - #### getAttrAsInteger

          public final int getAttrAsInteger(java.lang.String name,
                             boolean inherit,
                             int defaultValue)

    - #### getAttribute

          public final java.lang.Object getAttribute(java.lang.String name,
                                      boolean inherit)

      Gets the value of an attribute.
      Specified by:
        `getAttribute` in interface `Node`
      Parameters:
        `name` - Name of attribute.
        `inherit` - True if attribute can be defined by a parent node.
      Returns:
        Value of attribute or NULL, if not defined.

    - #### getDefinedAttributes

          public java.util.Set<java.lang.String> getDefinedAttributes(boolean deep)

      Gets a Set of all defined attributes.
      Specified by:
        `getDefinedAttributes` in interface `Node`
      Parameters:
        `deep` - true, if defined of parent nodes are included.
      Returns:
        Set of all defined attributes.

    - #### liftInheritedAttribute

          public final void liftInheritedAttribute(java.lang.String name)

      Copies inherited value of attribute `name` to this node if attribute `name` is unset on this node and `name` is inherited by any parent node. Attributes are not removed from parent nodes.
      Parameters:
        `name` - String

    - #### getContentText

          public java.lang.String getContentText(boolean deep)

      Gets only the text of this node.
      Specified by:
        `getContentText` in interface `Node`
      Parameters:
        `deep` - true to include text of sub-nodes.
      Returns:
        Text

    - #### getContentText

          public java.lang.String getContentText(boolean deep,
                                        int maxLength)

      Gets only the text of this node.
      Parameters:
        `deep` - true to include text of sub-nodes.
        `maxLength` - Max length of text.
      Returns:
        Text

    - #### getNamespacePrefixes

          public java.util.Set<java.lang.String> getNamespacePrefixes(boolean inherated)

      Gets a set of all defined namespace prefixes.
      Specified by:
        `getNamespacePrefixes` in interface `Node`
      Parameters:
        `inherated` - Get also defined namespaces of parent nodes.
      Returns:
        Set of namespace prefixes (String).

    - #### setNamespace

          public void setNamespace(java.lang.String prefix,
                          java.lang.String uri)

      Sets a namespace.
      Specified by:
        `setNamespace` in interface `Node`
      Parameters:
        `prefix` - Prefix of namespace.
        `uri` - URI of namespace.

    - #### getNamespacePrefix

          public java.lang.String getNamespacePrefix()

      Gets the namespace prefix of this node.
      Specified by:
        `getNamespacePrefix` in interface `Node`
      Returns:
        Prefix of namespace.

    - #### isEmpty

          public boolean isEmpty()

      Determinates if this node has no elements.
      Specified by:
        `isEmpty` in interface `Node`
      Returns:
        true, if this node has no elements.

    - #### clearInheratedAttributes

          public void clearInheratedAttributes()

      Clears all attributes that were defined by a parent node and have same value.
      Specified by:
        `clearInheratedAttributes` in interface `Node`

    - #### clearInheratedAttribute

          public boolean clearInheratedAttribute(java.lang.String name)

      Clears an attributed that was defined by a parent node and has same value.
      Specified by:
        `clearInheratedAttribute` in interface `Node`
      Parameters:
        `name` - Name of attribute.
      Returns:
        `true` if attribute was cleared.

    - #### clearEqualAttributes

          public void clearEqualAttributes(Node node,
                                  boolean deep)

      Clears all attributes of this node, that are defined in the given node with equal values.
      Parameters:
        `node` - Node.
        `deep` - true search deep in `node` for attributes.

    - #### contains

          public boolean contains(Node child)

      Tests if this node contains the given node directly.
      Parameters:
        `child` - Node.
      Returns:
        `true` if this node contains `child`.

    - #### contains

          public boolean contains(Node child,
                         boolean deep)

      Tests if this node contains the given node.
      Specified by:
        `contains` in interface `Node`
      Parameters:
        `child` - Node.
        `deep` - Search also in subnodes.
      Returns:
        `true` if this node contains `child`.

    - #### clearValue

          public void clearValue(java.lang.String name)

      Clears an attribute, this means they value becomes NULL.
      Specified by:
        `clearValue` in interface `Node`
      Parameters:
        `name` - Name of the attribute.

    - #### setAttribute

          public final boolean setAttribute(java.lang.String name,
                             java.lang.Object value)

      Sets the value of an attribute. A ValueChangeEvent is fired.
      Specified by:
        `setAttribute` in interface `Node`
      Parameters:
        `name` - Name of the attribute.
        `value` - New value.
      Returns:
        true, if value was setted.

    - #### setAttrIfNotNull

          public final boolean setAttrIfNotNull(java.lang.String name,
                                 java.lang.Object value)

      Sets the value of an attribute, but only if the given value is not NULL. A ValueChangeEvent is fired.
      Parameters:
        `name` - Name of the attribute.
        `value` - New value.
      Returns:
        true, if value was setted.

    - #### copyAttributes

          public void copyAttributes(Node node)

      Copies all attributes of given node to this node.
      Parameters:
        `node` - Node.

    - #### setAttributes

          public void setAttributes(java.util.Map<java.lang.String,java.lang.Object> attributeMap)

      Sets all attributes that are contained in the map.
      Specified by:
        `setAttributes` in interface `Node`
      Parameters:
        `attributeMap` - Map of attributes to values.

    - #### setUndefinedAttributes

          public void setUndefinedAttributes(java.util.Map<java.lang.String,?> attributeMap)

      Sets all attributes that are contained in the given map and that are not already defined by this node.
      Parameters:
        `attributeMap` - Map of attributes to values.

    - #### writeTo

          public void writeTo(java.io.OutputStream os)
                       throws java.io.IOException

      Writes full XML-tree into give OutputStream as XML. OutputStream is closed after writing.
      Parameters:
        `os` - OutputStream
      Throws:
        `java.io.IOException`

    - #### writeTo

          public void writeTo(java.io.File file)
                       throws java.io.IOException

      Writes full XML-tree of this node into given file.
      Parameters:
        `file` - File.
      Throws:
        `java.io.IOException`

    - #### writeTo

          public void writeTo(java.lang.String file)
                       throws java.io.IOException

      Writes full XML-tree of this node into given file.
      Parameters:
        `file` - File.
      Throws:
        `java.io.IOException`

    - #### setEnableAttributeChangeEvent

          public void setEnableAttributeChangeEvent(boolean enabled)

      Sets, if value change events are fired, when setAttribute is called. By default this is true. You can disable these event, but it may cause strange side effects.
      Parameters:
        `enabled` - true, if ValueChangeEvents are fired.

    - #### findNode

          public Node findNode(java.lang.String nodeName,
                      java.lang.String attrName,
                      java.lang.String attrValue)

      Searches for a node with a specific attribute in this node.
      Parameters:
        `nodeName` - Name of node.
        `attrName` - Name of attribute.
        `attrValue` - Value of attribute.
      Returns:
        Node that has given name and attribute with value.

    - #### getElements

          public java.util.List<java.lang.Object> getElements(java.lang.Class<?> type)

      Gets all direct elements of this node that are instances of class `type`.
      Parameters:
        `type` - Type.
      Returns:
        List of elements.

    - #### getElements

          public java.util.List<java.lang.Object> getElements(java.lang.Class<?> type,
                                                     boolean deep)

      Finds all sub nodes of this node that are instance of class `type`.
      Parameters:
        `type` - Type.
        `deep` - true, if deep search.
      Returns:
        Nodes that has given name.

    - #### getFirstElement

          public java.lang.Object getFirstElement(java.lang.Class<?> type)

      Get the first direct element which is instance of class `type`
      Parameters:
        `type` - Type.
      Returns:
        Node or null

    - #### getElements

          public java.util.List<Node> getElements(java.lang.String name,
                                         boolean deep)

      Finds all sub nodes of this node that have the given name.
      Specified by:
        `getElements` in interface `Node`
      Parameters:
        `name` - Tag of sub-node.
        `deep` - true, if deep search.
      Returns:
        Nodes that has given name.

    - #### fireSaxEvents

          public void fireSaxEvents(org.xml.sax.ContentHandler handler)
                             throws org.xml.sax.SAXException

      Fires SAX events to a SAX content handler.
      Specified by:
        `fireSaxEvents` in interface `Node`
      Parameters:
        `handler` - Content handler.
      Throws:
        `org.xml.sax.SAXException`

    - #### findNodesWithText

          public java.util.List<Node> findNodesWithText(java.lang.String text,
                                               boolean deep)

      Finds all elements that contains a specific text. If a node contains the text multiple times then this node is also listed multiple times in the result list.
      Parameters:
        `text` - Text to search.
        `deep` - Deep search.
      Returns:
        Set Elements with text.

    - #### findFirstNodeWithText

          public Node findFirstNodeWithText(java.lang.String text,
                                   boolean deep)

    - #### getIndex

          public int getIndex()

    - #### doSetAttribute

          protected abstract boolean doSetAttribute(java.lang.String name,
                               java.lang.Object value)

      Do implement this Method. A ValueChangeEvent is fired after setting new value (if enabled).
      Parameters:
        `name` - Name of attribute, always lower case.
        `value` - New value.
      Returns:
        true, if value was successfully setted.

    - #### doGetAttribute

          protected abstract java.lang.Object doGetAttribute(java.lang.String name)

      Do implement this Method.
      Parameters:
        `name` - Name of attribute, always lower case.
      Returns:
        Value.

    - #### fire

          protected void fire(ValueChangeEvent evt)

      Fire a ValueChangeEvent. You should fire a ValueChangeEvent, if you not set a value via setAttribute.
      Parameters:
        `evt` - ValueChangeEvent.

    - #### createID

          protected static final long createID()

      Creates a unique ID for a node.
      Returns:
        ID.

    - #### setQName

          protected final void setQName(java.lang.String name)

      Sets a new qualified node name.
      Parameters:
        `name` - New name of node.

    - #### getNamespaceURI

          public java.lang.String getNamespaceURI(java.lang.String prefix,
                                         boolean inherated)

      Gets the URI of a namespace prefix.
      Specified by:
        `getNamespaceURI` in interface `Node`
      Parameters:
        `prefix` - Prefix of namespace.
        `inherated` - Regard also namespace definitions of parent nodes.
      Returns:
        URI of namespace or NULL if not defined.

© 2003-2011 by Sascha Schmidt (vision-cloud.de). All Rights Reserved.