You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by ju...@apache.org on 2009/05/27 12:11:15 UTC

svn commit: r779076 - in /jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name: NameFactoryImpl.java PathFactoryImpl.java

Author: jukka
Date: Wed May 27 10:11:15 2009
New Revision: 779076

URL: http://svn.apache.org/viewvc?rev=779076&view=rev
Log:
JCR-2123: Better name and path factory exception messages

Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameFactoryImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathFactoryImpl.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameFactoryImpl.java?rev=779076&r1=779075&r2=779076&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameFactoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameFactoryImpl.java Wed May 27 10:11:15 2009
@@ -46,10 +46,10 @@
     public Name create(String namespaceURI, String localName) throws IllegalArgumentException {
         // NOTE: an empty localName and/or URI is valid (e.g. the root node name)
         if (namespaceURI == null) {
-            throw new IllegalArgumentException("invalid namespaceURI specified");
+            throw new IllegalArgumentException("No namespaceURI specified");
         }
         if (localName == null) {
-            throw new IllegalArgumentException("invalid localName specified");
+            throw new IllegalArgumentException("No localName specified");
         }
         return (Name) cache.get(new NameImpl(namespaceURI, localName));
     }
@@ -59,17 +59,20 @@
      */
     public Name create(String nameString) throws IllegalArgumentException {
         if (nameString == null || "".equals(nameString)) {
-            throw new IllegalArgumentException("Invalid Name literal.");
+            throw new IllegalArgumentException("No Name literal specified");
         }
         if (nameString.charAt(0) != '{') {
-            throw new IllegalArgumentException("Invalid Name literal");
+            throw new IllegalArgumentException(
+                    "Invalid Name literal: " + nameString);
         }
         int i = nameString.indexOf('}');
         if (i == -1) {
-            throw new IllegalArgumentException("Invalid Name literal");
+            throw new IllegalArgumentException(
+                    "Invalid Name literal: " + nameString);
         }
         if (i == nameString.length() - 1) {
-            throw new IllegalArgumentException("Invalid Name literal");
+            throw new IllegalArgumentException(
+                    "Invalid Name literal: " + nameString);
         }
         return (Name) cache.get(new NameImpl(
                 nameString.substring(1, i), nameString.substring(i + 1)));
@@ -228,4 +231,5 @@
             return new NameImpl(namespaceURI, localName);
         }
     }
-}
\ No newline at end of file
+
+}

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathFactoryImpl.java?rev=779076&r1=779075&r2=779076&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathFactoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathFactoryImpl.java Wed May 27 10:11:15 2009
@@ -68,7 +68,8 @@
      */
     public Path create(Path parent, Path relPath, boolean normalize) throws IllegalArgumentException, RepositoryException {
         if (relPath.isAbsolute()) {
-            throw new IllegalArgumentException("relPath is not a relative path");
+            throw new IllegalArgumentException(
+                    "relPath is not a relative path: " + relPath);
         }
         List l = new ArrayList();
         l.addAll(Arrays.asList(parent.getElements()));
@@ -130,7 +131,8 @@
      */
     public Path create(Name name, int index) throws IllegalArgumentException {
         if (index < Path.INDEX_UNDEFINED) {
-            throw new IllegalArgumentException("Index must not be negative: " + index);
+            throw new IllegalArgumentException(
+                    "Index must not be negative: " + name + "[" + index + "]");
         }
         Path.Element elem = createElement(name, index);
         return new Builder(new Path.Element[]{elem}).getPath();
@@ -148,7 +150,7 @@
      */
     public Path create(String pathString) throws IllegalArgumentException {
         if (pathString == null || "".equals(pathString)) {
-            throw new IllegalArgumentException("Invalid Path literal");
+            throw new IllegalArgumentException("No Path literal specified");
         }
         // split into path elements
         int lastPos = 0;
@@ -191,14 +193,16 @@
      */
     public Path.Element createElement(Name name, int index) throws IllegalArgumentException {
         if (index < Path.INDEX_UNDEFINED) {
-            throw new IllegalArgumentException("The index may not be negative.");
+            throw new IllegalArgumentException(
+                    "The index may not be negative: " + name + "[" + index + "]");
         } else if (name == null) {
             throw new IllegalArgumentException("The name must not be null");
         } else if (name.equals(PARENT_NAME)
                 || name.equals(CURRENT_NAME)
                 || name.equals(ROOT_NAME)) {
             throw new IllegalArgumentException(
-                    "Special path elements (root, '.' and '..') can not have an explicit index.");
+                    "Special path elements (root, '.' and '..') can not have an explicit index: "
+                    + name + "[" + index + "]");
         } else {
             return new Element(name, index);
         }
@@ -358,7 +362,8 @@
                 return this;
             }
             if (denotesIdentifier()) {
-                throw new RepositoryException("Identifier-based path cannot be normalized.");                 
+                throw new RepositoryException(
+                        "Identifier-based path cannot be normalized: " + this);
             }
             LinkedList queue = new LinkedList();
             Path.Element last = PARENT_ELEMENT;
@@ -391,10 +396,12 @@
                 return this;
             }
             if (!isAbsolute()) {
-                throw new RepositoryException("Only an absolute path can be canonicalized.");
+                throw new RepositoryException(
+                        "Only an absolute path can be canonicalized: "  + this);
             }
             if (denotesIdentifier()) {
-                throw new RepositoryException("Identifier-based path cannot be canonicalized.");
+                throw new RepositoryException(
+                        "Identifier-based path cannot be canonicalized: " + this);
             }
             return getNormalizedPath();
         }
@@ -409,10 +416,14 @@
 
             // make sure both paths are absolute and not id-based
             if (!isAbsolute() || !other.isAbsolute()) {
-                throw new RepositoryException("Cannot compute relative path from relative paths");
+                throw new RepositoryException(
+                        "Cannot compute relative path from relative paths: "
+                        + this + " vs. " + other);
             }
             if (denotesIdentifier() || other.denotesIdentifier()) {
-                throw new RepositoryException("Cannot compute relative path from identifier-based paths");                
+                throw new RepositoryException(
+                        "Cannot compute relative path from identifier-based paths: "
+                        + this + " vs. " + other);
             }
 
             // make sure we're comparing canonical paths
@@ -458,7 +469,8 @@
          */
         public Path getAncestor(int degree) throws IllegalArgumentException, PathNotFoundException, RepositoryException {
             if (degree < 0) {
-                throw new IllegalArgumentException("degree must be >= 0");
+                throw new IllegalArgumentException(
+                        "degree must be >= 0: " + this);
             } else if (degree == 0) {
                 return getNormalizedPath();
             }
@@ -467,7 +479,8 @@
                 Path.Element[] normElems = getNormalizedPath().getElements();
                 int length = normElems.length - degree;
                 if (length < 1) {
-                    throw new PathNotFoundException("no such ancestor path of degree " + degree);
+                    throw new PathNotFoundException(
+                            "no ancestor at degree " + degree + ": " + this);
                 }
                 Path.Element[] ancestorElements = new Element[length];
                 System.arraycopy(normElems, 0, ancestorElements, 0, length);
@@ -507,7 +520,8 @@
          */
         public int getDepth() throws RepositoryException {
             if (denotesIdentifier()) {
-                throw new RepositoryException("Cannot determine depth of an identifier based path.");
+                throw new RepositoryException(
+                        "Cannot determine depth of an identifier based path: " + this);
             }
             int depth = ROOT_DEPTH;
             for (int i = 0; i < elements.length; i++) {
@@ -529,7 +543,9 @@
                 throw new IllegalArgumentException("null argument");
             }
             if (isAbsolute() != other.isAbsolute()) {
-                throw new IllegalArgumentException("Cannot compare a relative path with an absolute path");
+                throw new IllegalArgumentException(
+                        "Cannot compare a relative path with an absolute path: "
+                        + this + " vs. " + other);
             }
 
             if (getDepth() != other.getDepth()) {
@@ -558,7 +574,9 @@
             }
             // make sure both paths are either absolute or relative
             if (isAbsolute() != other.isAbsolute()) {
-                throw new IllegalArgumentException("Cannot compare a relative path with an absolute path");
+                throw new IllegalArgumentException(
+                        "Cannot compare a relative path with an absolute path: "
+                        + this + " vs. " + other);
             }
 
             int delta = other.getDepth() - getDepth();
@@ -586,7 +604,9 @@
                 throw new IllegalArgumentException();
             }
             if (!isNormalized()) {
-                throw new RepositoryException("Cannot extract sub-Path from a non-normalized Path.");
+                throw new RepositoryException(
+                        "Cannot extract sub-Path from a non-normalized Path: "
+                        + this);
             }
             Path.Element[] dest = new Path.Element[to-from];
             System.arraycopy(elements, from, dest, 0, dest.length);
@@ -1089,4 +1109,5 @@
             return new PathImpl(elements, isNormalized);
         }
     }
+
 }