code: public synchronized String getNamespacePrefixByURI(String uri) throws NamespaceException
     {
        String prefix = uriToPrefix.get(uri);
        if (prefix == null)
        {
           // make sure prefix is not taken
           while (prefixToURI.get(String.valueOf(prefixCount)) != null)
           {
              prefixCount++;
           }
           prefix = String.valueOf(prefixCount);
           prefixToURI.put(prefix, uri);
           uriToPrefix.put(uri, prefix);
           log.debug("adding new namespace mapping: " + prefix + " -> " + uri);
           try
           {
              store();
           }
           catch (IOException e)
           {
              throw new NamespaceException("Could not obtain a prefix for uri: " + uri, e);
           }
        }
        return prefix;
     }
docs: Returns a prefix for the namespace <code>uri</code>. If a namespace
  mapping exists, the already known prefix is returned; otherwise a new
  prefix is created and assigned to the namespace uri.
  
  @param uri the namespace uri.
  @return the prefix for the namespace uri.
  @throws NamespaceException if an yet unknown namespace uri / prefix
  mapping could not be stored.