org.vectomatic.dom.svg
Class OMNode

java.lang.Object
  extended by org.vectomatic.dom.svg.OMNode
All Implemented Interfaces:
com.google.gwt.event.shared.HasHandlers
Direct Known Subclasses:
OMAttr, OMDocument, OMElement, OMText

public class OMNode
extends Object
implements com.google.gwt.event.shared.HasHandlers

Wrapper class for DOM Node. Wrapper classes decorate native DOM objects with java-like capabilities: capability to implement interfaces, notably event handler interfaces.

Author:
laaglu, Michael Allan

Field Summary
protected static com.google.gwt.event.shared.EventBus eventBus
          The event bus shared by all SVG objects
protected  com.google.gwt.dom.client.Node ot
          The DOM native overlay type wrapped by this object
 
Constructor Summary
protected OMNode(com.google.gwt.dom.client.Node node)
          Constructor
 
Method Summary
<H extends com.google.gwt.event.shared.EventHandler>
com.google.gwt.event.shared.HandlerRegistration
addDomHandler(H handler, com.google.gwt.event.dom.client.DomEvent.Type<H> type)
          Adds a DOM handler to this node's list of handlers
<H extends com.google.gwt.event.shared.EventHandler>
com.google.gwt.event.shared.HandlerRegistration
addHandler(H handler, com.google.gwt.event.shared.GwtEvent.Type<H> type)
          Adds a handler to this node's list of handlers
 OMNode appendChild(OMNode newChild)
          Adds the node newChild to the end of the list of children of this node.
 void cleanup()
          Cleanup method for wrapper objects which are not needed by the application any more.
 OMNode cloneNode(boolean deep)
          Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes.
static
<T extends OMNode>
T
convert(com.google.gwt.dom.client.Node obj)
          Returns the wrapper for the specified overlay type node, automatically constructing a new wrapper if the node was previously unwrapped.
static
<T extends Iterable<? extends OMNode>>
T
convertList(com.google.gwt.core.client.JavaScriptObject obj)
          Generates a wrapper around an overlay type list
 void dispatch(com.google.gwt.dom.client.NativeEvent event)
          Dispatches the specified event to this node event handlers
 void fireEvent(com.google.gwt.event.shared.GwtEvent<?> event)
          Fires the given event to the handlers listening to the event's type.
<T extends OMNode>
OMNodeList<T>
getChildNodes()
          A OMNodeList that contains all children of this node.
static com.google.gwt.event.shared.EventBus getEventBus()
          Returns the event bus shared by all SVG objects
 OMNode getFirstChild()
          The first child of this node.
 OMNode getLastChild()
          The last child of this node.
 String getLocalName()
          Returns the local part of the qualified name of this node.
 String getNamespaceURI()
          The namespace URI of the specified node, or null if it is unspecified (see ).
 OMNode getNextSibling()
          The node immediately following this node.
 com.google.gwt.dom.client.Node getNode()
          Returns the wrapped node
 String getNodeName()
          The name of this node, depending on its type.
 short getNodeType()
          A code representing the type of the underlying object.
 String getNodeValue()
          The value of this node, depending on its type.
 OMDocument getOwnerDocument()
          The OMDocument object associated with this node.
 OMNode getParentNode()
          The parent of this node.
 OMNode getPreviousSibling()
          The node immediately preceding this node.
 boolean hasChildNodes()
          Returns whether this node has any children.
 OMNode insertBefore(OMNode newChild, OMNode refChild)
          Inserts the node newChild before the existing child node refChild.
 void normalize()
          Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes.
 OMNode removeChild(OMNode oldChild)
          Removes the child node indicated by oldChild from the list of children, and returns it.
 OMNode replaceChild(OMNode newChild, OMNode oldChild)
          Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.
 void setNodeValue(String value)
          The value of this node, depending on its type; see the table above.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ot

protected final com.google.gwt.dom.client.Node ot
The DOM native overlay type wrapped by this object


eventBus

protected static com.google.gwt.event.shared.EventBus eventBus
The event bus shared by all SVG objects

Constructor Detail

OMNode

protected OMNode(com.google.gwt.dom.client.Node node)
Constructor

Parameters:
node - The node to wrap
Method Detail

cleanup

public void cleanup()
Cleanup method for wrapper objects which are not needed by the application any more. It breaks the back-reference the native DOM object maintains on this wrapper type, in order to facilitate garbage collection. Use only if your code needs to run in a browser which is not equipped with an automatic DOM object-native object cycle collector.


getEventBus

public static com.google.gwt.event.shared.EventBus getEventBus()
Returns the event bus shared by all SVG objects

Returns:
the event bus shared by all SVG objects

fireEvent

public void fireEvent(com.google.gwt.event.shared.GwtEvent<?> event)
Fires the given event to the handlers listening to the event's type.

Any exceptions thrown by handlers will be bundled into a UmbrellaException and then re-thrown after all handlers have completed. An exception thrown by a handler will not prevent other handlers from executing.

Specified by:
fireEvent in interface com.google.gwt.event.shared.HasHandlers
Parameters:
event - the event

dispatch

public void dispatch(com.google.gwt.dom.client.NativeEvent event)
Dispatches the specified event to this node event handlers

Parameters:
event - The event to dispatch

addDomHandler

public final <H extends com.google.gwt.event.shared.EventHandler> com.google.gwt.event.shared.HandlerRegistration addDomHandler(H handler,
                                                                                                                                com.google.gwt.event.dom.client.DomEvent.Type<H> type)
Adds a DOM handler to this node's list of handlers

Type Parameters:
H - The handler type
Parameters:
handler - The DOM handler
type - The event type
Returns:
HandlerRegistration used to remove this handler

addHandler

public final <H extends com.google.gwt.event.shared.EventHandler> com.google.gwt.event.shared.HandlerRegistration addHandler(H handler,
                                                                                                                             com.google.gwt.event.shared.GwtEvent.Type<H> type)
Adds a handler to this node's list of handlers

Type Parameters:
H - The handler type
Parameters:
handler - The handler
type - The event type
Returns:
HandlerRegistration used to remove this handler

convert

public static <T extends OMNode> T convert(com.google.gwt.dom.client.Node obj)
Returns the wrapper for the specified overlay type node, automatically constructing a new wrapper if the node was previously unwrapped.

Type Parameters:
T - the node type
Parameters:
obj - The overlay type node
Returns:
The node wrapper

convertList

public static <T extends Iterable<? extends OMNode>> T convertList(com.google.gwt.core.client.JavaScriptObject obj)
Generates a wrapper around an overlay type list

Type Parameters:
T - the list type
Parameters:
obj - The overlay type list
Returns:
The list wrapper

getNode

public com.google.gwt.dom.client.Node getNode()
Returns the wrapped node

Returns:
the wrapped node

getNodeName

public final String getNodeName()
The name of this node, depending on its type.

Returns:
name of this node

getNodeValue

public final String getNodeValue()
The value of this node, depending on its type. When it is defined to be null, setting it has no effect, including if the node is read-only.


setNodeValue

public final void setNodeValue(String value)
                        throws com.google.gwt.core.client.JavaScriptException
The value of this node, depending on its type; see the table above. When it is defined to be null, setting it has no effect, including if the node is read-only.

Parameters:
value - The node value
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly and if it is not defined to be null.
com.google.gwt.core.client.JavaScriptException

getNodeType

public final short getNodeType()
A code representing the type of the underlying object.

Returns:
A code representing the type of the underlying object

getParentNode

public final OMNode getParentNode()
The parent of this node. All nodes, except OMAttr, OMDocument may have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null.

Returns:
The parent of this node

getChildNodes

public final <T extends OMNode> OMNodeList<T> getChildNodes()
A OMNodeList that contains all children of this node. If there are no children, this is a OMNodeList containing no nodes.

Returns:
A OMNodeList that contains all children of this node. If

getFirstChild

public final OMNode getFirstChild()
The first child of this node. If there is no such node, this returns null.

Returns:
The first child of this node.

getLastChild

public final OMNode getLastChild()
The last child of this node. If there is no such node, this returns null.

Returns:
The last child of this node.

getLocalName

public final String getLocalName()
Returns the local part of the qualified name of this node.
For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as Document.createElement(), this is always null.

Returns:
The local part of the qualified name of this node

getPreviousSibling

public final OMNode getPreviousSibling()
The node immediately preceding this node. If there is no such node, this returns null.

Returns:
The node immediately preceding this node.

getNamespaceURI

public String getNamespaceURI()
The namespace URI of the specified node, or null if it is unspecified (see ).
This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time.
For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and nodes created with a DOM Level 1 method, such as Document.createElement(), this is always null.

Note: Per the Namespaces in XML Specification [XML Namespaces] an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it simply has no namespace.

Returns:
The namespace URI of this node

getNextSibling

public final OMNode getNextSibling()
The node immediately following this node. If there is no such node, this returns null.

Returns:
The node immediately following this node.

getOwnerDocument

public final OMDocument getOwnerDocument()
The OMDocument object associated with this node. This is also the OMDocument object used to create new nodes. When this node is a OMNode which is not used with any OMDocument yet, this is null.

Returns:
The OMDocument object associated with this node.

insertBefore

public final OMNode insertBefore(OMNode newChild,
                                 OMNode refChild)
                          throws com.google.gwt.core.client.JavaScriptException
Inserts the node newChild before the existing child node refChild. If refChild is null, insert newChild at the end of the list of children.
If newChild is a DocumentFragment object, all of its children are inserted, in the same order, before refChild. If the newChild is already in the tree, it is first removed.

Note: Inserting a node before itself is implementation dependent.

Parameters:
newChild - The node to insert.
refChild - The reference node, i.e., the node before which the new node must be inserted.
Returns:
The node being inserted.
Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to insert is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to insert a second DocumentType or Element node.
WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or if the parent of the node being inserted is readonly.
NOT_FOUND_ERR: Raised if refChild is not a child of this node.
NOT_SUPPORTED_ERR: if this node is of type Document, this exception might be raised if the DOM implementation doesn't support the insertion of a DocumentType or Element node.
com.google.gwt.core.client.JavaScriptException

replaceChild

public final OMNode replaceChild(OMNode newChild,
                                 OMNode oldChild)
                          throws com.google.gwt.core.client.JavaScriptException
Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.
If newChild is a DocumentFragment object, oldChild is replaced by all of the DocumentFragment children, which are inserted in the same order. If the newChild is already in the tree, it is first removed.

Note: Replacing a node with itself is implementation dependent.

Parameters:
newChild - The new node to put in the child list.
oldChild - The node being replaced in the list.
Returns:
The node replaced.
Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to put in is one of this node's ancestors or this node itself, or if this node is of type Document and the result of the replacement operation would add a second DocumentType or Element on the Document node.
WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of the new node is readonly.
NOT_FOUND_ERR: Raised if oldChild is not a child of this node.
NOT_SUPPORTED_ERR: if this node is of type Document, this exception might be raised if the DOM implementation doesn't support the replacement of the DocumentType child or Element child.
com.google.gwt.core.client.JavaScriptException

removeChild

public final OMNode removeChild(OMNode oldChild)
                         throws com.google.gwt.core.client.JavaScriptException
Removes the child node indicated by oldChild from the list of children, and returns it.

Parameters:
oldChild - The node being removed.
Returns:
The node removed.
Throws:
DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised if oldChild is not a child of this node.
NOT_SUPPORTED_ERR: if this node is of type Document, this exception might be raised if the DOM implementation doesn't support the removal of the DocumentType child or the Element child.
com.google.gwt.core.client.JavaScriptException

appendChild

public final OMNode appendChild(OMNode newChild)
                         throws com.google.gwt.core.client.JavaScriptException
Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.

Parameters:
newChild - The node to add.If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node
Returns:
The node added.
Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to append is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to append a second DocumentType or Element node.
WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or if the previous parent of the node being inserted is readonly.
NOT_SUPPORTED_ERR: if the newChild node is a child of the Document node, this exception might be raised if the DOM implementation doesn't support the removal of the DocumentType child or Element child.
com.google.gwt.core.client.JavaScriptException

hasChildNodes

public final boolean hasChildNodes()
Returns whether this node has any children.

Returns:
Returns true if this node has any children, false otherwise.

cloneNode

public final OMNode cloneNode(boolean deep)
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent ( parentNode is null) and no user data. User data associated to the imported node is not carried over. However, if any UserDataHandlers has been specified along with the associated data these handlers will be called with the appropriate parameters before this method returns.
Cloning an Element copies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any children it contains unless it is a deep clone. This includes text contained in an the Element since the text is contained in a child Text node. Cloning an Attr directly, as opposed to be cloned as part of an Element cloning operation, returns a specified attribute (specified is true). Cloning an Attr always clones its children, since they represent its value, no matter whether this is a deep clone or not. Cloning an EntityReference automatically constructs its subtree if a corresponding Entity is available, no matter whether this is a deep clone or not. Cloning any other type of node simply returns a copy of this node.
Note that cloning an immutable subtree results in a mutable copy, but the children of an EntityReference clone are readonly . In addition, clones of unspecified Attr nodes are specified. And, cloning Document, DocumentType, Entity, and Notation nodes is implementation dependent.

Parameters:
deep - If true, recursively clone the subtree under the specified node; if false, clone only the node itself (and its attributes, if it is an Element).
Returns:
The duplicate node.

normalize

public final void normalize()
Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded, and is useful when operations (such as XPointer [XPointer] lookups) that depend on a particular document tree structure are to be used. If the parameter "normalize-characters" of the DOMConfiguration object attached to the Node.ownerDocument is true, this method will also fully normalize the characters of the Text nodes.

Note: In cases where the document contains CDATASections, the normalize operation alone may not be sufficient, since XPointers do not differentiate between Text nodes and CDATASection nodes.


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012. All Rights Reserved.