Author: rhauch
Date: 2008-10-27 23:00:46 -0400 (Mon, 27 Oct 2008)
New Revision: 589
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/NamespaceRegistry.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/BasicNamespaceRegistry.java
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java
Log:
DNA-230 - Enhance NamespaceRegistry with additional functionality
http://jira.jboss.com/jira/browse/DNA-230
Added an "unregister" method to the interface and implementations.
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/NamespaceRegistry.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/NamespaceRegistry.java 2008-10-27
19:25:17 UTC (rev 588)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/NamespaceRegistry.java 2008-10-28
03:00:46 UTC (rev 589)
@@ -85,6 +85,16 @@
String namespaceUri );
/**
+ * Unregister the namespace with the supplied URI.
+ *
+ * @param namespaceUri the namespace URI
+ * @return true if the namespace was removed, or false if the namespace was not
registered
+ * @throws IllegalArgumentException if the namespace URI is null
+ * @throws NamespaceException if there is a problem unregistering the namespace
+ */
+ boolean unregister( String namespaceUri );
+
+ /**
* Obtain the set of namespaces that are registered.
*
* @return the set of
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/BasicNamespaceRegistry.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/BasicNamespaceRegistry.java 2008-10-27
19:25:17 UTC (rev 588)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/properties/basic/BasicNamespaceRegistry.java 2008-10-28
03:00:46 UTC (rev 589)
@@ -180,6 +180,8 @@
lock.lock();
if (prefix == null) prefix = generatePrefix();
prefix = prefix.trim();
+ prefix = prefix.replaceFirst("^:+", "");
+ prefix = prefix.replaceFirst(":+$", "");
previousNamespaceForPrefix = this.namespacesByPrefix.put(prefix,
namespaceUri);
String previousPrefix = this.prefixesByNamespace.put(namespaceUri, prefix);
if (previousPrefix != null && !previousPrefix.equals(prefix)) {
@@ -196,7 +198,27 @@
/**
* {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.properties.NamespaceRegistry#unregister(java.lang.String)
*/
+ public boolean unregister( String namespaceUri ) {
+ CheckArg.isNotNull(namespaceUri, "namespaceUri");
+ namespaceUri = namespaceUri.trim();
+ Lock lock = this.registryLock.writeLock();
+ try {
+ lock.lock();
+ String prefix = this.prefixesByNamespace.remove(namespaceUri);
+ if (prefix == null) return false;
+ this.namespacesByPrefix.remove(prefix);
+ } finally {
+ lock.unlock();
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Set<String> getRegisteredNamespaceUris() {
Set<String> result = new HashSet<String>();
Lock lock = this.registryLock.readLock();
Modified:
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java
===================================================================
---
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java 2008-10-27
19:25:17 UTC (rev 588)
+++
trunk/dna-repository/src/main/java/org/jboss/dna/repository/util/JcrNamespaceRegistry.java 2008-10-28
03:00:46 UTC (rev 589)
@@ -143,7 +143,31 @@
/**
* {@inheritDoc}
+ *
+ * @see
org.jboss.dna.graph.properties.NamespaceRegistry#unregister(java.lang.String)
*/
+ public boolean unregister( String namespaceUri ) {
+ Session session = null;
+ try {
+ session = this.sessionFactory.createSession(this.repositoryWorkspaceName);
+ String prefix = session.getNamespacePrefix(namespaceUri);
+ javax.jcr.NamespaceRegistry registry =
session.getWorkspace().getNamespaceRegistry();
+ registry.unregisterNamespace(prefix);
+ } catch (javax.jcr.NamespaceException e) {
+ return false;
+ } catch (RepositoryException e) {
+ throw new NamespaceException(e);
+ } finally {
+ if (session != null) {
+ session.logout();
+ }
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public Set<String> getRegisteredNamespaceUris() {
Session session = null;
try {