As discussed in 6.3 Namespaces, above, each content repository has a single, persistent namespace registry represented by the NamespaceRegistry object accessed via Workspace.getNamespaceRegistry(). In level 1 only the NamespaceRegistry methods related to discovering information must function. In level 2 the NamespaceRegistry additionally allows for persistent changes to namespace mappings using the following methods:
javax.jcr. |
|
void |
registerNamespace(String prefix, String uri) Sets a one-to-one mapping between prefix and uri in the global namespace registry of this repository. Assigning a new prefix to a URI that already exists in the namespace registry erases the old prefix. In general this can be done, though an implementation is free to prevent particular remappings by throwing a NamespaceException. On the other hand, taking a prefix that is already assigned to a URI and re-assigning it to a new URI in effect unregisters that URI. Therefore, the same restrictions apply to this operation as to NamespaceRegistry.unregisterNamespace:
In a level 1 implementation, this method always throws an UnsupportedRepositoryOperationException. If the session associated with the Workspace object through which this registry was acquired does not have sufficient permissions to register the namespace an AccessDeniedException is thrown. A RepositoryException is thrown if another error occurs. |
void |
unregisterNamespace(String prefix) Removes a namespace mapping from the registry. The following restrictions apply:
In a level 1 implementation, this method always throws an UnsupportedRepositoryOperationException. If the session associated with the Workspace object through which this registry was acquired does not have sufficient permissions to unregister the namespace an AccessDeniedException is thrown. A RepositoryException is thrown if another error occurs. |
Once registered, a 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 universal managed, the combination of the per-repository namespace and the larger URI namespace can be used to provide universally 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, which cannot be removed through the API:
jcr -> http://www.jcp.org/jcr/1.0
Reserved for items defined within built-in node types. For example jcr:content.
nt -> http://www.jcp.org/jcr/nt/1.0
Reserved for the names of built-in primary node types.
mix -> http://www.jcp.org/jcr/mix/1.0
Reserved for the names of built-in mixin node types.
xml -> http://www.w3.org/XML/1998/namespace
Reserved for reasons of compatibility with XML.
“” (the empty prefix) -> “”(the empty URI)
This makes the default namespace the empty URI. In effect this means that a name without a prefix is identical in both its prefixed form and in its fully qualified form (i.e. when it is stored internally as URI plus local name). See 6.3.3 Internal Storage of Names and Values.