org.apache.jackrabbit.core
Class NamespaceRegistryImpl

java.lang.Object
  extended by org.apache.jackrabbit.spi.commons.namespace.AbstractNamespaceResolver
      extended by org.apache.jackrabbit.core.NamespaceRegistryImpl
All Implemented Interfaces:
NamespaceRegistry, NamespaceEventListener, NamespaceResolver

public class NamespaceRegistryImpl
extends AbstractNamespaceResolver
implements NamespaceRegistry, NamespaceEventListener

A NamespaceRegistryImpl ...


Constructor Summary
protected NamespaceRegistryImpl(FileSystem nsRegStore)
          Protected constructor: Constructs a new instance of this class.
 
Method Summary
 void externalRemap(String oldPrefix, String newPrefix, String uri)
          Called when a namespace has been externally remapped.
 NameResolver getNameResolver()
           
 PathResolver getPathResolver()
           
 String getPrefix(String uri)
          Returns the prefix which is mapped to the given URI.
 String[] getPrefixes()
          
 String getUniquePrefix(String uriHint)
          Returns a prefix that is unique among the already registered prefixes.
 String getURI(int idx)
          Returns the URI for a given index (i.e.
 String getURI(String prefix)
          Returns the URI to which the given prefix is mapped.
 int getURIIndex(String uri)
          Returns the index (i.e.
 String[] getURIs()
          
 void registerNamespace(String prefix, String uri)
          
 void safeRegisterNamespace(String prefixHint, String uri)
          Registers a namespace using the given prefix hint.
 void setEventChannel(NamespaceEventChannel eventChannel)
          Set an event channel to inform about changes.
 void unregisterNamespace(String prefix)
          
 
Methods inherited from class org.apache.jackrabbit.spi.commons.namespace.AbstractNamespaceResolver
addListener, notifyNamespaceAdded, notifyNamespaceRemapped, notifyNamespaceRemoved, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamespaceRegistryImpl

protected NamespaceRegistryImpl(FileSystem nsRegStore)
                         throws RepositoryException
Protected constructor: Constructs a new instance of this class.

Parameters:
nsRegStore -
Throws:
RepositoryException
Method Detail

getNameResolver

public NameResolver getNameResolver()

getPathResolver

public PathResolver getPathResolver()

getUniquePrefix

public String getUniquePrefix(String uriHint)
Returns a prefix that is unique among the already registered prefixes.

Parameters:
uriHint - namespace uri that serves as hint for the prefix generation
Returns:
a unique prefix

safeRegisterNamespace

public void safeRegisterNamespace(String prefixHint,
                                  String uri)
                           throws NamespaceException,
                                  RepositoryException
Registers a namespace using the given prefix hint. Does nothing if the namespace is already registered. If the given prefix hint is not yet registered as a prefix, then it is used as the prefix of the registered namespace. Otherwise a unique prefix is generated based on the given hint.

Parameters:
prefixHint - the prefix hint
uri - the namespace URI
Throws:
NamespaceException - if an illegal attempt is made to register a mapping
RepositoryException - if an unexpected error occurs
See Also:
registerNamespace(String, String)

setEventChannel

public void setEventChannel(NamespaceEventChannel eventChannel)
Set an event channel to inform about changes.

Parameters:
eventChannel - event channel

getURIIndex

public int getURIIndex(String uri)
                throws NamespaceException
Returns the index (i.e. stable prefix) for the given uri.

Parameters:
uri - the uri to retrieve the index for
Returns:
the index
Throws:
NamespaceException - if the URI is not registered.

getURI

public String getURI(int idx)
              throws NamespaceException
Returns the URI for a given index (i.e. stable prefix).

Parameters:
idx - the index to retrieve the uri for.
Returns:
the uri
Throws:
NamespaceException - if the URI is not registered.

registerNamespace

public void registerNamespace(String prefix,
                              String uri)
                       throws NamespaceException,
                              UnsupportedRepositoryOperationException,
                              AccessDeniedException,
                              RepositoryException

Specified by:
registerNamespace in interface NamespaceRegistry
Throws:
NamespaceException
UnsupportedRepositoryOperationException
AccessDeniedException
RepositoryException

unregisterNamespace

public void unregisterNamespace(String prefix)
                         throws NamespaceException,
                                UnsupportedRepositoryOperationException,
                                AccessDeniedException,
                                RepositoryException

Specified by:
unregisterNamespace in interface NamespaceRegistry
Throws:
NamespaceException
UnsupportedRepositoryOperationException
AccessDeniedException
RepositoryException

getPrefixes

public String[] getPrefixes()
                     throws RepositoryException

Specified by:
getPrefixes in interface NamespaceRegistry
Throws:
RepositoryException

getURIs

public String[] getURIs()
                 throws RepositoryException

Specified by:
getURIs in interface NamespaceRegistry
Throws:
RepositoryException

getURI

public String getURI(String prefix)
              throws NamespaceException
Returns the URI to which the given prefix is mapped.

Specified by:
getURI in interface NamespaceRegistry
Specified by:
getURI in interface NamespaceResolver
Parameters:
prefix - namespace prefix
Returns:
the namespace URI to which the given prefix is mapped.
Throws:
NamespaceException - if the prefix is unknown.

getPrefix

public String getPrefix(String uri)
                 throws NamespaceException
Returns the prefix which is mapped to the given URI.

Specified by:
getPrefix in interface NamespaceRegistry
Specified by:
getPrefix in interface NamespaceResolver
Parameters:
uri - namespace URI
Returns:
the prefix mapped to the given URI.
Throws:
NamespaceException - if the URI is unknown.

externalRemap

public void externalRemap(String oldPrefix,
                          String newPrefix,
                          String uri)
                   throws RepositoryException
Called when a namespace has been externally remapped.

Specified by:
externalRemap in interface NamespaceEventListener
Parameters:
oldPrefix - old prefix. if null this is a fresh mapping
newPrefix - new prefix. if null this is an unmap operation
uri - uri to map prefix to
Throws:
RepositoryException - if an error occurs


Copyright © 2004-2008 The Apache Software Foundation. All Rights Reserved.