|
BEA Systems, Inc. | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--weblogic.apache.xerces.dom.NodeImpl | +--weblogic.apache.xerces.dom.ParentNode | +--weblogic.apache.xerces.dom.DocumentImpl
The Document interface represents the entire HTML or XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of a Document, the Document interface also contains the factory methods needed to create these objects. The Node objects created have a ownerDocument attribute which associates them with the Document within whose context they were created.
The DocumentImpl class also implements the DOM Level 2 DocumentTraversal interface. This interface is comprised of factory methods needed to create NodeIterators and TreeWalkers. The process of creating NodeIterator objects also adds these references to this document. After finishing with an iterator it is important to remove the object using the remove methods in this implementation. This allows the release of the references from the iterator objects to the DOM Nodes.
Note: When any node in the document is serialized, the entire document is serialized along with it.
This class is based on an implementation from the Apache XML Project. In future releases the XML parser, XSLT processor, and associated classes will likely be updated to be based on a later version of the Apache implementations. Since Apache does not guarantee backwards compatibility between versions of their software, we cannot guarantee backwards compatibility of any of the classes contained in the weblogic.apache package or sub-packages.
Field Summary | |
protected boolean |
allowGrammarAccess
Allow grammar access. |
protected int |
changes
Number of alterations made to this document since its creation. |
protected ElementImpl |
docElement
Document element. |
protected DocumentTypeImpl |
docType
Document type. |
protected boolean |
errorChecking
Bypass error checking. |
protected java.util.Hashtable |
eventListeners
Table for event listeners registered to this document nodes. |
protected java.util.Hashtable |
identifiers
Identifiers. |
protected java.util.Vector |
iterators
Iterators |
protected static int[] |
kidOK
Table for quick check of child insertion. |
protected boolean |
mutationEvents
Bypass mutation events firing. |
protected java.util.Vector |
ranges
Ranges |
protected java.util.Hashtable |
userData
Table for user data attached to this document nodes. |
Fields inherited from class weblogic.apache.xerces.dom.ParentNode |
firstChild,
nodeListIndex,
nodeListLength,
nodeListNode,
ownerDocument |
Fields inherited from class weblogic.apache.xerces.dom.NodeImpl |
ELEMENT_DEFINITION_NODE,
FIRSTCHILD,
flags,
IGNORABLEWS,
MUTATION_AGGREGATE,
MUTATION_ALL,
MUTATION_LOCAL,
MUTATION_NONE,
MUTATIONEVENTS,
OWNED,
ownerNode,
READONLY,
SETVALUE,
SPECIFIED,
SYNCCHILDREN,
SYNCDATA |
Constructor Summary | |
DocumentImpl()
NON-DOM: Actually creating a Document is outside the DOM's spec, since it has to operate in terms of a particular implementation. |
|
DocumentImpl(boolean grammarAccess)
Experimental constructor. |
|
DocumentImpl(org.w3c.dom.DocumentType doctype)
|
|
DocumentImpl(org.w3c.dom.DocumentType doctype,
boolean grammarAccess)
Experimental constructor. |
Method Summary | |
void |
adoptNode(org.w3c.dom.Node source)
NON-DOM: Change the node's ownerDocument, and its subtree, to this Document |
protected void |
changed()
Denotes that this node has changed. |
protected int |
changes()
Returns the number of changes to this node. |
java.lang.Object |
clone()
Clone. |
org.w3c.dom.Node |
cloneNode(boolean deep)
Deep-clone a document, including fixing ownerDoc for the cloned children. |
org.w3c.dom.Attr |
createAttribute(java.lang.String name)
Factory method; creates an Attribute having this Document as its OwnerDoc. |
org.w3c.dom.Attr |
createAttributeNS(java.lang.String namespaceURI,
java.lang.String qualifiedName)
Introduced in DOM Level 2. |
org.w3c.dom.CDATASection |
createCDATASection(java.lang.String data)
Factory method; creates a CDATASection having this Document as its OwnerDoc. |
org.w3c.dom.Comment |
createComment(java.lang.String data)
Factory method; creates a Comment having this Document as its OwnerDoc. |
org.w3c.dom.DocumentFragment |
createDocumentFragment()
Factory method; creates a DocumentFragment having this Document as its OwnerDoc. |
org.w3c.dom.DocumentType |
createDocumentType(java.lang.String qualifiedName,
java.lang.String publicID,
java.lang.String systemID)
NON-DOM Factory method; creates a DocumentType having this Document as its OwnerDoc. |
org.w3c.dom.Element |
createElement(java.lang.String tagName)
Factory method; creates an Element having this Document as its OwnerDoc. |
ElementDefinitionImpl |
createElementDefinition(java.lang.String name)
NON-DOM Factory method: creates an element definition. |
org.w3c.dom.Element |
createElementNS(java.lang.String namespaceURI,
java.lang.String qualifiedName)
Introduced in DOM Level 2. |
org.w3c.dom.Entity |
createEntity(java.lang.String name)
NON-DOM Factory method; creates an Entity having this Document as its OwnerDoc. |
org.w3c.dom.EntityReference |
createEntityReference(java.lang.String name)
Factory method; creates an EntityReference having this Document as its OwnerDoc. |
org.w3c.dom.events.Event |
createEvent(java.lang.String type)
Introduced in DOM Level 2. |
org.w3c.dom.traversal.NodeIterator |
createNodeIterator(org.w3c.dom.Node root,
int whatToShow,
org.w3c.dom.traversal.NodeFilter filter,
boolean entityReferenceExpansion)
Create and return a NodeIterator. |
org.w3c.dom.traversal.NodeIterator |
createNodeIterator(org.w3c.dom.Node root,
short whatToShow,
org.w3c.dom.traversal.NodeFilter filter)
NON-DOM extension: Create and return a NodeIterator. |
org.w3c.dom.Notation |
createNotation(java.lang.String name)
NON-DOM Factory method; creates a Notation having this Document as its OwnerDoc. |
org.w3c.dom.ProcessingInstruction |
createProcessingInstruction(java.lang.String target,
java.lang.String data)
Factory method; creates a ProcessingInstruction having this Document as its OwnerDoc. |
org.w3c.dom.range.Range |
createRange()
|
org.w3c.dom.Text |
createTextNode(java.lang.String data)
Factory method; creates a Text node having this Document as its OwnerDoc. |
org.w3c.dom.traversal.TreeWalker |
createTreeWalker(org.w3c.dom.Node root,
int whatToShow,
org.w3c.dom.traversal.NodeFilter filter,
boolean entityReferenceExpansion)
Create and return a TreeWalker. |
org.w3c.dom.traversal.TreeWalker |
createTreeWalker(org.w3c.dom.Node root,
short whatToShow,
org.w3c.dom.traversal.NodeFilter filter)
NON-DOM extension: Create and return a TreeWalker. |
org.w3c.dom.DocumentType |
getDoctype()
For XML, this provides access to the Document Type Definition. |
org.w3c.dom.Element |
getDocumentElement()
Convenience method, allowing direct access to the child node which is considered the root of the actual document content. |
org.w3c.dom.Element |
getElementById(java.lang.String elementId)
Introduced in DOM Level 2 Returns the Element whose ID is given by elementId. |
org.w3c.dom.NodeList |
getElementsByTagName(java.lang.String tagname)
Return a live collection of all descendent Elements (not just immediate children) having the specified tag name. |
org.w3c.dom.NodeList |
getElementsByTagNameNS(java.lang.String namespaceURI,
java.lang.String localName)
Introduced in DOM Level 2. |
boolean |
getErrorChecking()
Returns true if the DOM implementation performs error checking. |
protected java.util.Vector |
getEventListeners(NodeImpl n)
Retreive event listener registered on a given node |
org.w3c.dom.Element |
getIdentifier(java.lang.String idName)
Returns a previously registered element with the specified identifier name, or null if no element is registered. |
java.util.Enumeration |
getIdentifiers()
Returns an enumeration registered of identifier names. |
org.w3c.dom.DOMImplementation |
getImplementation()
Retrieve information describing the abilities of this particular DOM implementation. |
boolean |
getMutationEvents()
Returns true if the DOM implementation generates mutation events. |
java.lang.String |
getNodeName()
Returns the node name. |
short |
getNodeType()
Returns the node type. |
org.w3c.dom.Document |
getOwnerDocument()
|
protected java.lang.Object |
getUserData(NodeImpl n)
Retreive user data related to a given node |
org.w3c.dom.Node |
importNode(org.w3c.dom.Node source,
boolean deep)
Copies data from the source node. |
org.w3c.dom.Node |
insertBefore(org.w3c.dom.Node newChild,
org.w3c.dom.Node refChild)
Since a Document may contain at most one top-level Element child, and at most one DocumentType declaraction, we need to subclass our add-children methods to implement this constraint. |
protected boolean |
isKidOK(org.w3c.dom.Node parent,
org.w3c.dom.Node child)
Uses the kidOK lookup table to check whether the proposed tree structure is legal. |
static boolean |
isXMLName(java.lang.String s)
Check the string against XML's definition of acceptable names for elements and attributes and so on. |
void |
putIdentifier(java.lang.String idName,
org.w3c.dom.Element element)
Registers an identifier name with a specified element node. |
org.w3c.dom.Node |
removeChild(org.w3c.dom.Node oldChild)
Since insertBefore caches the docElement (and, currently, docType), removeChild has to know how to undo the cache REVISIT: According to the spec it is not allowed to alter neither the document element nor the document type in any way |
void |
removeIdentifier(java.lang.String idName)
Removes a previously registered element with the specified identifier name. |
org.w3c.dom.Node |
replaceChild(org.w3c.dom.Node newChild,
org.w3c.dom.Node oldChild)
Since we cache the docElement (and, currently, docType), replaceChild has to update the cache REVISIT: According to the spec it is not allowed to alter neither the document element nor the document type in any way |
void |
setErrorChecking(boolean check)
Sets whether the DOM implementation performs error checking upon operations. |
protected void |
setEventListeners(NodeImpl n,
java.util.Vector listeners)
Store event listener registered on a given node This is another place where we could use weak references! Indeed, the node here won't be GC'ed as long as some listener is registered on it, since the eventsListeners table will have a reference to the node. |
void |
setMutationEvents(boolean set)
Sets whether the DOM implementation generates mutation events upon operations. |
protected void |
setUserData(NodeImpl n,
java.lang.Object data)
Store user data related to a given node This is a place where we could use weak references! Indeed, the node here won't be GC'ed as long as some user data is attached to it, since the userData table will have a reference to the node. |
Methods inherited from class weblogic.apache.xerces.dom.ParentNode |
getChildNodes,
getFirstChild,
getLastChild,
getLength,
hasChildNodes,
item,
normalize,
setReadOnly,
synchronizeChildren,
synchronizeChildren |
Methods inherited from class weblogic.apache.xerces.dom.NodeImpl |
addEventListener,
appendChild,
dispatchEvent,
getAttributes,
getLocalName,
getNamespaceURI,
getNextSibling,
getNodeValue,
getParentNode,
getPrefix,
getPreviousSibling,
getReadOnly,
getUserData,
hasAttributes,
removeEventListener,
setNodeValue,
setPrefix,
setUserData,
supports,
synchronizeData,
toString |
Methods inherited from class java.lang.Object |
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected DocumentTypeImpl docType
protected ElementImpl docElement
protected java.util.Hashtable identifiers
protected java.util.Vector iterators
protected java.util.Vector ranges
protected static int[] kidOK
protected java.util.Hashtable userData
protected java.util.Hashtable eventListeners
protected int changes
Any method that alters the tree structure MUST cause or be accompanied by a call to changed(), to inform it that any outstanding NodeLists may have to be updated.
(Required because NodeList is simultaneously "live" and integer- indexed -- a bad decision in the DOM's design.)
Note that changes which do not affect the tree's structure -- changing the node's name, for example -- do _not_ have to call changed().
Alternative implementation would be to use a cryptographic Digest value rather than a count. This would have the advantage that "harmless" changes (those producing equal() trees) would not force NodeList to resynchronize. Disadvantage is that it's slightly more prone to "false negatives", though that's the difference between "wildly unlikely" and "absurdly unlikely". IF we start maintaining digests, we should consider taking advantage of them. Note: This used to be done a node basis, so that we knew what subtree changed. But since only DeepNodeList really use this today, the gain appears to be really small compared to the cost of having an int on every (parent) node plus having to walk up the tree all the way to the root to mark the branch as changed everytime a node is changed. So we now have a single counter global to the document. It means that some objects may flush their cache more often than necessary, but this makes nodes smaller and only the document needs to be marked as changed.
protected boolean allowGrammarAccess
protected boolean errorChecking
protected boolean mutationEvents
Constructor Detail |
public DocumentImpl()
public DocumentImpl(boolean grammarAccess)
public DocumentImpl(org.w3c.dom.DocumentType doctype)
public DocumentImpl(org.w3c.dom.DocumentType doctype, boolean grammarAccess)
Method Detail |
public final org.w3c.dom.Document getOwnerDocument()
public short getNodeType()
public java.lang.String getNodeName()
public org.w3c.dom.Node cloneNode(boolean deep)
deep
- boolean, iff true replicate childrenpublic org.w3c.dom.Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) throws org.w3c.dom.DOMException
While I'm doing so, I've taken advantage of the opportunity to cache documentElement and docType so we don't have to search for them. REVISIT: According to the spec it is not allowed to alter neither the document element nor the document type in any way
public org.w3c.dom.Node removeChild(org.w3c.dom.Node oldChild) throws org.w3c.dom.DOMException
public org.w3c.dom.Node replaceChild(org.w3c.dom.Node newChild, org.w3c.dom.Node oldChild) throws org.w3c.dom.DOMException
public org.w3c.dom.Attr createAttribute(java.lang.String name) throws org.w3c.dom.DOMException
name
- The name of the attribute. Note that the attribute's value
is _not_ established at the factory; remember to set it!public org.w3c.dom.CDATASection createCDATASection(java.lang.String data) throws org.w3c.dom.DOMException
data
- The initial contents of the CDATApublic org.w3c.dom.Comment createComment(java.lang.String data)
data
- The initial contents of the Comment.public org.w3c.dom.DocumentFragment createDocumentFragment()
public org.w3c.dom.Element createElement(java.lang.String tagName) throws org.w3c.dom.DOMException
tagName
- The name of the element type to instantiate. For
XML, this is case-sensitive. For HTML, the tagName parameter may
be provided in any case, but it must be mapped to the canonical
uppercase form by the DOM implementation.public org.w3c.dom.EntityReference createEntityReference(java.lang.String name) throws org.w3c.dom.DOMException
name
- The name of the Entity we wish to refer topublic org.w3c.dom.ProcessingInstruction createProcessingInstruction(java.lang.String target, java.lang.String data) throws org.w3c.dom.DOMException
target
- The target "processor channel"data
- Parameter string to be passed to the target.public org.w3c.dom.Text createTextNode(java.lang.String data)
data
- The initial contents of the Text.public org.w3c.dom.DocumentType getDoctype()
public org.w3c.dom.Element getDocumentElement()
public org.w3c.dom.NodeList getElementsByTagName(java.lang.String tagname)
tagname
- The type of Element we want to gather. "*" will be
taken as a wildcard, meaning "all elements in the document."DeepNodeListImpl
public org.w3c.dom.DOMImplementation getImplementation()
public void setErrorChecking(boolean check)
Turning off error checking does not turn off the following checks:
public boolean getErrorChecking()
public void setMutationEvents(boolean set)
public boolean getMutationEvents()
public org.w3c.dom.DocumentType createDocumentType(java.lang.String qualifiedName, java.lang.String publicID, java.lang.String systemID) throws org.w3c.dom.DOMException
name
- The name of the Entity we wish to provide a value for.public org.w3c.dom.Entity createEntity(java.lang.String name) throws org.w3c.dom.DOMException
name
- The name of the Entity we wish to provide a value for.public org.w3c.dom.Notation createNotation(java.lang.String name) throws org.w3c.dom.DOMException
name
- The name of the Notation we wish to describepublic ElementDefinitionImpl createElementDefinition(java.lang.String name) throws org.w3c.dom.DOMException
public org.w3c.dom.Node importNode(org.w3c.dom.Node source, boolean deep) throws org.w3c.dom.DOMException
public void adoptNode(org.w3c.dom.Node source)
source
- The node to move in to this document.DocumentImpl.importNode
public org.w3c.dom.Element getElementById(java.lang.String elementId)
Note: The DOM implementation must have information that says which attributes are of type ID. Attributes with the name "ID" are not of type ID unless so defined. Implementations that do not know whether attributes are of type ID or not are expected to return null.
getIdentifier(java.lang.String)
public void putIdentifier(java.lang.String idName, org.w3c.dom.Element element)
getIdentifier(java.lang.String)
,
removeIdentifier(java.lang.String)
public org.w3c.dom.Element getIdentifier(java.lang.String idName)
putIdentifier(java.lang.String, org.w3c.dom.Element)
,
removeIdentifier(java.lang.String)
public void removeIdentifier(java.lang.String idName)
putIdentifier(java.lang.String, org.w3c.dom.Element)
,
getIdentifier(java.lang.String)
public java.util.Enumeration getIdentifiers()
public org.w3c.dom.Element createElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName) throws org.w3c.dom.DOMException
Creates an element of the given qualified name and namespace URI. If the given namespaceURI is null or an empty string and the qualifiedName has a prefix that is "xml", the created element is bound to the predefined namespace "http://www.w3.org/XML/1998/namespace" [Namespaces].
namespaceURI
- The namespace URI of the element to
create.qualifiedName
- The qualified name of the element type to
instantiate.public org.w3c.dom.Attr createAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName) throws org.w3c.dom.DOMException
Creates an attribute of the given qualified name and namespace URI. If the given namespaceURI is null or an empty string and the qualifiedName has a prefix that is "xml", the created element is bound to the predefined namespace "http://www.w3.org/XML/1998/namespace" [Namespaces].
namespaceURI
- The namespace URI of the attribute to
create. When it is null or an empty string,
this method behaves like createAttribute.qualifiedName
- The qualified name of the attribute to
instantiate.public org.w3c.dom.NodeList getElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)
Returns a NodeList of all the Elements with a given local name and namespace URI in the order in which they would be encountered in a preorder traversal of the Document tree.
namespaceURI
- The namespace URI of the elements to match
on. The special value "*" matches all
namespaces. When it is null or an empty
string, this method behaves like
getElementsByTagName.localName
- The local name of the elements to match on.
The special value "*" matches all local names.public org.w3c.dom.traversal.NodeIterator createNodeIterator(org.w3c.dom.Node root, short whatToShow, org.w3c.dom.traversal.NodeFilter filter)
root
- The root of the iterator.whatToShow
- The whatToShow mask.filter
- The NodeFilter installed. Null means no filter.#removeNodeIterator
,
#removeNodeIterators
public org.w3c.dom.traversal.NodeIterator createNodeIterator(org.w3c.dom.Node root, int whatToShow, org.w3c.dom.traversal.NodeFilter filter, boolean entityReferenceExpansion)
root
- The root of the iterator.whatToShow
- The whatToShow mask.filter
- The NodeFilter installed. Null means no filter.entityReferenceExpansion
- true to expand the contents of EntityReference nodes#removeNodeIterator
,
#removeNodeIterators
public org.w3c.dom.traversal.TreeWalker createTreeWalker(org.w3c.dom.Node root, short whatToShow, org.w3c.dom.traversal.NodeFilter filter)
root
- The root of the iterator.whatToShow
- The whatToShow mask.filter
- The NodeFilter installed. Null means no filter.public org.w3c.dom.traversal.TreeWalker createTreeWalker(org.w3c.dom.Node root, int whatToShow, org.w3c.dom.traversal.NodeFilter filter, boolean entityReferenceExpansion)
root
- The root of the iterator.whatToShow
- The whatToShow mask.filter
- The NodeFilter installed. Null means no filter.entityReferenceExpansion
- true to expand the contents of EntityReference nodespublic org.w3c.dom.range.Range createRange()
public org.w3c.dom.events.Event createEvent(java.lang.String type) throws org.w3c.dom.DOMException
Create and return Event objects.
type
- The event set name, defined as the interface name
minus package qualifiers. For example, to create a DOMNodeInserted
event you'd call createEvent("MutationEvent")
,
then use its initMutationEvent() method to configure it properly
as DOMNodeInserted. This parameter is case-sensitive.init...Event()
method before dispatching it.public java.lang.Object clone() throws java.lang.CloneNotSupportedException
public static boolean isXMLName(java.lang.String s)
[Definition:] A Name is a token beginning with a letter or one of a few punctuation characters, and continuing with letters, digits, hyphens,underscores, colons, or full stops, together known as name characters.
Unfortunately, that spec goes on to say that after the first character, names may use "combining characters" and "extender characters", which are explicitly listed rather than defined in terms of Java's Unicode character types... and which in fact can't be expressed solely in terms of those types.
I've empirically derived some tests which are partly based on the Java Unicode space (which simplifies them considerably), but they still wind up having to be further qualified. This may not remain valid if future extensions of Java and/or Unicode introduce other characters having these type numbers.
Suggestions for alternative implementations would be welcome.
protected void setUserData(NodeImpl n, java.lang.Object data)
protected java.lang.Object getUserData(NodeImpl n)
protected void setEventListeners(NodeImpl n, java.util.Vector listeners)
protected java.util.Vector getEventListeners(NodeImpl n)
protected boolean isKidOK(org.w3c.dom.Node parent, org.w3c.dom.Node child)
protected void changed()
protected int changes()
|
Documentation is available at http://download.oracle.com/docs/cd/E13222_01/wls/docs60 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |