jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1328695 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ oak-jcr/src/test/java/org/apache...
Date Sat, 21 Apr 2012 15:39:52 GMT
Author: mduerig
Date: Sat Apr 21 15:39:52 2012
New Revision: 1328695

URL: http://svn.apache.org/viewvc?rev=1328695&view=rev
Log:
OAK-61: Implement JCR path handling
- Rename NamespaceRegistry in oak-core to NamespaceMappings to avoid naming conflict with
javax.jcr.NamespaceRegistry
- Add methods for enumerating namespaces to NamespaceMappings
- Use NamespaceMappings in oak-core in NamespaceRegistryImpl 
- Enable namespace test in RepositoryTest



Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamespaceMappings.java
      - copied, changed from r1328633, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamespaceRegistry.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamespaceRegistry.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NameSpaceRegistryTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NamespaceRegistryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamespaceMappings.java
(from r1328633, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamespaceRegistry.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamespaceMappings.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamespaceMappings.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamespaceRegistry.java&r1=1328633&r2=1328695&rev=1328695&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamespaceRegistry.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamespaceMappings.java
Sat Apr 21 15:39:52 2012
@@ -31,7 +31,7 @@ import java.util.Map;
  *
  * TODO: expose the relevant methods through the Oak API.
  */
-public class NamespaceRegistry {
+public class NamespaceMappings {
     private final Map<String, String> jcr2NsMap = new HashMap<String, String>();
     private final Map<String, String> ns2MkMap = new HashMap<String, String>();
     private final Map<String, String> mk2JcrMap = new HashMap<String, String>();
@@ -117,8 +117,24 @@ public class NamespaceRegistry {
     public String getJcrPrefix(String namespace) {
         return mk2JcrMap.get(ns2MkMap.get(namespace));
     }
-    
-    //------------------------------------------------------------< internal >--- 
+
+    /**
+     * Return the registered namespaces
+     * @return
+     */
+    public String[] getNamespaces() {
+        return jcr2NsMap.values().toArray(new String[jcr2NsMap.size()]);
+    }
+
+    /**
+     * Return the registered jcr prefixes
+     * @return
+     */
+    public String[] getJcrPrefixes() {
+        return jcr2NsMap.keySet().toArray(new String[jcr2NsMap.size()]);
+    }
+
+    //------------------------------------------------------------< internal >---
 
     /**
      * Retrieve the jcr prefix which maps to {@code mkPrefix} if any

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NameSpaceRegistryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NameSpaceRegistryTest.java?rev=1328695&r1=1328694&r2=1328695&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NameSpaceRegistryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NameSpaceRegistryTest.java
Sat Apr 21 15:39:52 2012
@@ -26,7 +26,7 @@ public class NameSpaceRegistryTest {
 
     @Test
     public void nameSpaceRegistry() {
-        NamespaceRegistry r = new NamespaceRegistry();
+        NamespaceMappings r = new NamespaceMappings();
 
         r.registerNamespace("p", "n");
         assertEquals(r.getNamespace("p"), "n");

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NamespaceRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NamespaceRegistryImpl.java?rev=1328695&r1=1328694&r2=1328695&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NamespaceRegistryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NamespaceRegistryImpl.java
Sat Apr 21 15:39:52 2012
@@ -16,54 +16,52 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import org.apache.jackrabbit.oak.namepath.NamespaceMappings;
+
 import javax.jcr.NamespaceException;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
-import java.util.HashMap;
-import java.util.Map;
 
 /**
  * A naive implementation of {@link NamespaceRegistry}, hard-wiring the
  * predefined namespaces for now.
+ * TODO use API only
  */
 public class NamespaceRegistryImpl implements NamespaceRegistry {
-    private final Map<String, String> map;
-
+    NamespaceMappings nsMappings = new NamespaceMappings();
+    
     public NamespaceRegistryImpl() {
-        map = new HashMap<String, String>();
-        map.put(PREFIX_EMPTY, NAMESPACE_EMPTY);
-        map.put(PREFIX_JCR, NAMESPACE_JCR);
-        map.put(PREFIX_MIX, NAMESPACE_MIX);
-        map.put(PREFIX_NT, NAMESPACE_NT);
-        map.put(PREFIX_XML, NAMESPACE_XML);
-        map.put("sv", "http://www.jcp.org/jcr/sv/1.0");
+        nsMappings.registerNamespace(PREFIX_EMPTY, NAMESPACE_EMPTY);
+        nsMappings.registerNamespace(PREFIX_JCR, NAMESPACE_JCR);
+        nsMappings.registerNamespace(PREFIX_MIX, NAMESPACE_MIX);
+        nsMappings.registerNamespace(PREFIX_NT, NAMESPACE_NT);
+        nsMappings.registerNamespace(PREFIX_XML, NAMESPACE_XML);
+        nsMappings.registerNamespace("sv", "http://www.jcp.org/jcr/sv/1.0");
     }
 
     @Override
     public void registerNamespace(String prefix, String uri) throws RepositoryException {
-        // TODO
-        throw new UnsupportedOperationException();
+        nsMappings.registerNamespace(prefix, uri);
     }
 
     @Override
     public void unregisterNamespace(String prefix) throws RepositoryException {
-        // TODO
-        throw new UnsupportedOperationException();
+        nsMappings.unregisterJcrPrefix(prefix);
     }
 
     @Override
     public String[] getPrefixes() throws RepositoryException {
-        return map.keySet().toArray(new String[map.size()]);
+        return nsMappings.getJcrPrefixes();
     }
 
     @Override
     public String[] getURIs() throws RepositoryException {
-        return map.values().toArray(new String[map.size()]);
+        return nsMappings.getNamespaces();
     }
 
     @Override
     public String getURI(String prefix) throws RepositoryException {
-        String result = map.get(prefix);
+        String result = nsMappings.getNamespace(prefix);
         if (result == null) {
             throw new NamespaceException();
         }
@@ -72,11 +70,10 @@ public class NamespaceRegistryImpl imple
 
     @Override
     public String getPrefix(String uri) throws RepositoryException {
-        for (Map.Entry<String, String> entry : map.entrySet()) {
-            if (entry.getValue().equals(uri)) {
-                return entry.getKey();
-            }
+        String result = nsMappings.getJcrPrefix(uri);
+        if (result == null) {
+            throw new NamespaceException();
         }
-        throw new NamespaceException();
+        return result;
     }
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1328695&r1=1328694&r2=1328695&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Sat Apr 21 15:39:52 2012
@@ -1312,7 +1312,6 @@ public class RepositoryTest extends Abst
         assertFalse(ntMgr.hasNodeType("foo"));
     }
 
-    @Ignore // TODO implement node type support
     @Test
     public void nameSpaceRegistry() throws RepositoryException {
         NamespaceRegistry nsReg = getSession().getWorkspace().getNamespaceRegistry();



Mime
View raw message