jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1171521 - in /jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src: main/java/org/apache/jackrabbit/spi/commons/name/ test/java/org/apache/jackrabbit/spi/commons/name/
Date Fri, 16 Sep 2011 12:04:55 GMT
Author: mduerig
Date: Fri Sep 16 12:04:55 2011
New Revision: 1171521

URL: http://svn.apache.org/viewvc?rev=1171521&view=rev
Log:
Microkernel based Jackrabbit prototype (WIP) 
special case non default index elements in path 

Added:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePathWithIndex.java
Modified:
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractPath.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePath.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathBuilder.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathFactoryImpl.java
    jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractPath.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractPath.java?rev=1171521&r1=1171520&r2=1171521&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractPath.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractPath.java
Fri Sep 16 12:04:55 2011
@@ -146,7 +146,7 @@ abstract class AbstractPath implements P
     @Override
     public final Path resolve(Element element) {
         if (element.denotesName()) {
-            return new NamePath(this, element.getName(), element.getIndex());
+            return NamePath.create(this, element.getName(), element.getIndex());
         } else if (element.denotesParent()) {
             if (isAbsolute() && getDepth() == 0) {
                 throw new IllegalArgumentException(
@@ -178,7 +178,7 @@ abstract class AbstractPath implements P
         } else if (relative.denotesParent()) {
             return new ParentPath(this);
         } else if (relative.denotesName()) {
-            return new NamePath(this, relative.getName(), relative.getIndex());
+            return NamePath.create(this, relative.getName(), relative.getIndex());
         } else {
             throw new IllegalArgumentException(
                     "Unknown path type: " + relative);

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePath.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePath.java?rev=1171521&r1=1171520&r2=1171521&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePath.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePath.java
Fri Sep 16 12:04:55 2011
@@ -21,7 +21,7 @@ import org.apache.jackrabbit.spi.Path;
 
 import javax.jcr.RepositoryException;
 
-final class NamePath extends RelativePath {
+class NamePath extends RelativePath {
 
     /** Serial version UID */
     private static final long serialVersionUID = -2887665244213430950L;
@@ -31,24 +31,19 @@ final class NamePath extends RelativePat
      */
     private final Name name;
 
-    /**
-     * Optional index of the last path element. Set to
-     * {@link Path#INDEX_UNDEFINED} if not explicitly specified,
-     * otherwise contains the 1-based index.
-     */
-    private final int index;
+    public static NamePath create(Path parent, Name name, int index) {
+        return index == INDEX_UNDEFINED  
+            ? new NamePath(parent, name)
+            : new NamePathWithIndex(parent, name, index);
+    }
 
-    public NamePath(Path parent, Name name, int index) {
+    protected NamePath(Path parent, Name name) {
         super(parent);
         if (name == null) {
             throw new IllegalArgumentException("Name must not be null");
         }
-        if (index < 0) {
-            throw new IllegalArgumentException("Index must be non negative");
-        }
 
         this.name = name;
-        this.index = index;
     }
 
     @Override
@@ -67,11 +62,7 @@ final class NamePath extends RelativePat
 
     @Override
     protected String getElementString() {
-        if (index > Path.INDEX_DEFAULT) {
-            return name + "[" + index + ']';
-        } else {
-            return name.toString();
-        }
+        return name.toString();
     }
 
     @Override
@@ -79,20 +70,6 @@ final class NamePath extends RelativePat
         return name;
     }
 
-    @Override
-    public int getIndex() {
-        return index;
-    }
-
-    @Override
-    public int getNormalizedIndex() {
-        if (index == INDEX_UNDEFINED) {
-            return INDEX_DEFAULT;
-        } else {
-            return index;
-        }
-    }
-
     /**
      * Returns {@code true} as this path ends in a named element.
      *
@@ -125,7 +102,7 @@ final class NamePath extends RelativePat
             if (normalized.denotesCurrent()) {
                 normalized = null; // special case: ./a
             }
-            return new NamePath(normalized, name, index);
+            return create(normalized, name, getIndex());
         }
     }
 
@@ -134,7 +111,7 @@ final class NamePath extends RelativePat
         if (isCanonical()) {
             return this;
         } else if (parent != null) {
-            return new NamePath(parent.getCanonicalPath(), name, index);
+            return create(parent.getCanonicalPath(), name, getIndex());
         } else {
             throw new RepositoryException(
                     "There is no canonical representation of " + this);
@@ -149,7 +126,7 @@ final class NamePath extends RelativePat
     @Override
     public AbstractPath getLastElement() {
         if (parent != null) {
-            return new NamePath(null, name, index);
+            return create(null, name, getIndex());
         } else {
             return this;
         }

Added: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePathWithIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePathWithIndex.java?rev=1171521&view=auto
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePathWithIndex.java
(added)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePathWithIndex.java
Fri Sep 16 12:04:55 2011
@@ -0,0 +1,41 @@
+package org.apache.jackrabbit.spi.commons.name;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+
+class NamePathWithIndex extends NamePath {
+
+    /**
+     * Optional index of the last path element. Set to
+     * {@link Path#INDEX_UNDEFINED} if not explicitly specified,
+     * otherwise contains the 1-based index.
+     */
+    private final int index;
+
+    public NamePathWithIndex(Path parent, Name name, int index) {
+        super(parent, name);
+        if (index < 0) {
+            throw new IllegalArgumentException("Index must be non negative");
+        }
+
+        this.index = index;
+    }
+
+    @Override
+    protected String getElementString() {
+        return index > Path.INDEX_DEFAULT
+            ? super.getElementString() + '[' + index + ']'
+            : super.getElementString();
+    }
+
+    @Override
+    public int getIndex() {
+        return index;
+    }
+
+    @Override
+    public int getNormalizedIndex() {
+        return index;
+    }
+
+}

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathBuilder.java?rev=1171521&r1=1171520&r2=1171521&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathBuilder.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathBuilder.java
Fri Sep 16 12:04:55 2011
@@ -172,7 +172,7 @@ public final class PathBuilder {
      * @param index
      */
     public void addLast(Name name, int index) {
-        path = new NamePath(path, name, index);
+        path = NamePath.create(path, name, index);
     }
 
     /**

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathFactoryImpl.java?rev=1171521&r1=1171520&r2=1171521&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathFactoryImpl.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathFactoryImpl.java
Fri Sep 16 12:04:55 2011
@@ -72,7 +72,7 @@ public class PathFactoryImpl implements 
         if (RootPath.NAME.equals(name)) {
             throw new IllegalArgumentException();
         }
-        Path path = new NamePath(parent, name, index);
+        Path path = NamePath.create(parent, name, index);
         if (normalize) {
             return path.getNormalizedPath();
         } else {
@@ -121,7 +121,7 @@ public class PathFactoryImpl implements 
                 throw new IllegalArgumentException();
             }
         } else {
-            return new NamePath(null, name, index);
+            return NamePath.create(null, name, index);
         }
     }
 
@@ -132,7 +132,7 @@ public class PathFactoryImpl implements 
         } else if (element.denotesIdentifier()) {
             return new IdentifierPath(element.getIdentifier());
         } else if (element.denotesName()) {
-            return new NamePath(null, element.getName(), element.getIndex());
+            return NamePath.create(null, element.getName(), element.getIndex());
         } else if (element.denotesParent()) {
             return ParentPath.PARENT_PATH;
         } else if (element.denotesRoot()) {
@@ -158,7 +158,7 @@ public class PathFactoryImpl implements 
                 }
                 path = new IdentifierPath(element.getIdentifier());
             } else if (element.denotesName()) {
-                path = new NamePath(path, element.getName(), element.getIndex());
+                path = NamePath.create(path, element.getName(), element.getIndex());
             } else if (element.denotesParent()) {
                 if (path != null && path.isAbsolute() && path.getDepth()
== 0) {
                     throw new IllegalArgumentException();
@@ -215,7 +215,7 @@ public class PathFactoryImpl implements 
         } else if (name.equals(RootPath.NAME)) {
             return RootPath.ROOT_PATH;
         } else {
-            return new NamePath(null, name, Path.INDEX_UNDEFINED);
+            return NamePath.create(null, name, Path.INDEX_UNDEFINED);
         }
     }
 
@@ -236,7 +236,7 @@ public class PathFactoryImpl implements 
                     "Special path elements (root, '.' and '..') can not have an explicit
index: "
                     + name + '[' + index + ']');
         } else {
-            return new NamePath(null, name, index);
+            return NamePath.create(null, name, index);
         }
     }
 
@@ -271,7 +271,7 @@ public class PathFactoryImpl implements 
         int pos = elementString.indexOf('[');
         if (pos == -1) {
             Name name = factory.create(elementString);
-            return new NamePath(null, name, Path.INDEX_UNDEFINED);
+            return NamePath.create(null, name, Path.INDEX_UNDEFINED);
         }
         Name name = factory.create(elementString.substring(0, pos));
         int pos1 = elementString.indexOf(']');
@@ -283,7 +283,7 @@ public class PathFactoryImpl implements 
             if (index < 1) {
                 throw new IllegalArgumentException("invalid PathElement literal: " + elementString
+ " (index is 1-based)");
             }
-            return new NamePath(null, name, index);
+            return NamePath.create(null, name, index);
         } catch (NumberFormatException e) {
             throw new IllegalArgumentException("invalid PathElement literal: " + elementString
+ " (" + e.getMessage() + ')');
         }

Modified: jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java?rev=1171521&r1=1171520&r2=1171521&view=diff
==============================================================================
--- jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java
(original)
+++ jackrabbit/sandbox/jackrabbit-mk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java
Fri Sep 16 12:04:55 2011
@@ -58,8 +58,7 @@ public class ElementTest extends TestCas
     }
 
     public void testNameElement() {
-        Element element =
-            new NamePath(null, createName("test"), Path.INDEX_UNDEFINED);
+        Element element = NamePath.create(null, createName("test"), Path.INDEX_UNDEFINED);
         assertFalse(element.denotesCurrent());
         assertFalse(element.denotesIdentifier());
         assertTrue(element.denotesName());
@@ -72,7 +71,7 @@ public class ElementTest extends TestCas
     }
 
     public void testIndexedNameElement() {
-        Element element = new NamePath(null, createName("test"), 123);
+        Element element = NamePath.create(null, createName("test"), 123);
         assertFalse(element.denotesCurrent());
         assertFalse(element.denotesIdentifier());
         assertTrue(element.denotesName());



Mime
View raw message