org.apache.jackrabbit.session
Class SessionNamespaceRegistry

java.lang.Object
  extended byorg.apache.jackrabbit.session.SessionNamespaceRegistry
All Implemented Interfaces:
NamespaceRegistry

public final class SessionNamespaceRegistry
extends Object
implements NamespaceRegistry


Constructor Summary
SessionNamespaceRegistry(NamespaceRegistry registry)
          Creates a local namespace registry based on the given global namespace registry.
 
Method Summary
 String getPrefix(String uri)
          Returns the prefix that is mapped to the given namespace URI.
 String[] getPrefixes()
          Returns the currently mapped namespace prefixes.
 String getURI(String prefix)
          Returns the namespace URI that is mapped to the given prefix.
 String[] getURIs()
          Returns the registered namespace URIs.
 void registerNamespace(String prefix, String uri)
          Creates a local namespace mapping.
 void unregisterNamespace(String prefix)
          Not implemented.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionNamespaceRegistry

public SessionNamespaceRegistry(NamespaceRegistry registry)
Creates a local namespace registry based on the given global namespace registry. The local namespace mappings are initially empty.

Parameters:
registry - global namespace registry
Method Detail

registerNamespace

public void registerNamespace(String prefix,
                              String uri)
                       throws NamespaceException,
                              RepositoryException
Creates a local namespace mapping. See the JCR specification for the details of this rather complex operation.

This method implements the specified semantics of the Session.setNamespacePrefix method. Session implementations can use this method as follows:

     NamespaceRegistry registry = new SessionNamespaceRegistry(
             getWorkspace().getNamespaceRegistry());

     public void setNamespacePrefix(String prefix, String uri)
             throws NamespaceException, RepositoryException {
         return registry.registerNamespace(prefix, uri);
     }
 

Specified by:
registerNamespace in interface NamespaceRegistry
Parameters:
prefix - namespace prefix
uri - namespace URI
Throws:
NamespaceException - if the given namespace mapping is invalid
RepositoryException - on repository errors
See Also:
NamespaceRegistry.registerNamespace(String, String), Session.setNamespacePrefix(String, String)

unregisterNamespace

public void unregisterNamespace(String prefix)
                         throws UnsupportedRepositoryOperationException
Not implemented. It is not possible to unregister namespaces from a session, you need to access the global namespace registry directly.

Specified by:
unregisterNamespace in interface NamespaceRegistry
Parameters:
prefix - namespace prefix
Throws:
UnsupportedRepositoryOperationException - always thrown

getPrefixes

public String[] getPrefixes()
                     throws RepositoryException
Returns the currently mapped namespace prefixes. The returned set contains all locally mapped prefixes and those global prefixes that have not been hidden by local mappings.

This method implements the specified semantics of the Session.getNamespacePrefixes method. Session implementations can use this method as follows:

     NamespaceRegistry registry = new SessionNamespaceRegistry(
             getWorkspace().getNamespaceRegistry());

     public String getNamespacePrefixes() throws RepositoryException {
         return registry.getPrefixes();
     }
 

Specified by:
getPrefixes in interface NamespaceRegistry
Returns:
namespace prefixes
Throws:
RepositoryException - on repository errors
See Also:
NamespaceRegistry.getPrefixes(), Session.getNamespacePrefixes()

getURIs

public String[] getURIs()
                 throws RepositoryException
Returns the registered namespace URIs. This method call is simply forwarded to the underlying global namespace registry as it is not possible to locally add new namespace URIs.

Specified by:
getURIs in interface NamespaceRegistry
Returns:
namespace URIs
Throws:
RepositoryException - on repository errors
See Also:
NamespaceRegistry.getURIs()

getURI

public String getURI(String prefix)
              throws NamespaceException,
                     RepositoryException
Returns the namespace URI that is mapped to the given prefix. Returns the local namespace mapping if the prefix is locally mapped, otherwise falls back to the underlying global namespace registry unless the prefix has been hidden by local namespace mappings.

This method implements the specified semantics of the Session.getNamespaceURI method. Session implementations can use this method as follows:

     NamespaceRegistry registry = new SessionNamespaceRegistry(
             getWorkspace().getNamespaceRegistry());

     public String getNamespaceURI(String prefix)
             throws NamespaceException, RepositoryException {
         return registry.getURI(prefix);
     }
 

Specified by:
getURI in interface NamespaceRegistry
Parameters:
prefix - namespace prefix
Returns:
namespace URI
Throws:
NamespaceException - if the prefix is not registered or currently visible
RepositoryException - on repository errors
See Also:
NamespaceRegistry.getURI(String), Session.getNamespaceURI(String)

getPrefix

public String getPrefix(String uri)
                 throws NamespaceException,
                        RepositoryException
Returns the prefix that is mapped to the given namespace URI. Returns the local prefix if the namespace URI is locally mapped, otherwise falls back to the underlying global namespace registry.

This method implements the specified semantics of the Session.getNamespacePrefix method. Session implementations can use this method as follows:

     NamespaceRegistry registry = new SessionNamespaceRegistry(
             getWorkspace().getNamespaceRegistry());

     public String getNamespacePrefix(String uri)
             throws NamespaceException, RepositoryException {
         return registry.getPrefix(uri);
     }
 

Specified by:
getPrefix in interface NamespaceRegistry
Parameters:
uri - namespace URI
Returns:
namespace prefix
Throws:
NamespaceException - if the namespace URI is not registered
RepositoryException - on repository errors
See Also:
NamespaceRegistry.getPrefix(String), Session.getNamespacePrefix(String)


Copyright © 2004-2005 . All Rights Reserved.