|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.xerces.dom.NamedNodeMapImpl
NamedNodeMaps represent collections of Nodes that can be accessed by name. They're currently used in two modes. Attributes are placed in a NamedNodeMap rather than being children of the node they describe. On the other hand Entity and Notation appear both in the NamedNodeMap _and_ as kids of the DocumentType, requiring some additional logic so these are maintained as "live views" of each other.
Only one Node may be stored per name; attempting to store another will replace the previous value.
NOTE: The "primary" storage key is taken from the NodeName attribute of the node. The "nodes" Vector is kept sorted by this key to speed lookup, ad make it easier to reconcile with the defaults. The "secondary" storage key is the namespaceURI and localName, when accessed by DOM level 2 nodes. all nodes, even DOM Level 2 nodes are stored in a single Vector sorted by the primary "nodename" key.
NOTE: item()'s integer index does _not_ imply that the named nodes must be stored in an array; that's only an access method. Note too that these indices are "live"; if someone changes the map's contents, the indices associated with nodes may change.
As of REC-DOM-Level-1-19981001, Entities and Notations are no longer shadowed as children of DocumentType.
This implementation includes support for DOM Level 2 Mutation Events. If the static boolean NodeImpl.MUTATIONEVENTS is not set true, that support is disabled and can be optimized out to reduce code size.
Field Summary | |
protected int |
changes
Changes. |
protected NamedNodeMapImpl |
defaults
Default nodes. |
protected ElementImpl |
element
Element. |
protected int |
lastDefaultsChanges
Last defaults changes. |
protected java.util.Vector |
nodes
Nodes. |
protected Document |
ownerDocument
Owner document. |
protected boolean |
readOnly
Read-only. |
Constructor Summary | |
protected |
NamedNodeMapImpl(Document ownerDoc,
NamedNodeMapImpl defaults)
Constructs a named node map. |
protected |
NamedNodeMapImpl(ElementImpl element,
NamedNodeMapImpl defaults)
Constructs a named node map. |
Method Summary | |
NamedNodeMapImpl |
cloneMap()
Cloning a NamedNodeMap is a DEEP OPERATION; it always clones all the nodes contained in the map. |
int |
getLength()
Report how many nodes are currently stored in this NamedNodeMap. |
Node |
getNamedItem(java.lang.String name)
Retrieve a node by name. |
Node |
getNamedItemNS(java.lang.String namespaceURI,
java.lang.String localName)
Introduced in DOM Level 2. |
Node |
item(int index)
Retrieve an item from the map by 0-based index. |
protected void |
reconcileDefaults()
Subroutine: If this NamedNodeMap is backed by a "defaults" map (eg, if it's being used for Attributes of an XML file validated against a DTD), we need to deal with the risk that those defaults might have changed. |
Node |
removeNamedItem(java.lang.String name)
Removes a node specified by name. |
Node |
removeNamedItemNS(java.lang.String namespaceURI,
java.lang.String name)
Introduced in DOM Level 2. |
Node |
setNamedItem(Node arg)
Adds a node using its nodeName attribute. |
Node |
setNamedItemNS(Node arg)
Adds a node using its namespaceURI and localName. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected java.util.Vector nodes
protected Document ownerDocument
protected ElementImpl element
protected NamedNodeMapImpl defaults
protected int changes
protected int lastDefaultsChanges
protected boolean readOnly
Constructor Detail |
protected NamedNodeMapImpl(Document ownerDoc, NamedNodeMapImpl defaults)
protected NamedNodeMapImpl(ElementImpl element, NamedNodeMapImpl defaults)
Method Detail |
public int getLength()
COMPLICATION: In the case of attributes, the count has to include any defaults that may be inherited, yet not double-count when there is both a default and a specified value. Convolving the two lists is expensive, and for GC reasons we don't want to register with the DTD (it wouldn't know when to release us).
One solution is to go into the change-counter domain, as we did for DeepNodeList. Another is to accept the convolution, and count on the fact that our implementation is a sorted list to keep the cost managable... which works pretty well for getLength(), but makes item() expensive.
The ideal fix would be to rearchitect to eliminate integer indexing, but of course that wouldn't meet the spec!
public Node item(int index)
index
- Which item to retrieve. Note that indices are just an
enumeration of the current contents; they aren't guaranteed to be
stable, nor do they imply any promises about the order of the
NamedNodeMap's contents. In other words, DO NOT assume either that
index(i) will always refer to the same entry, or that there is any
stable ordering of entries... and be prepared for double-reporting
or skips as insertion and deletion occur.public Node getNamedItem(java.lang.String name)
name
- Name of a node to look up.public Node getNamedItemNS(java.lang.String namespaceURI, java.lang.String localName)
Retrieves a node specified by local name and namespace URI.
namespaceURI
- The namespace URI of the node to retrieve.
When it is null or an empty string, this
method behaves like getNamedItem.localName
- The local name of the node to retrieve.public Node setNamedItem(Node arg) throws DOMException
arg
- A node to store in a named node map. The node will later be
accessible using the value of the namespaceURI and localName
attribute of the node. If a node with those namespace URI and
local name is already present in the map, it is replaced by the new
one.NamedNodeMap.setNamedItem(org.w3c.dom.Node)
public Node setNamedItemNS(Node arg) throws DOMException
arg
- A node to store in a named node map. The node will later be
accessible using the value of the namespaceURI and localName
attribute of the node. If a node with those namespace URI and
local name is already present in the map, it is replaced by the new
one.NamedNodeMap.setNamedItem(org.w3c.dom.Node)
public Node removeNamedItem(java.lang.String name) throws DOMException
Node
interface. If so, an attribute immediately appears
containing the default value as well as the corresponding namespace
URI, local name, and prefix when applicable.name
- The nodeName
of the node to remove.name
in this map.
public Node removeNamedItemNS(java.lang.String namespaceURI, java.lang.String name) throws DOMException
Removes a node specified by local name and namespace URI.
namespaceURI
- The namespace URI of the node to remove.
When it is null or an empty string, this
method behaves like removeNamedItem.The
- local name of the node to remove. When
this NamedNodeMap contains the attributes
attached to an element, as returned by the
attributes attribute of the Node interface, if the
removed attribute is known to have a default
value, an attribute immediately appears
containing the default value.public NamedNodeMapImpl cloneMap()
protected void reconcileDefaults()
Luckily, this currently applies _only_ to Attributes, which have a "specified" flag that allows us to distinguish which we set manually versus which were defaults... assuming that the defaults list is being maintained properly, of course.
Also luckily, The NameNodeMaps are maintained as sorted lists. This should keep the cost of convolving the two lists managable... not wonderful, but at least more like 2N than N**2..
Finally, to avoid doing the convolution except when there are actually changes to be absorbed, I've made the Map aware of whether or not its defaults Map has changed. This is not 110% reliable, but it should work under normal circumstances, especially since the DTD is usually relatively static information.
Note: This is NON-DOM implementation, though used to support behavior that the DOM requires.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |