APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.org.apache.xml.internal.serializer

public Class NamespaceMappings

extends Object
Class Inheritance
Imports
java.util.HashMap, .Iterator, .Stack, org.xml.sax.ContentHandler, .SAXException

This class keeps track of the currently defined namespaces. Conceptually the prefix/uri/depth triplets are pushed on a stack pushed on a stack. The depth indicates the nesting depth of the element for which the mapping was made.

For example:


  
     
     
   
   
   

When the element is encounted the prefix "p1" associated with uri "def" is pushed on the stack with depth 1. When the first is encountered "p2" and "ghi" are pushed with depth 2. When the is encountered "p3" and "jkl" are pushed with depth 3. When occurs the popNamespaces(3) will pop "p3"/"jkl" off the stack. Of course popNamespaces(2) would pop anything with depth 2 or greater. So prefix/uri pairs are pushed and poped off the stack as elements are processed. At any given moment of processing the currently visible prefixes are on the stack and a prefix can be found given a uri, or a uri can be found given a prefix. This class is public only because it is used by Xalan. It is not a public API

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
private int
count

This member is continually incremented when new prefixes need to be generated.

private static final String
private HashMap<String, Stack<NamespaceMappings.MappingRecord>>
m_namespaces

Each entry (prefix) in this hashmap points to a Stack of URIs This maps a prefix (String) to a Stack of prefix mappings.

private Stack<NamespaceMappings.MappingRecord>
m_nodeStack

The top of this stack contains the MapRecord of the last declared a namespace.

private static final String

Constructor Summary

AccessConstructor and Description
public
NamespaceMappings()

Default constructor

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides java.lang.Object.clone.

This method makes a clone of this object.

public String

Returns:

String a new namespace prefix ( ns0, ns1, ns2 ...)
generateNextPrefix
()

Generate a new namespace prefix ( ns0, ns1 ...) not used before

pack-priv NamespaceMappings.MappingRecord
pack-priv NamespaceMappings.MappingRecord
private void
initNamespaces()

This method initializes the namespace object with appropriate stacks and predefines a few prefix/uri pairs which always exist.

public String

Returns:

the URI corresponding to the prefix
lookupNamespace
(String
String the prefix of the namespace
prefix
)

Use a namespace prefix to lookup a namespace URI.

public String

Returns:

an existing prefix that maps to the given URI, null if no prefix maps to the given namespace URI.
lookupPrefix
(String
the namespace URI to be search for
uri
)

Given a namespace uri, and the namespaces mappings for the current element, return the current prefix for that uri.

pack-priv boolean
popNamespace(String prefix)

Undeclare the namespace that is currently pointed to by a given prefix

pack-priv void
popNamespaces(int
the element depth for which mappings declared at this depth or deeper will no longer be valid
elemDepth
,
ContentHandler
The ContentHandler to notify of any endPrefixMapping() calls. This parameter can be null.
saxHandler
)

Pop, or undeclare all namespace definitions that are currently declared at the given element depth, or deepter.

pack-priv boolean
pushNamespace(String
a String with the prefix for a qualified name
prefix
,
String
a String with the uri to which the prefix is to map
uri
,
int
the depth of current declaration
elemDepth
)

Declare a mapping of a prefix to namespace URI at the given element depth.

pack-priv final void
Inherited from java.lang.Object:
equalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
private int count

This member is continually incremented when new prefixes need to be generated. ("ns0" "ns1" ...)

EMPTYSTRINGback to summary
private static final String EMPTYSTRING
m_namespacesback to summary
private HashMap<String, Stack<NamespaceMappings.MappingRecord>> m_namespaces

Each entry (prefix) in this hashmap points to a Stack of URIs This maps a prefix (String) to a Stack of prefix mappings. All mappings in that retrieved stack have the same prefix, though possibly different URI's or depths. Such a stack must have mappings at deeper depths push later on such a stack. Mappings pushed earlier on the stack will have smaller values for MappingRecord.m_declarationDepth.

m_nodeStackback to summary
private Stack<NamespaceMappings.MappingRecord> m_nodeStack

The top of this stack contains the MapRecord of the last declared a namespace. Used to know how many prefix mappings to pop when leaving the current element depth. For every prefix mapping the current element depth is pushed on this stack. That way all prefixes pushed at the current depth can be removed at the same time. Used to ensure prefix/uri map scopes are closed correctly

XML_PREFIXback to summary
private static final String XML_PREFIX

Constructor Detail

NamespaceMappingsback to summary
public NamespaceMappings()

Default constructor

See Also
java.lang.Object#Object()

Method Detail

cloneback to summary
public Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

This method makes a clone of this object.

Annotations
@SuppressWarnings:unchecked
Exceptions
CloneNotSupportedException:

Doc from java.lang.Object.clone.

if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.

generateNextPrefixback to summary
public String generateNextPrefix()

Generate a new namespace prefix ( ns0, ns1 ...) not used before

Returns:String

String a new namespace prefix ( ns0, ns1, ns2 ...)

getMappingFromPrefixback to summary
pack-priv NamespaceMappings.MappingRecord getMappingFromPrefix(String prefix)
getMappingFromURIback to summary
pack-priv NamespaceMappings.MappingRecord getMappingFromURI(String uri)
initNamespacesback to summary
private void initNamespaces()

This method initializes the namespace object with appropriate stacks and predefines a few prefix/uri pairs which always exist.

lookupNamespaceback to summary
public String lookupNamespace(String prefix)

Use a namespace prefix to lookup a namespace URI.

Parameters
prefix:String

String the prefix of the namespace

Returns:String

the URI corresponding to the prefix

lookupPrefixback to summary
public String lookupPrefix(String uri)

Given a namespace uri, and the namespaces mappings for the current element, return the current prefix for that uri.

Parameters
uri:String

the namespace URI to be search for

Returns:String

an existing prefix that maps to the given URI, null if no prefix maps to the given namespace URI.

popNamespaceback to summary
pack-priv boolean popNamespace(String prefix)

Undeclare the namespace that is currently pointed to by a given prefix

popNamespacesback to summary
pack-priv void popNamespaces(int elemDepth, ContentHandler saxHandler)

Pop, or undeclare all namespace definitions that are currently declared at the given element depth, or deepter.

Parameters
elemDepth:int

the element depth for which mappings declared at this depth or deeper will no longer be valid

saxHandler:ContentHandler

The ContentHandler to notify of any endPrefixMapping() calls. This parameter can be null.

pushNamespaceback to summary
pack-priv boolean pushNamespace(String prefix, String uri, int elemDepth)

Declare a mapping of a prefix to namespace URI at the given element depth.

Parameters
prefix:String

a String with the prefix for a qualified name

uri:String

a String with the uri to which the prefix is to map

elemDepth:int

the depth of current declaration

resetback to summary
pack-priv final void reset()
com.sun.org.apache.xml.internal.serializer back to summary

pack-priv Class NamespaceMappings.MappingRecord

extends Object
Class Inheritance
  • java.lang.Object
  • com.sun.org.apache.xml.internal.serializer.NamespaceMappings.MappingRecord

Field Summary

Modifier and TypeField and Description
pack-priv final int
pack-priv final String
pack-priv final String

Constructor Summary

AccessConstructor and Description
pack-priv
MappingRecord(String prefix, String uri, int depth)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

m_declarationDepthback to summary
pack-priv final int m_declarationDepth
m_prefixback to summary
pack-priv final String m_prefix
m_uriback to summary
pack-priv final String m_uri

Constructor Detail

MappingRecordback to summary
pack-priv MappingRecord(String prefix, String uri, int depth)