org.apache.commons.betwixt.strategy
Class NamespacePrefixMapper

java.lang.Object
  extended byorg.apache.commons.betwixt.strategy.NamespacePrefixMapper

public class NamespacePrefixMapper
extends java.lang.Object

Maps namespace URI's to prefixes.

When validating xml documents including namespaces, the issue of prefixes (the short expression before the colon in a universal name) becomes important. DTDs are not namespace aware and so a fixed prefixed must be chosen and used consistently. This class is used to supply consistent, user specified prefixes.

Version:
$Revision: 438373 $
Author:
Jakarta Commons Team

Field Summary
private  int count
           
private  java.util.HashMap prefixesByUri
           
 
Constructor Summary
NamespacePrefixMapper()
           
 
Method Summary
protected  java.lang.String generatePrefix(java.lang.String namespaceUri)
          Generates a prefix for the given namespace Uri.
 java.lang.String getPrefix(java.lang.String namespaceUri)
          Gets the prefix to be used with the given namespace URI
 void setPrefix(java.lang.String namespaceUri, java.lang.String prefix)
          Sets the prefix to be used for the given namespace URI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

count

private int count

prefixesByUri

private java.util.HashMap prefixesByUri
Constructor Detail

NamespacePrefixMapper

public NamespacePrefixMapper()
Method Detail

getPrefix

public java.lang.String getPrefix(java.lang.String namespaceUri)
Gets the prefix to be used with the given namespace URI

Parameters:
namespaceUri -
Returns:
prefix, not null

setPrefix

public void setPrefix(java.lang.String namespaceUri,
                      java.lang.String prefix)
Sets the prefix to be used for the given namespace URI. This method does not check for clashes amongst the namespaces. Possibly it should.

Parameters:
namespaceUri -
prefix -

generatePrefix

protected java.lang.String generatePrefix(java.lang.String namespaceUri)
Generates a prefix for the given namespace Uri. Used to assign prefixes for unassigned namespaces. Subclass may wish to override this method to provide more sophisticated implementations.

Parameters:
namespaceUri - URI, not null
Returns:
prefix, not null