## net.sf.saxon.instruct
Class NamespaceContext

    java.lang.Object
      |
      +--net.sf.saxon.instruct.NamespaceContext

All Implemented Interfaces:
  NamespaceResolver, java.io.Serializable

public final class NamespaceContext
extends java.lang.Object
implements java.io.Serializable, NamespaceResolver

An object representing a list of Namespaces. Used when the namespace controller in the stylesheet needs to be kept for use at run-time. The list of namespaces is maintained in the form of numeric prefix/uri codes, which are only meaningful in the controller of a name pool; however, in order to save space, the NamespaceContext object does not keep a reference to the namepool, it requires this to be supplied by the caller.

See Also:
  Serialized Form

Constructor Summary
`NamespaceContext(int[] nscodes, NamePool pool)` Create a NamespaceContext object

Method Summary
`int` `getFingerprint(java.lang.String qname, boolean useDefault, NamePool pool)` Use this NamespaceContext to resolve a lexical QName
`int[]` `getNamespaceCodes()` Get the list of in-scope namespaces held in this NamespaceContext
`java.lang.String` `getURIForPrefix(java.lang.String prefix, boolean useDefault)` Get the namespace URI corresponding to a given prefix.
`java.util.Iterator` `iteratePrefixes()` Get an iterator over all the prefixes declared in this namespace context.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### NamespaceContext

    public NamespaceContext(int[] nscodes,
                            NamePool pool)

  Create a NamespaceContext object

Parameters:
  `nscodes` - an array of namespace codes. Each namespace code is an integer in which the first 16 bits represent the prefix (zero if it's the default namespace) and the next 16 bits represent the uri. These are codes held in the NamePool. The list will be searched from the "high" end.

Method Detail

### getNamespaceCodes

    public int[] getNamespaceCodes()

  Get the list of in-scope namespaces held in this NamespaceContext

  Returns:
    the list of namespaces

### getURIForPrefix

    public java.lang.String getURIForPrefix(java.lang.String prefix,
                                            boolean useDefault)

  Get the namespace URI corresponding to a given prefix. Return null if the prefix is not in scope.

  Specified by:
    `getURIForPrefix` in interface `NamespaceResolver`
  Parameters:
    `prefix` - the namespace prefix
    `useDefault` - true if the default namespace is to be used when the prefix is ""
  Returns:
    the uri for the namespace, or null if the prefix is not in scope

### getFingerprint

    public int getFingerprint(java.lang.String qname,
                              boolean useDefault,
                              NamePool pool)
                       throws DynamicError

  Use this NamespaceContext to resolve a lexical QName

  Specified by:
    `getFingerprint` in interface `NamespaceResolver`
  Parameters:
    `qname` - the lexical QName; this must have already been lexically validated
    `useDefault` - true if the default namespace is to be used to resolve an unprefixed QName
    `pool` - the NamePool to be used
  Returns:
    the integer fingerprint that uniquely identifies this name
  Throws:
    `DynamicError` - if the string is not a valid lexical QName or if the namespace prefix has not been declared

### iteratePrefixes

    public java.util.Iterator iteratePrefixes()

  Get an iterator over all the prefixes declared in this namespace context. This will include the default namespace (prefix="") and the XML namespace where appropriate

  Specified by:
    `iteratePrefixes` in interface `NamespaceResolver`