jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1434122 - 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/main/java/org/apache/jackrabbit/oak/plugins/value/ oak-core/src/...
Date Wed, 16 Jan 2013 19:34:25 GMT
Author: angela
Date: Wed Jan 16 19:34:24 2013
New Revision: 1434122

URL: http://svn.apache.org/viewvc?rev=1434122&view=rev
Log:
OAK-553 : Add NameMapper#getValidOakName that never returns null

Modified:
    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
    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/namepath/NamePathMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionTemplateImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeTemplateImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/PropertyDefinitionTemplateImpl.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/value/ValueFactoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeManagerImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.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/NodeImpl.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/query/qom/QueryObjectModelFactoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java

Modified: 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=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
Wed Jan 16 19:34:24 2013
@@ -16,13 +16,13 @@
  */
 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;
+import javax.jcr.RepositoryException;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
  * Name mapper with no local prefix remappings. URI to prefix mappings
@@ -50,7 +50,7 @@ public abstract class GlobalNameMapper i
     }
 
     @Override @CheckForNull
-    public String getOakName(@Nonnull String jcrName) {
+    public String getOakNameOrNull(@Nonnull String jcrName) {
         if (jcrName.startsWith("{")) {
             return getOakNameFromExpanded(jcrName);
         }
@@ -58,6 +58,16 @@ public abstract class GlobalNameMapper i
         return jcrName;
     }
 
+    @Nonnull
+    @Override
+    public String getOakName(@Nonnull String jcrName) throws RepositoryException {
+        String oakName = getOakNameOrNull(jcrName);
+        if (oakName == null) {
+            throw new RepositoryException("Invalid jcr name " + jcrName);
+        }
+        return oakName;
+    }
+
     @Override
     public boolean hasSessionLocalMappings() {
         return false;

Modified: 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=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
Wed Jan 16 19:34:24 2013
@@ -16,13 +16,12 @@
  */
 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 static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
 /**
  * Name mapper with local namespace mappings.
  */
@@ -79,7 +78,7 @@ public abstract class LocalNameMapper ex
     }
 
     @Override @CheckForNull
-    public String getOakName(String jcrName) {
+    public String getOakNameOrNull(String jcrName) {
         checkNotNull(jcrName);
 
         if (jcrName.startsWith("{")) {

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=1434122&r1=1434121&r2=1434122&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
Wed Jan 16 19:34:24 2013
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.namepa
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
+import javax.jcr.RepositoryException;
 
 /**
  * TODO document
@@ -33,7 +34,20 @@ public interface NameMapper {
      * @return Oak name, or {@code null}
      */
     @CheckForNull
-    String getOakName(@Nonnull String jcrName);
+    String getOakNameOrNull(@Nonnull String jcrName);
+
+    /**
+     * Returns the Oak name for the specified JCR name. In contrast to
+     * {@link #getOakNameOrNull(String)} this method will throw a {@code RepositoryException}
+     * if the JCR name is invalid and cannot be resolved.
+     *
+     * @param jcrName The JCR name to be converted.
+     * @return A valid Oak name.
+     * @throws RepositoryException If the JCR name cannot be resolved.
+     */
+    @Nonnull
+    String getOakName(@Nonnull String jcrName) throws RepositoryException;
+
 
     /**
      * Returns whether the mapper has prefix remappings; when there aren't

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapper.java
Wed Jan 16 19:34:24 2013
@@ -17,6 +17,7 @@
 package org.apache.jackrabbit.oak.namepath;
 
 import javax.annotation.Nonnull;
+import javax.jcr.RepositoryException;
 
 /**
  * The {@code NamePathMapper} interface combines {@code NameMapper} and
@@ -33,7 +34,13 @@ public interface NamePathMapper extends 
     public class Default implements NamePathMapper {
 
         @Override
-        public String getOakName(String jcrName) {
+        public String getOakNameOrNull(String jcrName) {
+            return jcrName;
+        }
+
+        @Nonnull
+        @Override
+        public String getOakName(@Nonnull String jcrName) throws RepositoryException {
             return jcrName;
         }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
Wed Jan 16 19:34:24 2013
@@ -18,8 +18,8 @@ package org.apache.jackrabbit.oak.namepa
 
 import java.util.ArrayList;
 import java.util.List;
-
 import javax.annotation.Nonnull;
+import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.namepath.JcrPathParser.Listener;
@@ -52,8 +52,18 @@ public class NamePathMapperImpl implemen
 
     //---------------------------------------------------------< NameMapper >---
     @Override
-    public String getOakName(String jcrName) {
-        return nameMapper.getOakName(jcrName);
+    public String getOakNameOrNull(String jcrName) {
+        return nameMapper.getOakNameOrNull(jcrName);
+    }
+
+    @Nonnull
+    @Override
+    public String getOakName(@Nonnull String jcrName) throws RepositoryException {
+        String oakName = getOakNameOrNull(jcrName);
+        if (oakName == null) {
+            throw new RepositoryException("Invalid jcr name " + jcrName);
+        }
+        return oakName;
     }
 
     @Override
@@ -210,7 +220,7 @@ public class NamePathMapperImpl implemen
                     error("index > 1");
                     return false;
                 }
-                String p = nameMapper.getOakName(name);
+                String p = nameMapper.getOakNameOrNull(name);
                 if (p == null) {
                     error("Invalid name: " + name);
                     return false;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionTemplateImpl.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionTemplateImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeDefinitionTemplateImpl.java
Wed Jan 16 19:34:24 2013
@@ -72,7 +72,7 @@ class NodeDefinitionTemplateImpl
     @Override
     public void setName(String name) throws ConstraintViolationException {
         JcrNameParser.checkName(name, true);
-        this.name = mapper.getJcrName(mapper.getOakName(name));
+        this.name = mapper.getJcrName(mapper.getOakNameOrNull(name));
     }
 
     @Override
@@ -155,7 +155,7 @@ class NodeDefinitionTemplateImpl
         }
         else {
             JcrNameParser.checkName(name, false);
-            this.defaultPrimaryTypeName = mapper.getJcrName(mapper.getOakName(name));
+            this.defaultPrimaryTypeName = mapper.getJcrName(mapper.getOakNameOrNull(name));
         }
     }
 
@@ -198,7 +198,7 @@ class NodeDefinitionTemplateImpl
         String[] n = new String[names.length];
         for (String name : names) {
             JcrNameParser.checkName(name, false);
-            n[k++] = mapper.getJcrName(mapper.getOakName(name));
+            n[k++] = mapper.getJcrName(mapper.getOakNameOrNull(name));
         }
         this.requiredPrimaryTypeNames = n;
     }
@@ -207,11 +207,11 @@ class NodeDefinitionTemplateImpl
     public void addRequiredPrimaryType(String name) throws ConstraintViolationException {
         JcrNameParser.checkName(name, false);
         if (requiredPrimaryTypeNames == null) {
-            requiredPrimaryTypeNames = new String[] { mapper.getJcrName(mapper.getOakName(name))
};
+            requiredPrimaryTypeNames = new String[] { mapper.getJcrName(mapper.getOakNameOrNull(name))
};
         } else {
             String[] names = new String[requiredPrimaryTypeNames.length + 1];
             System.arraycopy(requiredPrimaryTypeNames, 0, names, 0, requiredPrimaryTypeNames.length);
-            names[requiredPrimaryTypeNames.length] = mapper.getJcrName(mapper.getOakName(name));
+            names[requiredPrimaryTypeNames.length] = mapper.getJcrName(mapper.getOakNameOrNull(name));
             requiredPrimaryTypeNames = names;
         }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeImpl.java
Wed Jan 16 19:34:24 2013
@@ -225,7 +225,7 @@ class NodeTypeImpl implements NodeType {
 
     @Override
     public boolean isNodeType(String nodeTypeName) {
-        String oakName = node.getNameMapper().getOakName(nodeTypeName);
+        String oakName = node.getNameMapper().getOakNameOrNull(nodeTypeName);
         return internalIsNodeType(oakName);
     }
 
@@ -499,8 +499,8 @@ class NodeTypeImpl implements NodeType {
     }
 
     private boolean matches(String childNodeName, String name) {
-        String oakChildName = node.getNameMapper().getOakName(childNodeName);
-        String oakName = node.getNameMapper().getOakName(name);
+        String oakChildName = node.getNameMapper().getOakNameOrNull(childNodeName);
+        String oakName = node.getNameMapper().getOakNameOrNull(name);
         // TODO need a better way to handle SNS
         return oakChildName != null && oakChildName.startsWith(oakName);
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeTemplateImpl.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeTemplateImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/NodeTypeTemplateImpl.java
Wed Jan 16 19:34:24 2013
@@ -164,7 +164,7 @@ final class NodeTypeTemplateImpl
     @Override
     public void setName(String name) throws ConstraintViolationException {
         JcrNameParser.checkName(name, false);
-        this.name = mapper.getJcrName(mapper.getOakName(name));
+        this.name = mapper.getJcrName(mapper.getOakNameOrNull(name));
     }
 
     @Override
@@ -219,7 +219,7 @@ final class NodeTypeTemplateImpl
         }
         else {
             JcrNameParser.checkName(name, false);
-            this.primaryItemName = mapper.getJcrName(mapper.getOakName(name));
+            this.primaryItemName = mapper.getJcrName(mapper.getOakNameOrNull(name));
         }
     }
 
@@ -237,7 +237,7 @@ final class NodeTypeTemplateImpl
         String[] n = new String[names.length];
         for (String name : names) {
             JcrNameParser.checkName(name, false);
-            n[k++] = mapper.getJcrName(mapper.getOakName(name));
+            n[k++] = mapper.getJcrName(mapper.getOakNameOrNull(name));
         }
         this.superTypeNames = n;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/PropertyDefinitionTemplateImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/PropertyDefinitionTemplateImpl.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/PropertyDefinitionTemplateImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/PropertyDefinitionTemplateImpl.java
Wed Jan 16 19:34:24 2013
@@ -68,7 +68,7 @@ class PropertyDefinitionTemplateImpl
     @Override
     public void setName(String name) throws ConstraintViolationException {
         JcrNameParser.checkName(name, true);
-        this.name = mapper.getJcrName(mapper.getOakName(name));
+        this.name = mapper.getJcrName(mapper.getOakNameOrNull(name));
     }
 
     @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=1434122&r1=1434121&r2=1434122&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
Wed Jan 16 19:34:24 2013
@@ -84,11 +84,7 @@ public abstract class ReadOnlyNodeTypeMa
      */
     @Nonnull
     protected final String getOakName(String jcrName) throws RepositoryException {
-        String oakName = getNamePathMapper().getOakName(jcrName);
-        if (oakName == null) {
-            throw new RepositoryException("Invalid JCR name " + jcrName);
-        }
-        return oakName;
+        return getNamePathMapper().getOakName(jcrName);
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueFactoryImpl.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueFactoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/value/ValueFactoryImpl.java
Wed Jan 16 19:34:24 2013
@@ -200,7 +200,7 @@ public class ValueFactoryImpl implements
                 case PropertyType.BOOLEAN:
                     return createValue(Conversions.convert(value).toBoolean());
                 case PropertyType.NAME:
-                    String oakName = namePathMapper.getOakName(value);
+                    String oakName = namePathMapper.getOakNameOrNull(value);
                     if (oakName == null) {
                         throw new ValueFormatException("Invalid name: " + value);
                     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeManagerImpl.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/privilege/PrivilegeManagerImpl.java
Wed Jan 16 19:34:24 2013
@@ -24,7 +24,6 @@ import java.util.Set;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.InvalidItemStateException;
-import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
 import javax.jcr.security.AccessControlException;
@@ -83,12 +82,7 @@ public class PrivilegeManagerImpl implem
         if (privilegeName == null || privilegeName.isEmpty()) {
             throw new RepositoryException("Invalid privilege name " + privilegeName);
         }
-        String oakName = getOakName(privilegeName);
-        if (oakName == null) {
-            throw new NamespaceException("Invalid privilege name " + privilegeName);
-        }
-
-        PrivilegeDefinition definition = new PrivilegeDefinitionImpl(oakName, isAbstract,
getOakNames(declaredAggregateNames));
+        PrivilegeDefinition definition = new PrivilegeDefinitionImpl(getOakName(privilegeName),
isAbstract, getOakNames(declaredAggregateNames));
         PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(getWriteRoot());
         writer.writeDefinition(definition);
 
@@ -98,6 +92,7 @@ public class PrivilegeManagerImpl implem
     }
 
     //------------------------------------------------------------< private >---
+    @Nonnull
     private Root getWriteRoot() throws UnsupportedRepositoryOperationException {
         if (root instanceof RootImpl) {
             return ((RootImpl) root).getLatest();
@@ -106,6 +101,7 @@ public class PrivilegeManagerImpl implem
         }
     }
 
+    @Nonnull
     private Set<String> getOakNames(String[] jcrNames) throws RepositoryException {
         Set<String> oakNames;
         if (jcrNames == null || jcrNames.length == 0) {
@@ -114,22 +110,19 @@ public class PrivilegeManagerImpl implem
             oakNames = new HashSet<String>(jcrNames.length);
             for (String jcrName : jcrNames) {
                 String oakName = getOakName(jcrName);
-                if (oakName == null) {
-                    throw new RepositoryException("Invalid name " + jcrName);
-                }
                 oakNames.add(oakName);
             }
         }
         return oakNames;
     }
 
-    @CheckForNull
-    String getOakName(String jcrName) {
+    @Nonnull
+    private String getOakName(String jcrName) throws RepositoryException {
         return namePathMapper.getOakName(jcrName);
     }
 
     @Nonnull
-    Privilege getPrivilege(PrivilegeDefinition definition) {
+    private Privilege getPrivilege(PrivilegeDefinition definition) {
         return new PrivilegeImpl(definition);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
Wed Jan 16 19:34:24 2013
@@ -308,7 +308,7 @@ public class NodeUtil {
 
     @Nonnull
     private String getOakName(String jcrName) {
-        String oakName = (jcrName == null) ? null : mapper.getOakName(jcrName);
+        String oakName = (jcrName == null) ? null : mapper.getOakNameOrNull(jcrName);
         if (oakName == null) {
             throw new IllegalArgumentException(new RepositoryException("Invalid name:" +
jcrName));
         }

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
Wed Jan 16 19:34:24 2013
@@ -16,14 +16,18 @@
  */
 package org.apache.jackrabbit.oak.namepath;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
-
-import org.junit.Test;
+import javax.jcr.RepositoryException;
 
 import com.google.common.collect.ImmutableMap;
+import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
 
 public class GlobalNameMapperTest {
 
@@ -42,57 +46,70 @@ public class GlobalNameMapperTest {
     };
 
     @Test
-    public void testEmptyName() {
+    public void testEmptyName() throws RepositoryException {
         assertEquals("", mapper.getJcrName(""));
+        assertEquals("", mapper.getOakNameOrNull(""));
         assertEquals("", mapper.getOakName(""));
     }
 
 
     @Test
-    public void testSimpleNames() {
-        assertEquals("foo", mapper.getOakName("foo"));
-        assertEquals("foo", mapper.getJcrName("foo"));
-        assertEquals("foo ", mapper.getOakName("foo "));
-        assertEquals("foo ", mapper.getJcrName("foo "));
-        assertEquals(" foo ", mapper.getOakName(" foo "));
-        assertEquals(" foo ", mapper.getJcrName(" foo "));
-        assertEquals("foo.bar", mapper.getOakName("foo.bar"));
-        assertEquals("foo.bar", mapper.getJcrName("foo.bar"));
-        assertEquals(".", mapper.getOakName("."));
-        assertEquals(".", mapper.getJcrName("."));
-        assertEquals("..", mapper.getOakName(".."));
-        assertEquals("..", mapper.getJcrName(".."));
-        assertEquals("/", mapper.getOakName("/"));
-        assertEquals("/", mapper.getJcrName("/"));
-        assertEquals(" ", mapper.getOakName(" "));
-        assertEquals(" ", mapper.getJcrName(" "));
+    public void testSimpleNames() throws RepositoryException {
+        List<String> simpleNames = new ArrayList<String>();
+        simpleNames.add("foo");
+        simpleNames.add(" foo ");
+        simpleNames.add("foo.bar");
+        simpleNames.add(".");
+        simpleNames.add("..");
+        simpleNames.add("/");
+        simpleNames.add(" ");
+
+        for (String name : simpleNames) {
+            assertEquals(name, mapper.getOakNameOrNull(name));
+            assertEquals(name, mapper.getOakName(name));
+            assertEquals(name, mapper.getJcrName(name));
+        }
     }
 
     @Test
-    public void testExpandedNames() {
-        assertEquals("foo", mapper.getOakName("{}foo"));
-        assertEquals("{foo", mapper.getOakName("{foo"));
-        assertEquals("{foo}", mapper.getOakName("{foo}"));
-        assertEquals("{0} foo", mapper.getOakName("{0} foo")); // OAK-509
-        assertEquals("{", mapper.getOakName("{"));
-        assertEquals("nt:base", mapper.getOakName("{http://www.jcp.org/jcr/nt/1.0}base"));
-        assertEquals("foo:bar", mapper.getOakName("{http://www.example.com/foo}bar"));
-        assertEquals("quu:bar", mapper.getOakName("{http://www.example.com/quu}bar"));
-        assertNull(mapper.getOakName("{http://www.example.com/bar}bar"));
+    public void testExpandedNames() throws RepositoryException {
+        Map<String, String> jcrToOak = new HashMap<String, String>();
+        jcrToOak.put("{}foo", "foo");
+        jcrToOak.put("{foo", "{foo");
+        jcrToOak.put("{foo}", "{foo}");
+        jcrToOak.put("{0} foo", "{0} foo"); // OAK-509
+        jcrToOak.put("{", "{");
+        jcrToOak.put("{http://www.jcp.org/jcr/nt/1.0}base", "nt:base");
+        jcrToOak.put("{http://www.example.com/foo}bar", "foo:bar");
+        jcrToOak.put("{http://www.example.com/quu}bar", "quu:bar");
+
+        for (String jcrName : jcrToOak.keySet()) {
+            assertEquals(jcrToOak.get(jcrName), mapper.getOakNameOrNull(jcrName));
+            assertEquals(jcrToOak.get(jcrName), mapper.getOakName(jcrName));
+        }
+
+        assertNull(mapper.getOakNameOrNull("{http://www.example.com/bar}bar"));
+        try {
+            mapper.getOakName("{http://www.example.com/bar}bar");
+            fail("RepositoryException expected");
+        } catch (RepositoryException e) {
+            // successs
+        }
     }
 
     @Test
-    public void testPrefixedNames() {
-        assertEquals("nt:base", mapper.getOakName("nt:base"));
-        assertEquals("nt:base", mapper.getJcrName("nt:base"));
-        assertEquals("foo: bar", mapper.getOakName("foo: bar"));
-        assertEquals("foo: bar", mapper.getJcrName("foo: bar"));
-        assertEquals("quu:bar ", mapper.getOakName("quu:bar "));
-        assertEquals("quu:bar ", mapper.getJcrName("quu:bar "));
-
+    public void testPrefixedNames() throws RepositoryException {
+        List<String> prefixed = new ArrayList<String>();
+        prefixed.add("nt:base");
+        prefixed.add("foo: bar");
+        prefixed.add("quu:bar ");
         // unknown prefixes are only captured by the NameValidator
-        assertEquals("unknown:bar", mapper.getOakName("unknown:bar"));
-        assertEquals("unknown:bar", mapper.getJcrName("unknown:bar"));
-    }
+        prefixed.add("unknown:bar");
 
+        for (String name : prefixed) {
+            assertEquals(name, mapper.getOakNameOrNull(name));
+            assertEquals(name, mapper.getOakName(name));
+            assertEquals(name, mapper.getJcrName(name));
+        }
+    }
 }

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=1434122&r1=1434121&r2=1434122&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
Wed Jan 16 19:34:24 2013
@@ -20,6 +20,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import javax.jcr.RepositoryException;
+
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.junit.Test;
 
@@ -68,8 +70,9 @@ public class NamePathMapperImplTest {
     }
 
     @Test
-    public void testEmptyName() {
+    public void testEmptyName() throws RepositoryException {
         assertEquals("", npMapper.getJcrName(""));
+        assertEquals("", npMapper.getOakNameOrNull(""));
         assertEquals("", npMapper.getOakName(""));
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Wed Jan 16 19:34:24 2013
@@ -253,7 +253,7 @@ public class NodeImpl<T extends NodeDele
                 if (ntName == null) {
                     DefinitionProvider dp = sessionDelegate.getDefinitionProvider();
                     try {
-                        String childName = sessionDelegate.getOakNameOrThrow(PathUtils.getName(relPath));
+                        String childName = sessionDelegate.getOakName(PathUtils.getName(relPath));
                         NodeDefinition def = dp.getDefinition(new NodeImpl<NodeDelegate>(parent),
childName);
                         ntName = def.getDefaultPrimaryTypeName();
                     } catch (RepositoryException e) {
@@ -864,7 +864,7 @@ public class NodeImpl<T extends NodeDele
     public boolean isNodeType(final String nodeTypeName) throws RepositoryException {
         checkStatus();
 
-        String oakName = sessionDelegate.getOakNameOrThrow(nodeTypeName);
+        String oakName = sessionDelegate.getOakName(nodeTypeName);
         return sessionDelegate.getEffectiveNodeTypeProvider().isNodeType(dlg.getTree(), oakName);
     }
 

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=1434122&r1=1434121&r2=1434122&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
Wed Jan 16 19:34:24 2013
@@ -278,13 +278,8 @@ public class SessionDelegate {
      * @throws RepositoryException if the name is invalid
      */
     @Nonnull
-    public String getOakNameOrThrow(String jcrName) throws RepositoryException {
-        String oakName = getNamePathMapper().getOakName(jcrName);
-        if (oakName != null) {
-            return oakName;
-        } else {
-            throw new RepositoryException("Invalid name: " + jcrName);
-        }
+    public String getOakName(String jcrName) throws RepositoryException {
+        return getNamePathMapper().getOakName(jcrName);
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/qom/QueryObjectModelFactoryImpl.java
Wed Jan 16 19:34:24 2013
@@ -228,7 +228,7 @@ public class QueryObjectModelFactoryImpl
         if (jcrName == null) {
             return null;
         }
-        return queryManager.getSessionDelegate().getOakNameOrThrow(jcrName);
+        return queryManager.getSessionDelegate().getOakName(jcrName);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java?rev=1434122&r1=1434121&r2=1434122&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java
Wed Jan 16 19:34:24 2013
@@ -100,7 +100,7 @@ public class VersionHistoryImpl extends 
     @Override
     public Version getVersionByLabel(String label)
             throws VersionException, RepositoryException {
-        String oakLabel = sessionDelegate.getOakNameOrThrow(label);
+        String oakLabel = sessionDelegate.getOakName(label);
         return new VersionImpl(dlg.getVersionByLabel(oakLabel));
     }
 



Mime
View raw message