org.apache.ws.jaxme.util

Class NamespaceSupport

Implemented Interfaces:
NamespaceContext

public class NamespaceSupport
extends java.lang.Object
implements NamespaceContext

Similar to org.xml.sax.NamespaceSupport, but for marshalling and not for parsing XML.
Version:
$Id: NamespaceSupport.java 232067 2005-03-10 11:14:08 +0100 (Thu, 10 Mar 2005) jochen $
Author:
Jochen Wiedmann

Constructor Summary

NamespaceSupport()
Creates a new instance of NamespaceSupport.

Method Summary

String
checkContext(int i)
This method is used to restore the namespace state after an element is created.
void
declarePrefix(String pPrefix, String pURI)
Declares a new prefix.
String
getAttributePrefix(String pURI)
Returns a non-empty prefix currently mapped to the given URL or null, if there is no such mapping.
int
getContext()
Returns the current number of assigned prefixes.
String
getNamespaceURI(String pPrefix)
Given a prefix, returns the URI to which the prefix is currently mapped or null, if there is no such mapping.
String
getPrefix(String pURI)
Returns a prefix currently mapped to the given URI or null, if there is no such mapping.
Iterator
getPrefixes(String pURI)
Returns a collection to all prefixes bound to the given namespace URI.
boolean
isPrefixDeclared(String pPrefix)
Returns whether a given prefix is currently declared.
void
reset()
Resets the NamespaceSupport's state for reuse.
void
undeclarePrefix(String pPrefix)
Removes a prefix declaration.

Constructor Details

NamespaceSupport

public NamespaceSupport()
Creates a new instance of NamespaceSupport.

Method Details

checkContext

public String checkContext(int i)
This method is used to restore the namespace state after an element is created. It takes as input a state, as returned by getContext().
For any prefix, which was since saving the state, the prefix is returned and deleted from the internal list. In other words, a typical use looks like this:
   NamespaceSupport nss;
   ContentHandler h;
   int context = nss.getContext();
   h.startElement("foo", "bar", "f:bar", new AttributesImpl());
   ...
   h.endElement("foo", "bar", "f:bar");
   for (;;) {
     String prefix = nss.checkContext(context);
     if (prefix == null) {
       break;
     }
     h.endPrefixMapping(prefix);
   }
 

declarePrefix

public void declarePrefix(String pPrefix,
                          String pURI)
Declares a new prefix.

getAttributePrefix

public String getAttributePrefix(String pURI)
Parameters:
pURI - Thhe namespace URI in question

getContext

public int getContext()

getNamespaceURI

public String getNamespaceURI(String pPrefix)
Given a prefix, returns the URI to which the prefix is currently mapped or null, if there is no such mapping.

Note: This methods behaviour is precisely defined by NamespaceContext.getNamespaceURI(java.lang.String).

Specified by:
getNamespaceURI in interface NamespaceContext
Parameters:
pPrefix - The prefix in question

getPrefix

public String getPrefix(String pURI)
Parameters:
pURI - The namespace URI in question

getPrefixes

public Iterator getPrefixes(String pURI)
Parameters:
pURI - The namespace prefix in question

isPrefixDeclared

public boolean isPrefixDeclared(String pPrefix)
Returns whether a given prefix is currently declared.

reset

public void reset()
Resets the NamespaceSupport's state for reuse.

undeclarePrefix

public void undeclarePrefix(String pPrefix)
Removes a prefix declaration. Assumes that the prefix is the current prefix. If not, throws a IllegalStateException.