org.apache.xml.utils
Class Context2

java.lang.Object
  extended by org.apache.xml.utils.Context2

final class Context2
extends java.lang.Object

Internal class for a single Namespace context.

This module caches and reuses Namespace contexts, so the number allocated will be equal to the element depth of the document, not to the total number of elements (i.e. 5-10 rather than tens of thousands).


Field Summary
(package private)  java.util.Hashtable attributeNameTable
           
private  Context2 child
           
private  java.util.Vector declarations
           
(package private)  java.lang.String defaultNS
           
(package private)  java.util.Hashtable elementNameTable
           
private static java.util.Enumeration EMPTY_ENUMERATION
          An empty enumeration.
private  Context2 parent
           
(package private)  java.util.Hashtable prefixTable
           
private  boolean tablesDirty
           
(package private)  java.util.Hashtable uriTable
           
 
Constructor Summary
Context2(Context2 parent)
          Create a new Namespace context.
 
Method Summary
private  void copyTables()
          Copy on write for the internal tables in this context.
(package private)  void declarePrefix(java.lang.String prefix, java.lang.String uri)
          Declare a Namespace prefix for this context.
(package private)  Context2 getChild()
           
(package private)  java.util.Enumeration getDeclaredPrefixes()
          Return an enumeration of prefixes declared in this context.
(package private)  Context2 getParent()
           
(package private)  java.lang.String getPrefix(java.lang.String uri)
          Look up one of the prefixes associated with a URI in this context.
(package private)  java.util.Enumeration getPrefixes()
          Return an enumeration of all prefixes currently in force.
(package private)  java.lang.String getURI(java.lang.String prefix)
          Look up the URI associated with a prefix in this context.
(package private)  java.lang.String[] processName(java.lang.String qName, boolean isAttribute)
          Process a raw XML 1.0 name in this context.
(package private)  void setParent(Context2 parent)
          (Re)set the parent of this Namespace context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ENUMERATION

private static final java.util.Enumeration EMPTY_ENUMERATION
An empty enumeration.


prefixTable

java.util.Hashtable prefixTable

uriTable

java.util.Hashtable uriTable

elementNameTable

java.util.Hashtable elementNameTable

attributeNameTable

java.util.Hashtable attributeNameTable

defaultNS

java.lang.String defaultNS

declarations

private java.util.Vector declarations

tablesDirty

private boolean tablesDirty

parent

private Context2 parent

child

private Context2 child
Constructor Detail

Context2

Context2(Context2 parent)
Create a new Namespace context.

Method Detail

getChild

Context2 getChild()

getParent

Context2 getParent()

setParent

void setParent(Context2 parent)
(Re)set the parent of this Namespace context. This is separate from the c'tor because it's re-applied when a Context2 is reused by push-after-pop.

Parameters:
context - The parent Namespace context object.

declarePrefix

void declarePrefix(java.lang.String prefix,
                   java.lang.String uri)
Declare a Namespace prefix for this context.

Parameters:
prefix - The prefix to declare.
uri - The associated Namespace URI.
See Also:
org.xml.sax.helpers.NamespaceSupport2#declarePrefix

processName

java.lang.String[] processName(java.lang.String qName,
                               boolean isAttribute)
Process a raw XML 1.0 name in this context.

Parameters:
qName - The raw XML 1.0 name.
isAttribute - true if this is an attribute name.
Returns:
An array of three strings containing the URI part (or empty string), the local part, and the raw name, all internalized, or null if there is an undeclared prefix.
See Also:
org.xml.sax.helpers.NamespaceSupport2#processName

getURI

java.lang.String getURI(java.lang.String prefix)
Look up the URI associated with a prefix in this context.

Parameters:
prefix - The prefix to look up.
Returns:
The associated Namespace URI, or null if none is declared.
See Also:
org.xml.sax.helpers.NamespaceSupport2#getURI

getPrefix

java.lang.String getPrefix(java.lang.String uri)
Look up one of the prefixes associated with a URI in this context.

Since many prefixes may be mapped to the same URI, the return value may be unreliable.

Parameters:
uri - The URI to look up.
Returns:
The associated prefix, or null if none is declared.
See Also:
org.xml.sax.helpers.NamespaceSupport2#getPrefix

getDeclaredPrefixes

java.util.Enumeration getDeclaredPrefixes()
Return an enumeration of prefixes declared in this context.

Returns:
An enumeration of prefixes (possibly empty).
See Also:
org.xml.sax.helpers.NamespaceSupport2#getDeclaredPrefixes

getPrefixes

java.util.Enumeration getPrefixes()
Return an enumeration of all prefixes currently in force.

The default prefix, if in force, is not returned, and will have to be checked for separately.

Returns:
An enumeration of prefixes (never empty).
See Also:
org.xml.sax.helpers.NamespaceSupport2#getPrefixes

copyTables

private void copyTables()
Copy on write for the internal tables in this context.

This class is optimized for the normal case where most elements do not contain Namespace declarations. In that case, the Context2 will share data structures with its parent. New tables are obtained only when new declarations are issued, so they can be popped off the stack.

JJK: **** Alternative: each Context2 might declare _only_ its local bindings, and delegate upward if not found.