jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1420139 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/ oak-jcr/src/main/j...
Date Tue, 11 Dec 2012 13:10:24 GMT
Author: jukka
Date: Tue Dec 11 13:10:22 2012
New Revision: 1420139

URL: http://svn.apache.org/viewvc?rev=1420139&view=rev
Log:
OAK-189: Swallowed exceptions

Replace SessionNameMapper with a LocalNameMapper class that doesn't need the JCR API.
Rename IdentityNameMapper to GlobalNameMapper for better alignment with the new LocalNameMapper
class.
Also clarify the nullability aspects of the NameMapper interface.

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/IdentityNameMapper.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionNameMapper.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefBuilderFactory.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java?rev=1420139&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
Tue Dec 11 13:10:22 2012
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.namepath;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Map;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+/**
+ * Name mapper with no local prefix remappings. URI to prefix mappings
+ * are read from the repository when needed.
+ */
+public abstract class GlobalNameMapper implements NameMapper {
+
+    @Override @Nonnull
+    public String getJcrName(@Nonnull String oakName) {
+        checkNotNull(oakName);
+        checkArgument(!oakName.startsWith(":")); // hidden name
+        checkArgument(!oakName.startsWith("{")); // expanded name
+        return oakName;
+    }
+
+    @Override @CheckForNull
+    public String getOakName(@Nonnull String jcrName) {
+        if (jcrName.startsWith("{")) {
+            return getOakNameFromExpanded(jcrName);
+        }
+
+        return jcrName;
+    }
+
+    @Override
+    public boolean hasSessionLocalMappings() {
+        return false;
+    }
+
+    @CheckForNull
+    protected String getOakNameFromExpanded(String expandedName) {
+        checkArgument(expandedName.startsWith("{"));
+
+        int brace = expandedName.indexOf('}', 1);
+        if (brace > 0) {
+            String uri = expandedName.substring(1, brace);
+            if (uri.isEmpty()) {
+                return expandedName.substring(2); // special case: {}name
+            } else if (uri.indexOf(':') != -1) {
+                // It's an expanded name, look up the namespace prefix
+                String oakPrefix = getOakPrefixOrNull(uri);
+                if (oakPrefix != null) {
+                    return oakPrefix + ':' + expandedName.substring(brace + 1);
+                }
+            }
+        }
+
+        return null; // invalid or unmapped name
+    }
+
+    protected abstract Map<String, String> getNamespaceMap();
+
+    @CheckForNull
+    protected String getOakPrefixOrNull(String uri) {
+        Map<String, String> namespaces = getNamespaceMap();
+        for (Map.Entry<String, String> entry : namespaces.entrySet()) {
+            if (uri.equals(entry.getValue())) {
+                return entry.getKey();
+            }
+        }
+        return null;
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java?rev=1420139&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
Tue Dec 11 13:10:22 2012
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.namepath;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Map;
+
+import javax.annotation.CheckForNull;
+
+/**
+ * Name mapper with local namespace mappings.
+ */
+public abstract class LocalNameMapper extends GlobalNameMapper {
+
+    private final Map<String, String> local;
+
+    public LocalNameMapper(Map<String, String> local) {
+        this.local = local;
+    }
+
+    @Override @CheckForNull
+    public String getJcrName(String oakName) {
+        checkNotNull(oakName);
+        checkArgument(!oakName.startsWith(":")); // hidden name
+        checkArgument(!oakName.startsWith("{")); // expanded name
+
+        if (hasSessionLocalMappings()) {
+            int colon = oakName.indexOf(':');
+            if (colon > 0) {
+                String oakPrefix = oakName.substring(0, colon);
+                String uri = getNamespaceMap().get(oakPrefix);
+                if (uri == null) {
+                    throw new IllegalStateException(
+                            "No namespace mapping found for " + oakName);
+                }
+
+                for (Map.Entry<String, String> entry : local.entrySet()) {
+                    if (uri.equals(entry.getValue())) {
+                        String jcrPrefix = entry.getKey();
+                        if (jcrPrefix.equals(oakPrefix)) {
+                            return oakName;
+                        } else {
+                            return jcrPrefix + oakName.substring(colon);
+                        }
+                    }
+                }
+
+                // local mapping not found for this URI, make sure there
+                // is no conflicting local mapping for the prefix
+                if (local.containsKey(oakPrefix)) {
+                    for (int i = 2; true; i++) {
+                        String jcrPrefix = oakPrefix + i;
+                        if (!local.containsKey(jcrPrefix)) {
+                            local.put(jcrPrefix, uri);
+                            return jcrPrefix + oakName.substring(colon);
+                        }
+                    }
+                }
+            }
+        }
+
+        return oakName;
+    }
+
+    @Override @CheckForNull
+    public String getOakName(String jcrName) {
+        checkNotNull(jcrName);
+
+        if (jcrName.startsWith("{")) {
+            return getOakNameFromExpanded(jcrName);
+        }
+
+        if (hasSessionLocalMappings()) {
+            int colon = jcrName.indexOf(':');
+            if (colon > 0) {
+                String jcrPrefix = jcrName.substring(0, colon);
+                String uri = local.get(jcrPrefix);
+                if (uri != null) {
+                    String oakPrefix = getOakPrefixOrNull(uri);
+                    if (jcrPrefix.equals(oakPrefix)) {
+                        return jcrName;
+                    } else if (oakPrefix != null) {
+                        return oakPrefix + jcrName.substring(colon);
+                    } else {
+                        return null;
+                    }
+                }
+
+                // Check that a global mapping is present and not remapped
+                uri = getNamespaceMap().get(jcrPrefix);
+                if (uri == null || local.values().contains(uri)) {
+                    return null;
+                }
+            }
+        }
+
+        return jcrName;
+    }
+
+    @Override
+    public boolean hasSessionLocalMappings() {
+        return !local.isEmpty();
+    }
+
+}

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java?rev=1420139&r1=1420138&r2=1420139&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
Tue Dec 11 13:10:22 2012
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.namepath;
 
 import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
 
 public interface NameMapper {
 
@@ -29,7 +30,7 @@ public interface NameMapper {
      * @return Oak name, or {@code null}
      */
     @CheckForNull
-    String getOakName(String jcrName);
+    String getOakName(@Nonnull String jcrName);
 
     /**
      * Returns whether the mapper has prefix remappings; when there aren't
@@ -49,6 +50,7 @@ public interface NameMapper {
      * @param oakName Oak name
      * @return JCR name
      */
-    @CheckForNull
-    String getJcrName(String oakName);
+    @Nonnull
+    String getJcrName(@Nonnull String oakName);
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefBuilderFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefBuilderFactory.java?rev=1420139&r1=1420138&r2=1420139&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefBuilderFactory.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/DefBuilderFactory.java
Tue Dec 11 13:10:22 2012
@@ -23,7 +23,7 @@ import javax.jcr.nodetype.NodeTypeTempla
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.cnd.DefinitionBuilderFactory;
 import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.namepath.IdentityNameMapper;
+import org.apache.jackrabbit.oak.namepath.GlobalNameMapper;
 import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants;
 import org.apache.jackrabbit.oak.plugins.name.Namespaces;
 
@@ -38,7 +38,12 @@ class DefBuilderFactory extends
 
     @Override
     public NodeTypeTemplateImpl newNodeTypeDefinitionBuilder() {
-        return new NodeTypeTemplateImpl(new IdentityNameMapper(root));
+        return new NodeTypeTemplateImpl(new GlobalNameMapper() {
+            @Override
+            protected Map<String, String> getNamespaceMap() {
+                return getNamespaceMapping();
+            }
+        });
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java?rev=1420139&r1=1420138&r2=1420139&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
Tue Dec 11 13:10:22 2012
@@ -254,7 +254,10 @@ public abstract class ReadOnlyNodeTypeMa
         String oakName = getOakName(nodeTypeName);
         NodeUtil node = new NodeUtil(tree);
         String ntName = node.getPrimaryNodeTypeName();
-        if (oakName.equals(ntName) || internalGetNodeType(ntName).isNodeType(nodeTypeName))
{
+        if (ntName == null) {
+            return false;
+        } else if (oakName.equals(ntName)
+                || internalGetNodeType(ntName).isNodeType(nodeTypeName)) {
             return true;
         }
         String[] mixinNames = node.getStrings(JcrConstants.JCR_MIXINTYPES);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidatorProvider.java?rev=1420139&r1=1420138&r2=1420139&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/TypeValidatorProvider.java
Tue Dec 11 13:10:22 2012
@@ -16,12 +16,15 @@
  */
 package org.apache.jackrabbit.oak.plugins.nodetype;
 
+import java.util.Map;
+
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.jackrabbit.oak.core.ReadOnlyTree;
-import org.apache.jackrabbit.oak.namepath.IdentityNameMapper;
+import org.apache.jackrabbit.oak.namepath.GlobalNameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
+import org.apache.jackrabbit.oak.plugins.name.Namespaces;
 import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -33,8 +36,13 @@ public class TypeValidatorProvider imple
     @Override
     public Validator getRootValidator(NodeState before, final NodeState after) {
         ReadOnlyNodeTypeManager ntm = new ValidatingNodeTypeManager(after);
-        ReadOnlyTree root = new ReadOnlyTree(after);
-        final NamePathMapper mapper = new NamePathMapperImpl(new IdentityNameMapper(root));
+        final ReadOnlyTree root = new ReadOnlyTree(after);
+        NamePathMapper mapper = new NamePathMapperImpl(new GlobalNameMapper() {
+            @Override
+            protected Map<String, String> getNamespaceMap() {
+                return Namespaces.getNamespaceMap(root);
+            }
+        });
         return new TypeValidator(ntm, root, mapper);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java?rev=1420139&r1=1420138&r2=1420139&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
Tue Dec 11 13:10:22 2012
@@ -17,20 +17,42 @@
 package org.apache.jackrabbit.oak.namepath;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableMap;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
 public class NamePathMapperImplTest {
-    private TestNameMapper mapper = new TestNameMapper(true);
+
+    private static final Map<String, String> GLOBAL = ImmutableMap.of(
+            "oak-jcr", "http://www.jcp.org/jcr/1.0",
+            "oak-nt", "http://www.jcp.org/jcr/nt/1.0",
+            "oak-mix", "http://www.jcp.org/jcr/mix/1.0",
+            "oak-foo", "http://www.example.com/foo",
+            "oak-quu", "http://www.example.com/quu");
+
+    private static final Map<String, String> LOCAL = ImmutableMap.of(
+            "jcr-jcr", "http://www.jcp.org/jcr/1.0",
+            "jcr-nt", "http://www.jcp.org/jcr/nt/1.0",
+            "jcr-mix", "http://www.jcp.org/jcr/mix/1.0",
+            "foo", "http://www.example.com/foo",
+            "quu", "http://www.example.com/quu");
+
+    private NameMapper mapper = new LocalNameMapper(LOCAL) {
+        @Override
+        protected Map<String, String> getNamespaceMap() {
+            return GLOBAL;
+        }
+    };
+
     private NamePathMapper npMapper = new NamePathMapperImpl(mapper);
 
     @Test
@@ -46,12 +68,6 @@ public class NamePathMapperImplTest {
     }
 
     @Test
-    public void testNullName() {
-        assertNull(npMapper.getJcrName(null));
-        assertNull(npMapper.getOakName(null));
-    }
-
-    @Test
     public void testEmptyName() {
         assertEquals("", npMapper.getJcrName(""));
         assertEquals("", npMapper.getOakName(""));
@@ -113,7 +129,12 @@ public class NamePathMapperImplTest {
 
     @Test
     public void testJcrToOakKeepIndexNoRemap() {
-        TestNameMapper mapper = new TestNameMapper(false); // a mapper with no prefix remappings
present
+        NameMapper mapper = new GlobalNameMapper() {
+            @Override
+            protected Map<String, String> getNamespaceMap() {
+                return GLOBAL;
+            }
+        };
         NamePathMapper npMapper = new NamePathMapperImpl(mapper);
 
         checkIdentical(npMapper, "/");
@@ -124,21 +145,21 @@ public class NamePathMapperImplTest {
 
     @Test
     public void testOakToJcr() {
-        assertEquals("/jcr-foo:bar", npMapper.getJcrPath("/foo:bar"));
-        assertEquals("/jcr-foo:bar/jcr-quu:qux", npMapper.getJcrPath("/foo:bar/quu:qux"));
-        assertEquals("jcr-foo:bar", npMapper.getJcrPath("foo:bar"));
+        assertEquals("/foo:bar", npMapper.getJcrPath("/oak-foo:bar"));
+        assertEquals("/foo:bar/quu:qux", npMapper.getJcrPath("/oak-foo:bar/oak-quu:qux"));
+        assertEquals("foo:bar", npMapper.getJcrPath("oak-foo:bar"));
         assertEquals(".", npMapper.getJcrPath(""));
 
         try {
             npMapper.getJcrPath("{http://www.jcp.org/jcr/nt/1.0}unstructured");
             fail("expanded name should not be accepted");
-        } catch (IllegalStateException expected) {
+        } catch (IllegalArgumentException expected) {
         }
 
         try {
             npMapper.getJcrPath("foobar/{http://www.jcp.org/jcr/1.0}content");
             fail("expanded name should not be accepted");
-        } catch (IllegalStateException expected) {
+        } catch (IllegalArgumentException expected) {
         }
     }
 
@@ -178,11 +199,6 @@ public class NamePathMapperImplTest {
         assertFalse(JcrPathParser.validate("/foo/../.."));
     }
 
-    private void checkEquals(NamePathMapper npMapper, String jcrPath) {
-        String oakPath = npMapper.getOakPathKeepIndex(jcrPath);
-        assertEquals(jcrPath, oakPath);
-    }
-    
     private void checkIdentical(NamePathMapper npMapper, String jcrPath) {
         String oakPath = npMapper.getOakPathKeepIndex(jcrPath);
         checkIdentical(jcrPath, oakPath);
@@ -194,49 +210,5 @@ public class NamePathMapperImplTest {
             fail("Expected the strings to be the same");
         }
     }
-    
-    private class TestNameMapper extends AbstractNameMapper {
-
-        private boolean withRemappings;
-        private Map<String, String> uri2oakprefix = new HashMap<String, String>();
-
-        public TestNameMapper(boolean withRemappings) {
-            this.withRemappings = withRemappings;
-
-            uri2oakprefix.put("", "");
-            uri2oakprefix.put("http://www.jcp.org/jcr/1.0", "jcr");
-            uri2oakprefix.put("http://www.jcp.org/jcr/nt/1.0", "nt");
-            uri2oakprefix.put("http://www.jcp.org/jcr/mix/1.0", "mix");
-            uri2oakprefix.put("http://www.w3.org/XML/1998/namespace", "xml");
-        }
 
-        @Override
-        protected String getJcrPrefix(String oakPrefix) {
-            if (oakPrefix.isEmpty() || !withRemappings) {
-                return oakPrefix;
-            } else {
-                return "jcr-" + oakPrefix;
-            }
-        }
-
-        @Override
-        protected String getOakPrefix(String jcrPrefix) {
-            if (jcrPrefix.isEmpty() || !withRemappings) {
-                return jcrPrefix;
-            } else {
-                return "oak-" + jcrPrefix;
-            }
-        }
-
-        @Override
-        protected String getOakPrefixFromURI(String uri) {
-            return (withRemappings ? "oak-" : "") + uri2oakprefix.get(uri);
-        }
-
-        @Override
-        public boolean hasSessionLocalMappings() {
-            return withRemappings;
-        }
-
-    }
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1420139&r1=1420138&r2=1420139&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Tue Dec 11 13:10:22 2012
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.jcr;
 
 import java.io.IOException;
+import java.util.Map;
 import java.util.concurrent.ScheduledExecutorService;
 
 import javax.annotation.CheckForNull;
@@ -45,9 +46,12 @@ import org.apache.jackrabbit.oak.api.Ses
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.namepath.LocalNameMapper;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
+import org.apache.jackrabbit.oak.plugins.name.Namespaces;
 import org.apache.jackrabbit.oak.plugins.nodetype.DefinitionProvider;
 import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeTypeProvider;
 import org.apache.jackrabbit.oak.plugins.observation.ObservationManagerImpl;
@@ -56,6 +60,8 @@ import org.apache.jackrabbit.oak.spi.sec
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.collect.Maps;
+
 import static com.google.common.base.Preconditions.checkNotNull;
 import static org.apache.jackrabbit.oak.namepath.PathResolvers.dotResolver;
 
@@ -68,7 +74,7 @@ public class SessionDelegate {
     private final ContentSession contentSession;
     private final ValueFactoryImpl valueFactory;
     private final Workspace workspace;
-    private final Session session;
+    private final SessionImpl session;
     private final Root root;
     private final boolean autoRefresh;
 
@@ -97,9 +103,17 @@ public class SessionDelegate {
 
         this.root = contentSession.getLatestRoot();
         this.workspace = new WorkspaceImpl(this);
-        this.session = new SessionImpl(this);
+
+        Map<String, String> namespaces = Maps.newHashMap();
+        NameMapper mapper = new LocalNameMapper(namespaces) {
+            @Override
+            protected Map<String, String> getNamespaceMap() {
+                return Namespaces.getNamespaceMap(root.getTree("/"));
+            }
+        };
+        this.session = new SessionImpl(this, namespaces);
         this.idManager = new IdentifierManager(root);
-        this.namePathMapper = new NamePathMapperImpl(new SessionNameMapper(this), idManager);
+        this.namePathMapper = new NamePathMapperImpl(mapper, idManager);
         this.valueFactory = new ValueFactoryImpl(root.getBlobFactory(), namePathMapper);
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1420139&r1=1420138&r2=1420139&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Tue Dec 11 13:10:22 2012
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.oak.jcr;
 
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Locale;
 import java.util.Map;
@@ -79,10 +78,11 @@ public class SessionImpl extends Abstrac
      * This map is only accessed from synchronized methods (see
      * <a href="https://issues.apache.org/jira/browse/JCR-1793">JCR-1793</a>).
      */
-    private final Map<String, String> namespaces = new HashMap<String, String>();
+    private final Map<String, String> namespaces;
 
-    SessionImpl(SessionDelegate dlg) {
+    SessionImpl(SessionDelegate dlg, Map<String, String> namespaces) {
         this.dlg = dlg;
+        this.namespaces = namespaces;
     }
 
     //------------------------------------------------------------< Session >---



Mime
View raw message