org.apache.xerces.dom

Class NamedNodeMapImpl

Implemented Interfaces:
NamedNodeMap, Serializable
Known Direct Subclasses:
AttributeMap

public class NamedNodeMapImpl
extends java.lang.Object
implements NamedNodeMap, Serializable

NamedNodeMaps represent collections of Nodes that can be accessed by name. Entity and Notation nodes are stored in NamedNodeMaps attached to the DocumentType. Attributes are placed in a NamedNodeMap attached to the elem they're related too. However, because attributes require more work, such as firing mutation events, they are stored in a subclass of NamedNodeMapImpl.

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 "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.

Version:
$Id: NamedNodeMapImpl.java,v 1.40 2005/03/07 23:28:40 mrglavas Exp $
Since:
PR-DOM-Level-1-19980818.

Field Summary

protected static short
CHANGED
protected static short
HASDEFAULTS
protected static short
READONLY
protected short
flags
protected Vector
nodes
Nodes.
protected NodeImpl
ownerNode

Constructor Summary

NamedNodeMapImpl(NodeImpl ownerNode)
Constructs a named node map.

Method Summary

protected int
addItem(Node arg)
protected void
cloneContent(NamedNodeMapImpl srcmap)
protected Vector
cloneMap(Vector list)
NON-DOM: copy content of this map into the specified vector
NamedNodeMapImpl
cloneMap(NodeImpl ownerNode)
Cloning a NamedNodeMap is a DEEP OPERATION; it always clones all the nodes contained in the map.
protected int
findNamePoint(String namespaceURI, String name)
This findNamePoint is for DOM Level 2 Namespaces.
protected int
findNamePoint(String name, int start)
Subroutine: Locate the named item, or the point at which said item should be added.
protected Object
getItem(int index)
int
getLength()
Report how many nodes are currently stored in this NamedNodeMap.
Node
getNamedItem(String name)
Retrieve a node by name.
protected int
getNamedItemIndex(String namespaceURI, String localName)
Node
getNamedItemNS(String namespaceURI, String localName)
Introduced in DOM Level 2.
Node
item(int index)
Retrieve an item from the map by 0-based index.
protected boolean
precedes(Node a, Node b)
void
removeAll()
NON-DOM remove all elements from this map
protected void
removeItem(int index)
NON-DOM: Remove attribute at specified index
Node
removeNamedItem(String name)
Node
removeNamedItemNS(String namespaceURI, 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.

Field Details

CHANGED

protected static final short CHANGED
Field Value:
2

HASDEFAULTS

protected static final short HASDEFAULTS
Field Value:
4

READONLY

protected static final short READONLY
Field Value:
1

flags

protected short flags

nodes

protected Vector nodes
Nodes.

ownerNode

protected NodeImpl ownerNode

Constructor Details

NamedNodeMapImpl

protected NamedNodeMapImpl(NodeImpl ownerNode)
Constructs a named node map.

Method Details

addItem

protected int addItem(Node arg)

cloneContent

protected void cloneContent(NamedNodeMapImpl srcmap)

cloneMap

protected Vector cloneMap(Vector list)
NON-DOM: copy content of this map into the specified vector
Parameters:
list - Vector to copy information into.
Returns:
A copy of this node named map

cloneMap

public NamedNodeMapImpl cloneMap(NodeImpl ownerNode)
Cloning a NamedNodeMap is a DEEP OPERATION; it always clones all the nodes contained in the map.

findNamePoint

protected int findNamePoint(String namespaceURI,
                            String name)
This findNamePoint is for DOM Level 2 Namespaces.

findNamePoint

protected int findNamePoint(String name,
                            int start)
Subroutine: Locate the named item, or the point at which said item should be added.
Parameters:
name - Name of a node to look up.
Returns:
If positive or zero, the index of the found item. If negative, index of the appropriate point at which to insert the item, encoded as -1-index and hence reconvertable by subtracting it from -1. (Encoding because I don't want to recompare the strings but don't want to burn bytes on a datatype to hold a flagged value.)

getItem

protected Object getItem(int index)

getLength

public int getLength()
Report how many nodes are currently stored in this NamedNodeMap. Caveat: This is a count rather than an index, so the highest-numbered node at any time can be accessed via item(getLength()-1).

getNamedItem

public Node getNamedItem(String name)
Retrieve a node by name.
Parameters:
name - Name of a node to look up.
Returns:
the Node (of unspecified sub-class) stored with that name, or null if no value has been assigned to that name.

getNamedItemIndex

protected int getNamedItemIndex(String namespaceURI,
                                String localName)

getNamedItemNS

public Node getNamedItemNS(String namespaceURI,
                           String localName)
Introduced in DOM Level 2.

Retrieves a node specified by local name and namespace URI.

Parameters:
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.
Returns:
Node A Node (of any type) with the specified name, or null if the specified name did not identify any node in the map.

item

public Node item(int index)
Retrieve an item from the map by 0-based index.
Parameters:
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.
Returns:
the node which currenly has the specified index, or null if index is greater than or equal to getLength().

precedes

protected boolean precedes(Node a,
                           Node b)

removeAll

public void removeAll()
NON-DOM remove all elements from this map

removeItem

protected void removeItem(int index)
NON-DOM: Remove attribute at specified index

removeNamedItem

public Node removeNamedItem(String name)
            throws DOMException

removeNamedItemNS

public Node removeNamedItemNS(String namespaceURI,
                              String name)
            throws DOMException
Introduced in DOM Level 2.

Removes a node specified by local name and namespace URI.

Parameters:
namespaceURI - The namespace URI of the node to remove. When it is null or an empty string, this method behaves like removeNamedItem.
Returns:
Node The node removed from the map if a node with such a local name and namespace URI exists.

setNamedItem

public Node setNamedItem(Node arg)
            throws DOMException
Adds a node using its nodeName attribute. As the nodeName attribute is used to derive the name which the node must be stored under, multiple nodes of certain types (those that have a "special" string value) cannot be stored as the names would clash. This is seen as preferable to allowing nodes to be aliased.
Parameters:
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.
Returns:
If the new Node replaces an existing node the replaced Node is returned, otherwise null is returned.
See Also:
org.w3c.dom.NamedNodeMap.setNamedItem

setNamedItemNS

public Node setNamedItemNS(Node arg)
            throws DOMException
Adds a node using its namespaceURI and localName.
Parameters:
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.
Returns:
If the new Node replaces an existing node the replaced Node is returned, otherwise null is returned.
See Also:
org.w3c.dom.NamedNodeMap.setNamedItem

Copyright B) 1999-2005 Apache XML Project. All Rights Reserved.