6.3.1 Namespace Registry

Each repository has a single, persistent namespace registry represented by the NamespaceRegistry object, accessed via Workspace.getNamespaceRegistry(). The following describes the methods of NamespaceRegistry supported in level 1. NamespaceRegistry also has other methods that are supported in level 2. In level 1 repositories these methods either do nothing or throw an exception. See 7.2 Adding and Deleting Namespaces for more details.

javax.jcr.
NamespaceRegistry

String[]

getPrefixes()

Returns an array holding all currently registered prefixes.

A RepositoryException is thrown if an error occurs.

String[]

getURIs()

Returns an array holding all currently registered URIs.

A RepositoryException is thrown if an error occurs.

String

getURI(String prefix)

Returns the URI to which the given prefix is mapped. If a mapping with the specified prefix does not exist, a NamespaceException is thrown.

A RepositoryException is thrown if another error occurs.

String

getPrefix(String uri)

Returns the prefix which is mapped to the given uri. If a mapping with the specified uri does not exist, a NamespaceException is thrown

A RepositoryException is thrown if another error occurs.


A registered prefix can be used in the name of any node or property in the repository. The prefix serves as shorthand for the URI to which it is mapped. Because the space of URIs is universally managed, the combination of the per-repository namespace and the larger URI namespace can be used to provide universal uniqueness of node or property names. Of course, just as in the case of XML namespaces, ensuring this universal uniqueness requires applications to map their application-specific prefixes to URIs that are uniquely identified with that particular application.

The namespace registry always contains at least the following built-in mappings:

In a level 1 repository there is no provision for adding new namespaces to the registry (or deleting namespaces from it), this functionality is part of level 2 (see 7.2 Adding and Deleting Namespaces). However, a level 1 implementation may provide any number of built-in namespaces, in addition to the five required ones listed above. As well, level 1 supports the temporary assignment of new prefixes to existing namespaces within the scope of a particular Session (see immediately below).