jd.xml.xpath.model
Class NamespaceContext

java.lang.Object
  extended byjd.xml.xpath.model.NamespaceContext

public class NamespaceContext
extends Object

NamespaceContext provides information about namespace declarations. A single NamespaceContext object stores information about a single namespace declaration, i.e. prefix, uri and declaring element. A NamespaceContext object can be be connected to another NamespaceContext thus effectivly representing a chain of namespace declarations. The xml namespace itself and the undeclaration of the default namespace (xmlns="") are by design not representable by a NamespaceContext object.


Method Summary
static NamespaceContext add(String prefix, String uri, NamespaceContext first)
          Create a NamespaceContext.
 int count()
          Return the number of namespaces in this namespace chain.
 void dump(PrintStream out)
          Dump the namespaces to the printstream.
 int getDeclarationId()
          Return the declaration id.
 int getIndex()
          Return the index of the NamespaceContext.
 String getPrefix()
          Return the prefix of this NamespaceContext obect.
static String getPrefix(NamespaceContext context, String uri)
           
 String getPrefix(String uri)
          Return the prefix associated with the supplied uri.
 String getUri()
          Return the uri of this NamespaceContext object.
static String getUri(NamespaceContext context, String prefix)
           
 String getUri(String prefix)
          Return the uri associated with the supplied prefix.
 NamespaceContext next()
          Return the next NamespaceContext in this chain.
static NamespaceContext remove(String prefix, NamespaceContext first)
          Remove a NamespaceContext.
 void setDeclarationId(int id)
          Set the declaration id of this NamespaceContext.
static void setDeclarationIds(NamespaceContext context, int id)
          Loop through the namespace chain and set the declaration id of all NamespaceContexts who have no declaration id, until the chain ends or a NamespaceContext with a declaration id is encountered.
 void setIndex(int index)
          Set the index of the NamespaceContext.
 void setUri(String uri)
          Set the uri of this NamespaceContext.
 String toString()
          Return a string representation of this namespace.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

add

public static NamespaceContext add(String prefix,
                                   String uri,
                                   NamespaceContext first)
Create a NamespaceContext.

Parameters:
prefix - the prefix
uri - the uri
first - another NamespaceContext to which this NamespaceContext gets connected.
Returns:
a NamespaceContext object connected to the chain represented by first. This chain does not contain duplicate declarations for the same prefix and no declaration for the xml namespace.

remove

public static NamespaceContext remove(String prefix,
                                      NamespaceContext first)
Remove a NamespaceContext.

Parameters:
prefix - the prefix of the namespace
first -
Returns:
a NamespaceContext object which does not contain the prefix.

getPrefix

public String getPrefix()
Return the prefix of this NamespaceContext obect.


getPrefix

public String getPrefix(String uri)
Return the prefix associated with the supplied uri.

Returns:
the prefix or null if no namespace defines a prefix for the uri

getPrefix

public static String getPrefix(NamespaceContext context,
                               String uri)

setUri

public void setUri(String uri)
Set the uri of this NamespaceContext.


getUri

public String getUri()
Return the uri of this NamespaceContext object.


getUri

public String getUri(String prefix)
Return the uri associated with the supplied prefix.

Returns:
the uri or null if no namespace has the prefix

getUri

public static String getUri(NamespaceContext context,
                            String prefix)

setDeclarationId

public void setDeclarationId(int id)
Set the declaration id of this NamespaceContext. This id can be used to group NamespaceContexts that Contexts with the same id are declared by an element which is denoted by this id.


getDeclarationId

public int getDeclarationId()
Return the declaration id.


setDeclarationIds

public static void setDeclarationIds(NamespaceContext context,
                                     int id)
Loop through the namespace chain and set the declaration id of all NamespaceContexts who have no declaration id, until the chain ends or a NamespaceContext with a declaration id is encountered.


next

public NamespaceContext next()
Return the next NamespaceContext in this chain.


count

public int count()
Return the number of namespaces in this namespace chain.


getIndex

public int getIndex()
Return the index of the NamespaceContext. The index can be deliberatly be set by the owner of the NamespaceContext to support an additional storage mechanism of the NamespaceContext objects.

See Also:
setIndex(int)

setIndex

public void setIndex(int index)
Set the index of the NamespaceContext. The default is -1.

See Also:
getIndex()

dump

public void dump(PrintStream out)
Dump the namespaces to the printstream.


toString

public String toString()
Return a string representation of this namespace.