jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1336187 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: NodeImpl.java SessionDelegate.java SessionImpl.java WorkspaceImpl.java security/user/UserManagerImpl.java
Date Wed, 09 May 2012 13:21:48 GMT
Author: jukka
Date: Wed May  9 13:21:48 2012
New Revision: 1336187

URL: http://svn.apache.org/viewvc?rev=1336187&view=rev
Log:
OAK-89: Improve exception handling

Switch back to separate getOakPathOrThrow... methods

Modified:
    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/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java

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=1336187&r1=1336186&r2=1336187&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 May  9 13:21:48 2012
@@ -149,7 +149,7 @@ public class NodeImpl extends ItemImpl i
     public Node addNode(String relPath, String primaryNodeTypeName) throws RepositoryException
{
         checkStatus();
 
-        String oakPath = sessionDelegate.getOakPathOrThrow(relPath, new RepositoryException());
+        String oakPath = sessionDelegate.getOakPathOrThrow(relPath);
         String oakName = PathUtils.getName(oakPath);
         NodeDelegate parent = dlg.getChild(PathUtils.getParentPath(oakPath));
         if (parent == null) {
@@ -212,7 +212,7 @@ public class NodeImpl extends ItemImpl i
             p.remove();
             return p;
         } else {
-            String oakName = sessionDelegate.getOakPathOrThrow(jcrName, new RepositoryException());
+            String oakName = sessionDelegate.getOakPathOrThrow(jcrName);
             CoreValue oakValue = ValueConverter.toCoreValue(targetValue, sessionDelegate);
             return new PropertyImpl(dlg.setProperty(oakName, oakValue));
         }
@@ -243,7 +243,7 @@ public class NodeImpl extends ItemImpl i
             p.remove();
             return p;
         } else {
-            String oakName = sessionDelegate.getOakPathOrThrow(jcrName, new RepositoryException());
+            String oakName = sessionDelegate.getOakPathOrThrow(jcrName);
             List<CoreValue> oakValue = ValueConverter.toCoreValues(targetValues, sessionDelegate);
             return new PropertyImpl(dlg.setProperty(oakName, oakValue));
         }
@@ -364,7 +364,7 @@ public class NodeImpl extends ItemImpl i
     public Node getNode(String relPath) throws RepositoryException {
         checkStatus();
 
-        String oakPath = sessionDelegate.getOakPathOrThrow(relPath, new PathNotFoundException(relPath));
+        String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);
         NodeDelegate nd = dlg.getChild(oakPath);
         if (nd == null) {
             throw new PathNotFoundException(relPath);
@@ -418,7 +418,7 @@ public class NodeImpl extends ItemImpl i
     public Property getProperty(String relPath) throws RepositoryException {
         checkStatus();
 
-        String oakPath = sessionDelegate.getOakPathOrThrow(relPath, new PathNotFoundException());
+        String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);
         PropertyDelegate pd = dlg.getProperty(oakPath);
         if (pd == null) {
             throw new PathNotFoundException(relPath + " not found on " + getPath());
@@ -550,16 +550,16 @@ public class NodeImpl extends ItemImpl i
     public boolean hasNode(String relPath) throws RepositoryException {
         checkStatus();
 
-        String oakPath = sessionDelegate.getOakPathOrThrow(relPath, new RepositoryException());
-        return oakPath != null && dlg.getChild(oakPath) != null;
+        String oakPath = sessionDelegate.getOakPathOrThrow(relPath);
+        return dlg.getChild(oakPath) != null;
     }
 
     @Override
     public boolean hasProperty(String relPath) throws RepositoryException {
         checkStatus();
 
-        String oakPath = sessionDelegate.getOakPathOrThrow(relPath, new RepositoryException());
-        return oakPath != null && dlg.getProperty(oakPath) != null;
+        String oakPath = sessionDelegate.getOakPathOrThrow(relPath);
+        return dlg.getProperty(oakPath) != null;
     }
 
     @Override
@@ -656,7 +656,7 @@ public class NodeImpl extends ItemImpl i
         // TODO: END
 
         String jcrPrimaryType =
-                sessionDelegate.getOakPathOrThrow(Property.JCR_PRIMARY_TYPE, new RepositoryException());
+                sessionDelegate.getOakPathOrThrow(Property.JCR_PRIMARY_TYPE);
         CoreValue cv = ValueConverter.toCoreValue(nodeTypeName, PropertyType.NAME, sessionDelegate);
         dlg.setProperty(jcrPrimaryType, cv);
     }

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=1336187&r1=1336186&r2=1336187&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 May  9 13:21:48 2012
@@ -142,18 +142,52 @@ public class SessionDelegate {
         }
     }
 
-    public <T extends Throwable> String getOakPathOrThrow(String jcrPath, T t) throws
T {
+    /**
+     * Shortcut for {@code SessionDelegate.getNamePathMapper().getOakPath(jcrPath)}.
+     *
+     * @param jcrPath JCR path
+     * @return Oak path, or {@code null}
+     */
+    public String getOakPathOrNull(String jcrPath) {
+        return getNamePathMapper().getOakPath(jcrPath);
+    }
+
+    /**
+     * Returns the Oak path for the given JCR path, or throws a
+     * {@link PathNotFoundException} if the path can not be mapped.
+     *
+     * @param jcrPath JCR path
+     * @return Oak path
+     * @throws PathNotFoundException if the path can not be mapped
+     */
+    public String getOakPathOrThrowNotFound(String jcrPath)
+            throws PathNotFoundException {
         String oakPath = getOakPathOrNull(jcrPath);
-        if (oakPath != null || t == null) {
+        if (oakPath != null) {
             return oakPath;
         } else {
-            throw t;
+            throw new PathNotFoundException(jcrPath);
         }
     }
 
-    public String getOakPathOrNull(String jcrPath) {
-        return getNamePathMapper().getOakPath(jcrPath);
+    /**
+     * Returns the Oak path for the given JCR path, or throws a
+     * {@link RepositoryException} if the path can not be mapped.
+     *
+     * @param jcrPath JCR path
+     * @return Oak path
+     * @throws RepositoryException if the path can not be mapped
+     */
+    public String getOakPathOrThrow(String jcrPath)
+            throws RepositoryException {
+        String oakPath = getOakPathOrNull(jcrPath);
+        if (oakPath != null) {
+            return oakPath;
+        } else {
+            throw new RepositoryException("Invalid name or path: " + jcrPath);
+        }
     }
+
     //----------------------------------------------------------< Workspace >---
 
     public Workspace getWorkspace() {

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=1336187&r1=1336186&r2=1336187&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
Wed May  9 13:21:48 2012
@@ -26,7 +26,6 @@ import org.xml.sax.ContentHandler;
 
 import javax.jcr.Credentials;
 import javax.jcr.Node;
-import javax.jcr.PathNotFoundException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -122,8 +121,8 @@ public class SessionImpl extends Abstrac
     public void move(String srcAbsPath, String destAbsPath) throws RepositoryException {
         ensureIsAlive();
         dlg.move(
-                dlg.getOakPathOrThrow(srcAbsPath, new PathNotFoundException(srcAbsPath)),
-                dlg.getOakPathOrThrow(destAbsPath, new PathNotFoundException(destAbsPath)),
+                dlg.getOakPathOrThrowNotFound(srcAbsPath),
+                dlg.getOakPathOrThrowNotFound(destAbsPath),
                 true);
     }
 
@@ -161,7 +160,7 @@ public class SessionImpl extends Abstrac
         ensureIsAlive();
 
         @SuppressWarnings("unused")
-        String oakPath = dlg.getOakPathOrThrow(parentAbsPath, new PathNotFoundException(parentAbsPath));
+        String oakPath = dlg.getOakPathOrThrowNotFound(parentAbsPath);
 
         throw new UnsupportedRepositoryOperationException("TODO: Session.getImportContentHandler");
     }

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=1336187&r1=1336186&r2=1336187&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
Wed May  9 13:21:48 2012
@@ -27,7 +27,6 @@ import org.xml.sax.ContentHandler;
 import org.xml.sax.InputSource;
 
 import javax.jcr.NamespaceRegistry;
-import javax.jcr.PathNotFoundException;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
@@ -92,8 +91,8 @@ public class WorkspaceImpl implements Ja
         }
 
         sessionDelegate.copy(
-                sessionDelegate.getOakPathOrThrow(srcAbsPath, new PathNotFoundException(srcAbsPath)),
-                sessionDelegate.getOakPathOrThrow(destAbsPath, new PathNotFoundException(srcAbsPath)));
+                sessionDelegate.getOakPathOrThrowNotFound(srcAbsPath),
+                sessionDelegate.getOakPathOrThrowNotFound(destAbsPath));
     }
 
     @SuppressWarnings("deprecation")
@@ -112,8 +111,8 @@ public class WorkspaceImpl implements Ja
         ensureIsAlive();
 
         sessionDelegate.move(
-                sessionDelegate.getOakPathOrThrow(srcAbsPath, new PathNotFoundException(srcAbsPath)),
-                sessionDelegate.getOakPathOrThrow(destAbsPath, new PathNotFoundException(destAbsPath)),
+                sessionDelegate.getOakPathOrThrowNotFound(srcAbsPath),
+                sessionDelegate.getOakPathOrThrowNotFound(destAbsPath),
                 false);
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java?rev=1336187&r1=1336186&r2=1336187&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/user/UserManagerImpl.java
Wed May  9 13:21:48 2012
@@ -388,7 +388,7 @@ public class UserManagerImpl implements 
     }
 
     private String getInternalPath(Node node) throws RepositoryException {
-        return sessionDelegate.getOakPathOrThrow(node.getPath(), new RepositoryException());
+        return sessionDelegate.getOakPathOrThrow(node.getPath());
     }
 
 }
\ No newline at end of file



Mime
View raw message