jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1345255 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/ oak-it/jcr/src/test/ja...
Date Fri, 01 Jun 2012 15:49:51 GMT
Author: jukka
Date: Fri Jun  1 15:49:50 2012
New Revision: 1345255

URL: http://svn.apache.org/viewvc?rev=1345255&view=rev
Log:
OAK-125: Improved namespace registry

Move NamespaceRegistryImpl to .oak.plugins.name.
Hook up the NamespaceValidator to the rest of the system.
Generate JCR exceptions based on NamespaceValidatorExceptions from the commit hook.
Various smaller improvements.

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
  (with props)
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java
  (contents, props changed)
      - copied, changed from r1345236, jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/namespace/NamespaceRegistryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidatorException.java
      - copied, changed from r1345236, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImplTest.java
  (contents, props changed)
      - copied, changed from r1345236, jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappings.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/namespace/NamespaceRegistryImpl.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/Namespaces.java
    jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
    jackrabbit/oak/trunk/oak-it/jcr/src/test/resources/repositoryStubImpl.properties
    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/WorkspaceImpl.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1345255&r1=1345254&r2=1345255&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
Fri Jun  1 15:49:50 2012
@@ -24,6 +24,7 @@ import org.apache.jackrabbit.oak.api.Con
 import org.apache.jackrabbit.oak.api.QueryEngine;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
 import org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider;
+import org.apache.jackrabbit.oak.plugins.name.NamespaceValidatorProvider;
 import org.apache.jackrabbit.oak.plugins.type.TypeValidatorProvider;
 import org.apache.jackrabbit.oak.query.QueryEngineImpl;
 import org.apache.jackrabbit.oak.security.authentication.LoginContextProviderImpl;
@@ -84,6 +85,7 @@ public class ContentRepositoryImpl imple
         if (validatorProvider == null) {
             List<ValidatorProvider> providers = new ArrayList<ValidatorProvider>();
             providers.add(new NameValidatorProvider());
+            providers.add(new NamespaceValidatorProvider());
             providers.add(new TypeValidatorProvider());
             validatorProvider = new CompositeValidatorProvider(providers);
         }

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java?rev=1345255&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
Fri Jun  1 15:49:50 2012
@@ -0,0 +1,184 @@
+/*
+ * 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.core;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.jackrabbit.oak.api.CoreValue;
+import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+public class ReadOnlyTree implements Tree {
+
+    /** Parent of this tree, {@code null} for the root */
+    private Tree parent;
+
+    /** Name of this tree */
+    private String name;
+
+    /** Underlying node state */
+    protected NodeState state;
+
+    public ReadOnlyTree(NodeState root) {
+        this(null, "", root);
+    }
+
+    private ReadOnlyTree(Tree parent, String name, NodeState state) {
+        assert name != null;
+        assert name.length() > 0 || parent == null;
+        assert state != null;
+        this.parent = parent;
+        this.name = name;
+        this.state = state;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String getPath() {
+        if (parent == null) {
+            return "";
+        } else {
+            return parent.getPath() + "/" + name;
+        }
+    }
+
+    @Override
+    public Tree getParent() {
+        return parent;
+    }
+
+    @Override
+    public PropertyState getProperty(String name) {
+        return state.getProperty(name);
+    }
+
+    @Override
+    public Status getPropertyStatus(String name) {
+        if (hasProperty(name)) {
+            return Status.EXISTING;
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public boolean hasProperty(String name) {
+        return state.getProperty(name) != null;
+    }
+
+    @Override
+    public long getPropertyCount() {
+        return state.getPropertyCount();
+    }
+
+    @Override
+    public Iterable<? extends PropertyState> getProperties() {
+        return state.getProperties();
+    }
+
+    @Override
+    public ReadOnlyTree getChild(String name) {
+        NodeState child = state.getChildNode(name);
+        if (child != null) {
+            return new ReadOnlyTree(this, name, child);
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public Status getChildStatus(String name) {
+        if (hasChild(name)) {
+            return Status.EXISTING;
+        } else {
+            return null;
+        }
+    }
+
+    @Override
+    public boolean hasChild(String name) {
+        return state.getChildNode(name) != null;
+    }
+
+    @Override
+    public long getChildrenCount() {
+        return state.getChildNodeCount();
+    }
+
+    @Override
+    public Iterable<Tree> getChildren() {
+        return new Iterable<Tree>() {
+            @Override
+            public Iterator<Tree> iterator() {
+                final Iterator<? extends ChildNodeEntry> iterator =
+                        state.getChildNodeEntries().iterator();
+                return new Iterator<Tree>() {
+                    @Override
+                    public boolean hasNext() {
+                        return iterator.hasNext();
+                    }
+                    @Override
+                    public Tree next() {
+                        ChildNodeEntry entry = iterator.next();
+                        return new ReadOnlyTree(
+                                ReadOnlyTree.this,
+                                entry.getName(), entry.getNodeState());
+                    }
+                    @Override
+                    public void remove() {
+                        throw new UnsupportedOperationException();
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public Tree addChild(String name) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public boolean removeChild(String name) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public PropertyState setProperty(String name, CoreValue value) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public PropertyState setProperty(String name, List<CoreValue> values) {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void removeProperty(String name) {
+        throw new UnsupportedOperationException();
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ReadOnlyTree.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java?rev=1345255&r1=1345254&r2=1345255&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java
Fri Jun  1 15:49:50 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.plugin
 
 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.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -33,7 +34,8 @@ public class NameValidatorProvider imple
 
     @Override
     public Validator getRootValidator(NodeState before, NodeState after) {
-        return new NameValidator(Namespaces.getNamespaceMap(after).keySet());
+        return new NameValidator(
+                Namespaces.getNamespaceMap(new ReadOnlyTree(after)).keySet());
     }
 
 }

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java
(from r1345236, jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/namespace/NamespaceRegistryImpl.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java&p1=jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/namespace/NamespaceRegistryImpl.java&r1=1345236&r2=1345255&rev=1345255&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/namespace/NamespaceRegistryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java
Fri Jun  1 15:49:50 2012
@@ -14,37 +14,45 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.jackrabbit.oak.jcr.namespace;
+package org.apache.jackrabbit.oak.plugins.name;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.plugins.name.NamespaceMappings;
+import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
 
 import javax.annotation.Nonnull;
 import javax.jcr.NamespaceException;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
-import java.util.Locale;
+
+import java.util.Arrays;
+import java.util.Map;
 
 /**
  * Implementation of {@link NamespaceRegistry} based on {@link NamespaceMappings}.
  */
 public class NamespaceRegistryImpl implements NamespaceRegistry {
 
-    private final NamespaceMappings nsMappings;
+    private final ContentSession session;
 
     public NamespaceRegistryImpl(ContentSession session) {
-        this.nsMappings = new NamespaceMappings(session);
+        this.session = session;
     }
 
     //--------------------------------------------------< NamespaceRegistry >---
+
     @Override
     public void registerNamespace(String prefix, String uri)
             throws RepositoryException {
-        checkMutablePrefix(prefix);
-        checkMutableURI(uri);
         try {
-            nsMappings.registerNamespace(prefix, uri);
+            Root root = session.getCurrentRoot();
+            Tree namespaces = getOrCreate(root, "jcr:system", "jcr:namespaces");
+            namespaces.setProperty(
+                    prefix, session.getCoreValueFactory().createValue(uri));
+            root.commit();
+        } catch (NamespaceValidatorException e) {
+            throw e.getNamespaceException();
         } catch (CommitFailedException e) {
             throw new RepositoryException(
                     "Failed to register namespace mapping from "
@@ -54,24 +62,47 @@ public class NamespaceRegistryImpl imple
 
     @Override
     public void unregisterNamespace(String prefix) throws RepositoryException {
-        checkMutablePrefix(prefix);
         try {
-            if (nsMappings.getURI(prefix) == null) {
-                throw new NamespaceException("prefix '" + prefix + "' is unused");
+            Root root = session.getCurrentRoot();
+            Tree namespaces = getOrCreate(root, "jcr:system", "jcr:namespaces");
+            if (namespaces.hasProperty(prefix)) {
+                namespaces.removeProperty(prefix);
+            } else {
+                throw new NamespaceException(
+                        "Namespace mapping from " + prefix + " to "
+                        + getURI(prefix) + " can not be unregistered");
             }
-            nsMappings.unregisterNamespace(prefix);
+            root.commit();
+        } catch (NamespaceValidatorException e) {
+            throw e.getNamespaceException();
         } catch (CommitFailedException e) {
             throw new RepositoryException(
-                    "Failed to unregister a namespace mapping with prefix "
+                    "Failed to unregister namespace mapping for prefix "
                     + prefix, e);
         }
     }
 
+    private Tree getOrCreate(Root root, String... path) {
+        Tree tree = root.getTree("/");
+        for (String name : path) {
+            Tree child = tree.getChild(name);
+            if (child == null) {
+                child = tree.addChild(name);
+            }
+            tree = child;
+        }
+        return tree;
+    }
+
     @Override
     @Nonnull
     public String[] getPrefixes() throws RepositoryException {
         try {
-            return nsMappings.getPrefixes();
+            Tree root = session.getCurrentRoot().getTree("/");
+            Map<String, String> map = Namespaces.getNamespaceMap(root);
+            String[] prefixes = map.keySet().toArray(new String[map.size()]);
+            Arrays.sort(prefixes);
+            return prefixes;
         } catch (RuntimeException e) {
             throw new RepositoryException(
                     "Failed to retrieve registered namespace prefixes", e);
@@ -82,7 +113,11 @@ public class NamespaceRegistryImpl imple
     @Nonnull
     public String[] getURIs() throws RepositoryException {
         try {
-            return nsMappings.getURIs();
+            Tree root = session.getCurrentRoot().getTree("/");
+            Map<String, String> map = Namespaces.getNamespaceMap(root);
+            String[] uris = map.values().toArray(new String[map.size()]);
+            Arrays.sort(uris);
+            return uris;
         } catch (RuntimeException e) {
             throw new RepositoryException(
                     "Failed to retrieve registered namespace URIs", e);
@@ -93,7 +128,9 @@ public class NamespaceRegistryImpl imple
     @Nonnull
     public String getURI(String prefix) throws RepositoryException {
         try {
-            String uri = nsMappings.getURI(prefix);
+            Tree root = session.getCurrentRoot().getTree("/");
+            Map<String, String> map = Namespaces.getNamespaceMap(root);
+            String uri = map.get(prefix);
             if (uri == null) {
                 throw new NamespaceException(
                         "No namespace registered for prefix " + prefix);
@@ -110,12 +147,15 @@ public class NamespaceRegistryImpl imple
     @Nonnull
     public String getPrefix(String uri) throws RepositoryException {
         try {
-            String prefix = nsMappings.getPrefix(uri);
-            if (prefix == null) {
-                throw new NamespaceException(
-                        "No namespace registered for uri: " + uri);
+            Tree root = session.getCurrentRoot().getTree("/");
+            Map<String, String> map = Namespaces.getNamespaceMap(root);
+            for (Map.Entry<String, String> entry : map.entrySet()) {
+                if (entry.getValue().equals(uri)) {
+                    return entry.getKey();
+                }
             }
-            return prefix;
+            throw new NamespaceException(
+                        "No namespace prefix registered for URI " + uri);
         } catch (RuntimeException e) {
             throw new RepositoryException(
                     "Failed to retrieve the namespace prefix for URI "
@@ -123,17 +163,4 @@ public class NamespaceRegistryImpl imple
         }
     }
 
-    private static void checkMutablePrefix(String prefix) throws NamespaceException {
-        if ("jcr".equals(prefix) || "nt".equals(prefix) || "mix".equals(prefix) || "sv".equals(prefix)
-                || prefix.toLowerCase(Locale.ENGLISH).startsWith("xml")) {
-            throw new NamespaceException("Can not map or remap prefix '" + prefix + '\'');
-        }
-    }
-
-    private static void checkMutableURI(String uri) throws NamespaceException {
-        if ("http://www.jcp.org/jcr/1.0".equals(uri) || "http://www.jcp.org/jcr/nt/1.0".equals(uri)
-                || "http://www.jcp.org/jcr/mix/1.0".equals(uri) || "http://www.jcp.org/jcr/sv/1.0".equals(uri))
{
-            throw new NamespaceException("Can not map or remap uri '" + uri + '\'');
-        }
-    }
 }

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java?rev=1345255&r1=1345254&r2=1345255&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
Fri Jun  1 15:49:50 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.plugins.name;
 
+import java.util.Locale;
 import java.util.Map;
 
 import javax.jcr.PropertyType;
@@ -39,15 +40,17 @@ class NamespaceValidator extends Default
             throws CommitFailedException {
         String prefix = after.getName();
         if (map.containsKey(prefix)) {
-            throw new CommitFailedException(
-                    "Namespace mapping already registered: " + prefix);
+            throw new NamespaceValidatorException(
+                    "Namespace mapping already registered", prefix);
         } else if (Namespaces.isValidPrefix(prefix)) {
             if (after.isArray()
                     || after.getValue().getType() != PropertyType.STRING) {
-                throw new CommitFailedException(
-                        "Invalid namespace mapping: " + prefix);
+                throw new NamespaceValidatorException(
+                        "Invalid namespace mapping", prefix);
+            } else if (prefix.toLowerCase(Locale.ENGLISH).startsWith("xml")) {
+                throw new NamespaceValidatorException(
+                        "XML prefixes are reserved", prefix);
             }
-            
         }
     }
 
@@ -55,8 +58,8 @@ class NamespaceValidator extends Default
     public void propertyChanged(PropertyState before, PropertyState after)
             throws CommitFailedException {
         if (map.containsKey(after.getName())) {
-            throw new CommitFailedException(
-                    "Namespace modification not allowed: " + after.getName());
+            throw new NamespaceValidatorException(
+                    "Namespace modification not allowed", after.getName());
         }
     }
 
@@ -64,8 +67,7 @@ class NamespaceValidator extends Default
     public void propertyDeleted(PropertyState before)
             throws CommitFailedException {
         if (map.containsKey(before.getName())) {
-            throw new CommitFailedException(
-                    "Namespace removal not allowed: " + before.getName());
+            // TODO: Check whether this namespace is still used in content
         }
     }
 

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidatorException.java
(from r1345236, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidatorException.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidatorException.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java&r1=1345236&r2=1345255&rev=1345255&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NameValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidatorException.java
Fri Jun  1 15:49:50 2012
@@ -16,24 +16,18 @@
  */
 package org.apache.jackrabbit.oak.plugins.name;
 
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;
-import org.apache.jackrabbit.oak.spi.commit.Validator;
-import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
-
-/**
- * Validator service that checks that all node and property names as well
- * as any name values are syntactically valid and that any namespace prefixes
- * are properly registered.
- */
-@Component
-@Service(ValidatorProvider.class)
-public class NameValidatorProvider implements ValidatorProvider {
-
-    @Override
-    public Validator getRootValidator(NodeState before, NodeState after) {
-        return new NameValidator(Namespaces.getNamespaceMap(after).keySet());
+import javax.jcr.NamespaceException;
+
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+
+class NamespaceValidatorException extends CommitFailedException {
+
+    public NamespaceValidatorException(String message, String prefix) {
+        super(message + ": " + prefix);
+    }
+
+    public NamespaceException getNamespaceException() {
+        return new NamespaceException(getMessage(), this);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidatorProvider.java?rev=1345255&r1=1345254&r2=1345255&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidatorProvider.java
Fri Jun  1 15:49:50 2012
@@ -16,10 +16,9 @@
  */
 package org.apache.jackrabbit.oak.plugins.name;
 
-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.spi.commit.SubtreeValidator;
 import org.apache.jackrabbit.oak.spi.commit.Validator;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
@@ -36,9 +35,8 @@ public class NamespaceValidatorProvider 
 
     @Override
     public Validator getRootValidator(NodeState before, NodeState after) {
-        Map<String, String> map = Namespaces.getNamespaceMap(before);
-        Validator validator =
-                new NamespaceValidator(map);
+        Validator validator = new NamespaceValidator(
+                Namespaces.getNamespaceMap(new ReadOnlyTree(before)));
         return new SubtreeValidator(validator, "jcr:system", "jcr:namespaces");
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/Namespaces.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/Namespaces.java?rev=1345255&r1=1345254&r2=1345255&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/Namespaces.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/Namespaces.java
Fri Jun  1 15:49:50 2012
@@ -23,7 +23,7 @@ import javax.jcr.PropertyType;
 
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
-import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.api.Tree;
 
 /**
  * Internal static utility class for managing the persisted namespace registry.
@@ -46,17 +46,14 @@ class Namespaces {
 
         // TODO: see OAK-74
         defaults.put("rep", "internal");
-
-        // test prefix TODO: remove again.
-        defaults.put("test", "http://apache.jackrabbit.org/oak/0.1");
     }
 
-    public static Map<String, String> getNamespaceMap(NodeState root) {
+    public static Map<String, String> getNamespaceMap(Tree root) {
         Map<String, String> map = new HashMap<String, String>(defaults);
 
-        NodeState system = root.getChildNode("jcr:system");
+        Tree system = root.getChild("jcr:system");
         if (system != null) {
-            NodeState namespaces = system.getChildNode("jcr:namespaces");
+            Tree namespaces = system.getChild("jcr:namespaces");
             if (namespaces != null) {
                 for (PropertyState property : namespaces.getProperties()) {
                     String prefix = property.getName();

Copied: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImplTest.java
(from r1345236, jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImplTest.java?p2=jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImplTest.java&p1=jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java&r1=1345236&r2=1345255&rev=1345255&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceMappingsTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImplTest.java
Fri Jun  1 15:49:50 2012
@@ -17,44 +17,43 @@
 package org.apache.jackrabbit.oak.plugins.name;
 
 import static org.junit.Assert.assertEquals;
+
+import javax.jcr.GuestCredentials;
+import javax.jcr.NamespaceRegistry;
+
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
 import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
 import org.junit.Test;
 
-import javax.jcr.GuestCredentials;
-
-public class NamespaceMappingsTest {
+public class NamespaceRegistryImplTest {
 
     @Test
     public void testMappings() throws Exception {
         ContentRepository repository = new ContentRepositoryImpl();
-        ContentSession session = repository.login(new GuestCredentials(), "default");
-        NamespaceMappings r = new NamespaceMappings(session);
+        ContentSession session = repository.login(new GuestCredentials(), null);
+        NamespaceRegistry r = new NamespaceRegistryImpl(session);
+
+        assertEquals("", r.getURI(""));
+        assertEquals("http://www.jcp.org/jcr/1.0", r.getURI("jcr"));
+        assertEquals("http://www.jcp.org/jcr/nt/1.0", r.getURI("nt"));
+        assertEquals("http://www.jcp.org/jcr/mix/1.0", r.getURI("mix"));
+        assertEquals("http://www.w3.org/XML/1998/namespace", r.getURI("xml"));
+
+        assertEquals("", r.getPrefix(""));
+        assertEquals("jcr", r.getPrefix("http://www.jcp.org/jcr/1.0"));
+        assertEquals("nt", r.getPrefix("http://www.jcp.org/jcr/nt/1.0"));
+        assertEquals("mix", r.getPrefix("http://www.jcp.org/jcr/mix/1.0"));
+        assertEquals("xml", r.getPrefix("http://www.w3.org/XML/1998/namespace"));
 
         r.registerNamespace("p", "n");
         assertEquals(r.getURI("p"), "n");
         assertEquals(r.getPrefix("n"), "p");
 
-        r.registerNamespace("p", "n2");
-        assertEquals(r.getURI("p"), "n2");
-        assertEquals(r.getPrefix("n2"), "p");
-
-        r.registerNamespace("p2", "n");
-        assertEquals(r.getURI("p2"), "n");
-        assertEquals(r.getPrefix("n"), "p2");
-        assertEquals(r.getURI("p"), "n2");
-        assertEquals(r.getPrefix("n2"), "p");
-
         r.registerNamespace("p2", "n2");
         assertEquals(r.getURI("p2"), "n2");
         assertEquals(r.getPrefix("n2"), "p2");
 
-        r.registerNamespace("p", "n");
-        assertEquals(r.getURI("p2"), "n2");
-        assertEquals(r.getPrefix("n2"), "p2");
-        assertEquals(r.getURI("p"), "n");
-        assertEquals(r.getPrefix("n"), "p");
     }
 
 }

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java?rev=1345255&r1=1345254&r2=1345255&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
(original)
+++ jackrabbit/oak/trunk/oak-it/jcr/src/test/java/org/apache/jackrabbit/oak/jcr/TestContentLoader.java
Fri Jun  1 15:49:50 2012
@@ -38,6 +38,8 @@ public class TestContentLoader {
     private static final String ENCODING = "UTF-8";
 
     public void loadTestContent(Session session) throws RepositoryException, IOException
{
+        session.getWorkspace().getNamespaceRegistry().registerNamespace(
+                "test", "http://www.apache.org/jackrabbit/test");
 
         Node data = getOrAddNode(session.getRootNode(), "testdata");
         addPropertyTestData(getOrAddNode(data, "property"));

Modified: jackrabbit/oak/trunk/oak-it/jcr/src/test/resources/repositoryStubImpl.properties
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/jcr/src/test/resources/repositoryStubImpl.properties?rev=1345255&r1=1345254&r2=1345255&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/jcr/src/test/resources/repositoryStubImpl.properties (original)
+++ jackrabbit/oak/trunk/oak-it/jcr/src/test/resources/repositoryStubImpl.properties Fri Jun
 1 15:49:50 2012
@@ -41,8 +41,8 @@ javax.jcr.tck.propertyvalue2=value2
 javax.jcr.tck.workspacename=default
 
 # namespace configuration
-# javax.jcr.tck.namespaces=test
-# javax.jcr.tck.namespaces.test=http://www.apache.org/jackrabbit/test
+javax.jcr.tck.namespaces=test
+javax.jcr.tck.namespaces.test=http://www.apache.org/jackrabbit/test
 
 # retention and hold
 javax.jcr.tck.holdname=hold

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=1345255&r1=1345254&r2=1345255&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
Fri Jun  1 15:49:50 2012
@@ -26,7 +26,6 @@ import org.apache.jackrabbit.oak.api.Res
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.commons.PathUtils;
-import org.apache.jackrabbit.oak.jcr.namespace.NamespaceRegistryImpl;
 import org.apache.jackrabbit.oak.jcr.value.ValueFactoryImpl;
 import org.apache.jackrabbit.oak.namepath.AbstractNameMapper;
 import org.apache.jackrabbit.oak.namepath.NameMapper;
@@ -63,7 +62,6 @@ public class SessionDelegate {
     private final Repository repository;
     private final ContentSession contentSession;
     private final ValueFactoryImpl valueFactory;
-    private final NamespaceRegistry nsRegistry;
     private final Workspace workspace;
     private final Session session;
     private final Root root;
@@ -77,8 +75,7 @@ public class SessionDelegate {
         this.repository = repository;
         this.contentSession = contentSession;
         this.valueFactory = new ValueFactoryImpl(contentSession.getCoreValueFactory(), namePathMapper);
-        this.nsRegistry = new NamespaceRegistryImpl(contentSession);
-        this.workspace = new WorkspaceImpl(this, nsRegistry);
+        this.workspace = new WorkspaceImpl(this);
         this.session = new SessionImpl(this);
         this.root = contentSession.getCurrentRoot();
     }
@@ -389,7 +386,7 @@ public class SessionDelegate {
         @CheckForNull
         protected String getJcrPrefix(String oakPrefix) {
             try {
-                String ns = nsRegistry.getURI(oakPrefix);
+                String ns = getWorkspace().getNamespaceRegistry().getURI(oakPrefix);
                 return session.getNamespacePrefix(ns);
             } catch (RepositoryException e) {
                 log.debug("Could not get JCR prefix for OAK prefix " + oakPrefix);
@@ -402,7 +399,7 @@ public class SessionDelegate {
         protected String getOakPrefix(String jcrPrefix) {
             try {
                 String ns = getSession().getNamespaceURI(jcrPrefix);
-                return nsRegistry.getPrefix(ns);
+                return getWorkspace().getNamespaceRegistry().getPrefix(ns);
             } catch (RepositoryException e) {
                 log.debug("Could not get OAK prefix for JCR prefix " + jcrPrefix);
                 return null;
@@ -413,7 +410,7 @@ public class SessionDelegate {
         @CheckForNull
         protected String getOakPrefixFromURI(String uri) {
             try {
-                return nsRegistry.getPrefix(uri);
+                return getWorkspace().getNamespaceRegistry().getPrefix(uri);
             } catch (RepositoryException e) {
                 log.debug("Could not get OAK prefix for URI " + uri);
                 return null;

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java?rev=1345255&r1=1345254&r2=1345255&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
Fri Jun  1 15:49:50 2012
@@ -21,6 +21,7 @@ import org.apache.jackrabbit.api.securit
 import org.apache.jackrabbit.oak.jcr.nodetype.NodeTypeManagerImpl;
 import org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl;
 import org.apache.jackrabbit.oak.jcr.security.privileges.PrivilegeManagerImpl;
+import org.apache.jackrabbit.oak.plugins.name.NamespaceRegistryImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.ContentHandler;
@@ -51,15 +52,13 @@ public class WorkspaceImpl implements Ja
     private static final Logger log = LoggerFactory.getLogger(WorkspaceImpl.class);
 
     private final SessionDelegate sessionDelegate;
-    private final NamespaceRegistry nsRegistry;
     private final NodeTypeManager nodeTypeManager;
     private final QueryManagerImpl queryManager;
 
-    public WorkspaceImpl(SessionDelegate sessionDelegate, NamespaceRegistry nsRegistry)
+    public WorkspaceImpl(SessionDelegate sessionDelegate)
             throws RepositoryException {
 
         this.sessionDelegate = sessionDelegate;
-        this.nsRegistry = nsRegistry;
         this.nodeTypeManager = new NodeTypeManagerImpl(sessionDelegate.getValueFactory(),
sessionDelegate.getNamePathMapper());
         this.queryManager = new QueryManagerImpl(sessionDelegate);
     }
@@ -137,7 +136,7 @@ public class WorkspaceImpl implements Ja
 
     @Override
     public NamespaceRegistry getNamespaceRegistry() {
-        return nsRegistry;
+        return new NamespaceRegistryImpl(sessionDelegate.getContentSession());
     }
 
     @Override



Mime
View raw message