jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r997384 - in /jackrabbit/trunk: jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/
Date Wed, 15 Sep 2010 16:17:42 GMT
Author: jukka
Date: Wed Sep 15 16:17:41 2010
New Revision: 997384

URL: http://svn.apache.org/viewvc?rev=997384&view=rev
Log:
JCR-2744: Avoid element arrays in PathImpl

Get rid of separate Path.Element objects by making AbstractPath implement both Path and Path.Element

Removed:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractElement.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentElement.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierElement.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentElement.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootElement.java
Modified:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractPath.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentPath.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierPath.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePath.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentPath.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathBuilder.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathFactoryImpl.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RelativePath.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootPath.java
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java
    jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/Path.java

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractPath.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractPath.java?rev=997384&r1=997383&r2=997384&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractPath.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractPath.java
Wed Sep 15 16:17:41 2010
@@ -23,7 +23,7 @@ import org.apache.jackrabbit.spi.Path;
 /**
  * Abstract base class for paths.
  */
-abstract class AbstractPath implements Path {
+abstract class AbstractPath implements Path, Path.Element {
 
     /** Serial version UID */
     private static final long serialVersionUID = 3018771833963770499L;
@@ -49,6 +49,16 @@ abstract class AbstractPath implements P
     }
 
     /**
+     * Returns <code>null</code>, except when overridden by the
+     * {@link IdentifierPath} subclass.
+     *
+     * @return <code>null</code>
+     */
+    public String getIdentifier() {
+        return null;
+    }
+
+    /**
      * Returns <code>false</code>, except when overridden by the
      * {@link RootPath} subclass.
      *
@@ -98,13 +108,17 @@ abstract class AbstractPath implements P
         return false;
     }
 
+    public Element getNameElement() {
+        return getLastElement();
+    }
+
     /**
      * Returns this path, except when overridden by the {@link RelativePath}
      * subclasses.
      *
      * @return this path
      */
-    public Path getLastElement() {
+    public AbstractPath getLastElement() {
         return this;
     }
 
@@ -120,7 +134,7 @@ abstract class AbstractPath implements P
 
     public final Path resolve(Element element) {
         if (element.denotesName()) {
-            return new NamePath(this, element);
+            return new NamePath(this, element.getName(), element.getIndex());
         } else if (element.denotesParent()) {
             if (isAbsolute() && getDepth() == 0) {
                 throw new IllegalArgumentException(
@@ -130,9 +144,9 @@ abstract class AbstractPath implements P
         } else if (element.denotesCurrent()) {
             return new CurrentPath(this);
         } else if (element.denotesRoot()) {
-            return RootPath.INSTANCE;
+            return RootPath.ROOT_PATH;
         } else if (element.denotesIdentifier()) {
-            return new IdentifierPath(element);
+            return new IdentifierPath(element.getIdentifier());
         } else {
             throw new IllegalArgumentException(
                     "Unknown path element type: " + element);
@@ -151,7 +165,7 @@ abstract class AbstractPath implements P
         } else if (relative.denotesParent()) {
             return new ParentPath(this);
         } else if (relative.denotesName()) {
-            return new NamePath(this, relative.getNameElement());
+            return new NamePath(this, relative.getName(), relative.getIndex());
         } else {
             throw new IllegalArgumentException(
                     "Unknown path type: " + relative);

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentPath.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentPath.java?rev=997384&r1=997383&r2=997384&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentPath.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentPath.java
Wed Sep 15 16:17:41 2010
@@ -31,6 +31,13 @@ final class CurrentPath extends Relative
     /** Serial version UID */
     private static final long serialVersionUID = 1729196441091297231L;
 
+    /** The current path "." */
+    public static final CurrentPath CURRENT_PATH = new CurrentPath(null);
+
+    /** Name of the current element */
+    public static final Name NAME =
+        NameFactoryImpl.getInstance().create(Name.NS_DEFAULT_URI, ".");
+
     public CurrentPath(Path parent) {
         super(parent);
     }
@@ -47,8 +54,12 @@ final class CurrentPath extends Relative
         }
     }
 
+    protected String getElementString() {
+        return NAME.getLocalName();
+    }
+
     public Name getName() {
-        return CurrentElement.INSTANCE.getName();
+        return NAME;
     }
 
     /**
@@ -92,26 +103,14 @@ final class CurrentPath extends Relative
         }
     }
 
-    public Element getNameElement() {
-        return CurrentElement.INSTANCE;
-    }
-
     /**
      * Returns the current path ".".
      *
      * @return current path
      */
     @Override
-    public Path getLastElement() {
-        return new CurrentPath(null);
-    }
-
-    public String getString() {
-        if (parent != null) {
-            return parent.getString() + Path.DELIMITER + ".";
-        } else {
-            return ".";
-        }
+    public AbstractPath getLastElement() {
+        return CURRENT_PATH;
     }
 
     //--------------------------------------------------------------< Object >

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierPath.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierPath.java?rev=997384&r1=997383&r2=997384&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierPath.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierPath.java
Wed Sep 15 16:17:41 2010
@@ -26,12 +26,11 @@ final class IdentifierPath extends Abstr
     /** Serial version UID */
     private static final long serialVersionUID = 1602959709588338642L;
 
-    private final Element element;
+    private final String identifier;
 
-    public IdentifierPath(Element element) {
-        assert element != null;
-        assert element.denotesIdentifier();
-        this.element = element;
+    public IdentifierPath(String identifier) {
+        assert identifier != null;
+        this.identifier = identifier;
     }
 
     /**
@@ -43,6 +42,10 @@ final class IdentifierPath extends Abstr
         return null;
     }
 
+    public String getIdentifier() {
+        return identifier;
+    }
+
     /**
      * Returns <code>true</code> as this is an identifier-based path.
      *
@@ -136,15 +139,11 @@ final class IdentifierPath extends Abstr
     }
 
     public Element[] getElements() {
-        return new Element[] { element };
-    }
-
-    public Element getNameElement() {
-        return element;
+        return new Element[] { getNameElement() };
     }
 
     public String getString() {
-        return element.getString();
+        return "[" + identifier + "]";
     }
 
     //--------------------------------------------------------------< Object >
@@ -152,16 +151,17 @@ final class IdentifierPath extends Abstr
     public final boolean equals(Object that) {
         if (this == that) {
             return true;
-        } else if (that instanceof IdentifierPath) {
-            IdentifierPath path = (IdentifierPath) that;
-            return element.equals(path.element);
+        } else if (that instanceof Path) {
+            Path path = (Path) that;
+            return path.denotesIdentifier()
+                && identifier.equals(path.getIdentifier());
         } else {
             return false;
         }
     }
 
     public final int hashCode() {
-        return element.hashCode();
+        return identifier.hashCode();
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePath.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePath.java?rev=997384&r1=997383&r2=997384&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePath.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NamePath.java
Wed Sep 15 16:17:41 2010
@@ -26,12 +26,24 @@ final class NamePath extends RelativePat
     /** Serial version UID */
     private static final long serialVersionUID = -2887665244213430950L;
 
-    private final Element element;
+    /**
+     * Name of the last path element.
+     */
+    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 NamePath(Path parent, Element element) {
+    public NamePath(Path parent, Name name, int index) {
         super(parent);
-        assert element.denotesName();
-        this.element = element;
+        assert name != null;
+        assert index >= 0;
+        this.name = name;
+        this.index = index;
     }
 
     protected int getDepthModifier() {
@@ -46,18 +58,30 @@ final class NamePath extends RelativePat
         }
     }
 
+    protected String getElementString() {
+        if (index > Path.INDEX_DEFAULT) {
+            return name + "[" + index + "]";
+        } else {
+            return name.toString();
+        }
+    }
+
     public Name getName() {
-        return element.getName();
+        return name;
     }
 
     @Override
     public int getIndex() {
-        return element.getIndex();
+        return index;
     }
 
     @Override
     public int getNormalizedIndex() {
-        return element.getNormalizedIndex();
+        if (index != INDEX_UNDEFINED) {
+            return index;
+        } else {
+            return INDEX_DEFAULT;
+        }
     }
 
     /**
@@ -89,7 +113,7 @@ final class NamePath extends RelativePat
             if (normalized.denotesCurrent()) {
                 normalized = null; // special case: ./a
             }
-            return new NamePath(normalized, element);
+            return new NamePath(normalized, name, index);
         }
     }
 
@@ -97,32 +121,24 @@ final class NamePath extends RelativePat
         if (isCanonical()) {
             return this;
         } else if (parent != null) {
-            return new NamePath(parent.getCanonicalPath(), element);
+            return new NamePath(parent.getCanonicalPath(), name, index);
         } else {
             throw new RepositoryException(
                     "There is no canonical representation of " + this);
         }
     }
 
-    public Element getNameElement() {
-        return element;
-    }
-
     /**
      * Returns the last element of this path.
      *
      * @return last element of this path
      */
     @Override
-    public Path getLastElement() {
-        return new NamePath(null, element);
-    }
-
-    public String getString() {
+    public AbstractPath getLastElement() {
         if (parent != null) {
-            return parent.getString() + Path.DELIMITER + element.getString();
+            return new NamePath(null, name, index);
         } else {
-            return element.getString();
+            return this;
         }
     }
 
@@ -135,7 +151,8 @@ final class NamePath extends RelativePat
         } else if (that instanceof Path) {
             Path path = (Path) that;
             return path.denotesName()
-                && element.equals(path.getNameElement()) 
+                && name.equals(path.getName())
+                && getNormalizedIndex() == path.getNormalizedIndex()
                 && super.equals(that);
         } else {
             return false;
@@ -144,7 +161,7 @@ final class NamePath extends RelativePat
 
     @Override
     public final int hashCode() {
-        return super.hashCode() * 37 + element.hashCode();
+        return super.hashCode() * 37 + name.hashCode() + getNormalizedIndex();
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentPath.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentPath.java?rev=997384&r1=997383&r2=997384&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentPath.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentPath.java
Wed Sep 15 16:17:41 2010
@@ -31,6 +31,13 @@ final class ParentPath extends RelativeP
     /** Serial version UID */
     private static final long serialVersionUID = -688611157827116290L;
 
+    /** The parent path ".." */
+    public static final ParentPath PARENT_PATH = new ParentPath(null);
+
+    /** Name of the parent element */
+    public static final Name NAME =
+        NameFactoryImpl.getInstance().create(Name.NS_DEFAULT_URI, "..");
+
     public ParentPath(Path parent) {
         super(parent);
     }
@@ -47,8 +54,12 @@ final class ParentPath extends RelativeP
         }
     }
 
+    protected String getElementString() {
+        return NAME.getLocalName();
+    }
+
     public Name getName() {
-        return ParentElement.INSTANCE.getName();
+        return NAME;
     }
 
     /**
@@ -101,26 +112,14 @@ final class ParentPath extends RelativeP
         }
     }
 
-    public Element getNameElement() {
-        return ParentElement.INSTANCE;
-    }
-
     /**
      * Returns the parent path "..".
      *
      * @return parent path
      */
     @Override
-    public Path getLastElement() {
-        return new ParentPath(null);
-    }
-
-    public String getString() {
-        if (parent != null) {
-            return parent.getString() + Path.DELIMITER + "..";
-        } else {
-            return "..";
-        }
+    public AbstractPath getLastElement() {
+        return PARENT_PATH;
     }
 
     //--------------------------------------------------------------< Object >

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathBuilder.java?rev=997384&r1=997383&r2=997384&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathBuilder.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/PathBuilder.java
Wed Sep 15 16:17:41 2010
@@ -89,9 +89,9 @@ public final class PathBuilder {
      */
     public void addRoot() {
         if (path != null) {
-            path = RootPath.INSTANCE.resolve(path);
+            path = RootPath.ROOT_PATH.resolve(path);
         } else {
-            path = RootPath.INSTANCE;
+            path = RootPath.ROOT_PATH;
         }
     }
 
@@ -172,7 +172,7 @@ public final class PathBuilder {
      * @param index
      */
     public void addLast(Name name, int index) {
-        path = new NamePath(path, NameElement.create(name, index));
+        path = new NamePath(path, name, index);
     }
 
     /**

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=997384&r1=997383&r2=997384&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 Sep 15 16:17:41 2010
@@ -32,14 +32,6 @@ public class PathFactoryImpl implements 
 
     private static PathFactory FACTORY = new PathFactoryImpl();
 
-    private static final String CURRENT_LITERAL = ".";
-    private static final String PARENT_LITERAL = "..";
-
-    private static final NameFactory NAME_FACTORY = NameFactoryImpl.getInstance();
-    private final static Name CURRENT_NAME = NAME_FACTORY.create(Name.NS_DEFAULT_URI, CURRENT_LITERAL);
-    private final static Name PARENT_NAME = NAME_FACTORY.create(Name.NS_DEFAULT_URI, PARENT_LITERAL);
-    private final static Name ROOT_NAME = NAME_FACTORY.create(Name.NS_DEFAULT_URI, "");
-
     private PathFactoryImpl() {}
 
     public static PathFactory getInstance() {
@@ -75,11 +67,10 @@ public class PathFactoryImpl implements 
      * @see PathFactory#create(Path, Name, int, boolean)
      */
     public Path create(Path parent, Name name, int index, boolean normalize) throws IllegalArgumentException,
RepositoryException {
-        if (ROOT_NAME.equals(name)) {
+        if (RootPath.NAME.equals(name)) {
             throw new IllegalArgumentException();
         }
-        NameElement element = NameElement.create(name, index);
-        Path path = new NamePath(parent, element).getNormalizedPath();
+        Path path = new NamePath(parent, name, index);
         if (normalize) {
             return path.getNormalizedPath();
         } else {
@@ -91,50 +82,56 @@ public class PathFactoryImpl implements 
      * @see PathFactory#create(Name)
      */
     public Path create(Name name) throws IllegalArgumentException {
-        return create(name, Path.INDEX_UNDEFINED);
+        if (name != null) {
+            return create(name, Path.INDEX_UNDEFINED);
+        } else {
+            throw new IllegalArgumentException("PathFactory.create(null)");
+        }
     }
 
     /**
      * @see PathFactory#create(Name, int)
      */
     public Path create(Name name, int index) throws IllegalArgumentException {
-        if (index < Path.INDEX_UNDEFINED) {
+        if (name == null) {
+            throw new IllegalArgumentException("PathFactory.create(null, index");
+        } else if (index < Path.INDEX_UNDEFINED) {
             throw new IllegalArgumentException(
                     "Index must not be negative: " + name + "[" + index + "]");
-        } else if (CURRENT_NAME.equals(name)) {
+        } else if (CurrentPath.NAME.equals(name)) {
             if (index == Path.INDEX_UNDEFINED) {
-                return new CurrentPath(null);
+                return CurrentPath.CURRENT_PATH;
             } else {
                 throw new IllegalArgumentException();
             }
-        } else if (PARENT_NAME.equals(name)) {
+        } else if (ParentPath.NAME.equals(name)) {
             if (index == Path.INDEX_UNDEFINED) {
-                return new ParentPath(null);
+                return ParentPath.PARENT_PATH;
             } else {
                 throw new IllegalArgumentException();
             }
-        } else if (ROOT_NAME.equals(name)) {
+        } else if (RootPath.NAME.equals(name)) {
             if (index == Path.INDEX_UNDEFINED) {
-                return RootPath.INSTANCE;
+                return RootPath.ROOT_PATH;
             } else {
                 throw new IllegalArgumentException();
             }
         } else {
-            return new NamePath(null, NameElement.create(name, index));
+            return new NamePath(null, name, index);
         }
     }
 
     public Path create(Path.Element element) {
         if (element.denotesCurrent()) {
-            return new CurrentPath(null);
+            return CurrentPath.CURRENT_PATH;
         } else if (element.denotesIdentifier()) {
-            return new IdentifierPath(element);
+            return new IdentifierPath(element.getIdentifier());
         } else if (element.denotesName()) {
-            return new NamePath(null, element);
+            return new NamePath(null, element.getName(), element.getIndex());
         } else if (element.denotesParent()) {
-            return new ParentPath(null);
+            return ParentPath.PARENT_PATH;
         } else if (element.denotesRoot()) {
-            return RootPath.INSTANCE;
+            return RootPath.ROOT_PATH;
         } else {
             throw new IllegalArgumentException(
                     "Unknown path element type: " + element);
@@ -153,9 +150,9 @@ public class PathFactoryImpl implements 
                 if (path != null) {
                     throw new IllegalArgumentException();
                 }
-                path = new IdentifierPath(element);
+                path = new IdentifierPath(element.getIdentifier());
             } else if (element.denotesName()) {
-                path = new NamePath(path, element);
+                path = new NamePath(path, element.getName(), element.getIndex());
             } else if (element.denotesParent()) {
                 if (path != null && path.isAbsolute() && path.getDepth()
== 0) {
                     throw new IllegalArgumentException();
@@ -165,7 +162,7 @@ public class PathFactoryImpl implements 
                 if (path != null) {
                     throw new IllegalArgumentException();
                 }
-                path = RootPath.INSTANCE;
+                path = RootPath.ROOT_PATH;
             }
         }
         return path;
@@ -203,14 +200,14 @@ public class PathFactoryImpl implements 
     public Path.Element createElement(Name name) throws IllegalArgumentException {
         if (name == null) {
             throw new IllegalArgumentException("name must not be null");
-        } else if (name.equals(PARENT_NAME)) {
-            return ParentElement.INSTANCE;
-        } else if (name.equals(CURRENT_NAME)) {
-            return CurrentElement.INSTANCE;
-        } else if (name.equals(ROOT_NAME)) {
-            return RootElement.INSTANCE;
+        } else if (name.equals(ParentPath.NAME)) {
+            return ParentPath.PARENT_PATH;
+        } else if (name.equals(CurrentPath.NAME)) {
+            return CurrentPath.CURRENT_PATH;
+        } else if (name.equals(RootPath.NAME)) {
+            return RootPath.ROOT_PATH;
         } else {
-            return NameElement.create(name, Path.INDEX_UNDEFINED);
+            return new NamePath(null, name, Path.INDEX_UNDEFINED);
         }
     }
 
@@ -223,14 +220,14 @@ public class PathFactoryImpl implements 
                     "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)) {
+        } else if (name.equals(ParentPath.NAME)
+                || name.equals(CurrentPath.NAME)
+                || name.equals(RootPath.NAME)) {
             throw new IllegalArgumentException(
                     "Special path elements (root, '.' and '..') can not have an explicit
index: "
                     + name + "[" + index + "]");
         } else {
-            return NameElement.create(name, index);
+            return new NamePath(null, name, index);
         }
     }
 
@@ -238,7 +235,7 @@ public class PathFactoryImpl implements 
         if (identifier == null) {
             throw new IllegalArgumentException("The id must not be null.");
         } else {
-            return new IdentifierElement(identifier);
+            return new IdentifierPath(identifier);
         }
     }
 
@@ -249,22 +246,24 @@ public class PathFactoryImpl implements 
         if (elementString == null) {
             throw new IllegalArgumentException("null PathElement literal");
         }
-        if (elementString.equals(ROOT_NAME.toString())) {
-            return RootElement.INSTANCE;
-        } else if (elementString.equals(CURRENT_LITERAL)) {
-            return CurrentElement.INSTANCE;
-        } else if (elementString.equals(PARENT_LITERAL)) {
-            return ParentElement.INSTANCE;
+        if (elementString.equals(RootPath.NAME.toString())) {
+            return RootPath.ROOT_PATH;
+        } else if (elementString.equals(CurrentPath.CURRENT_PATH.getString())) {
+            return CurrentPath.CURRENT_PATH;
+        } else if (elementString.equals(ParentPath.PARENT_PATH.getString())) {
+            return ParentPath.PARENT_PATH;
         } else if (elementString.startsWith("[") && elementString.endsWith("]") &&
elementString.length() > 2) {
-            return new IdentifierElement(elementString.substring(1, elementString.length()-1));
+            return new IdentifierPath(
+                    elementString.substring(1, elementString.length()-1));
         }
 
+        NameFactory factory = NameFactoryImpl.getInstance();
         int pos = elementString.indexOf('[');
         if (pos == -1) {
-            Name name = NAME_FACTORY.create(elementString);
-            return NameElement.create(name, Path.INDEX_UNDEFINED);
+            Name name = factory.create(elementString);
+            return new NamePath(null, name, Path.INDEX_UNDEFINED);
         }
-        Name name = NAME_FACTORY.create(elementString.substring(0, pos));
+        Name name = factory.create(elementString.substring(0, pos));
         int pos1 = elementString.indexOf(']');
         if (pos1 == -1) {
             throw new IllegalArgumentException("invalid PathElement literal: " + elementString
+ " (missing ']')");
@@ -274,7 +273,7 @@ public class PathFactoryImpl implements 
             if (index < 1) {
                 throw new IllegalArgumentException("invalid PathElement literal: " + elementString
+ " (index is 1-based)");
             }
-            return NameElement.create(name, index);
+            return new NamePath(null, name, index);
         } catch (NumberFormatException e) {
             throw new IllegalArgumentException("invalid PathElement literal: " + elementString
+ " (" + e.getMessage() + ")");
         }
@@ -284,28 +283,28 @@ public class PathFactoryImpl implements 
      * @see PathFactory#getCurrentElement()
      */
     public Path.Element getCurrentElement() {
-        return CurrentElement.INSTANCE;
+        return CurrentPath.CURRENT_PATH;
     }
 
     /**
      * @see PathFactory#getParentElement()
      */
     public Path.Element getParentElement() {
-        return ParentElement.INSTANCE;
+        return ParentPath.PARENT_PATH;
     }
 
     /**
      * @see PathFactory#getRootElement()
      */
     public Path.Element getRootElement() {
-        return RootElement.INSTANCE;
+        return RootPath.ROOT_PATH;
     }
 
     /**
      * @see PathFactory#getRootPath()
      */
     public Path getRootPath() {
-        return RootPath.INSTANCE;
+        return RootPath.ROOT_PATH;
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RelativePath.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RelativePath.java?rev=997384&r1=997383&r2=997384&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RelativePath.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RelativePath.java
Wed Sep 15 16:17:41 2010
@@ -54,6 +54,8 @@ abstract class RelativePath extends Abst
 
     protected abstract Path getParent() throws RepositoryException;
 
+    protected abstract String getElementString();
+
     public final boolean isIdentifierBased() {
         return identifier;
     }
@@ -99,7 +101,7 @@ abstract class RelativePath extends Abst
         } else if (to < length) {
             return parent.subPath(from, to);
         } else if (from < to - 1) {
-            return parent.subPath(from, to - 1).resolve(getLastElement());
+            return parent.subPath(from, to - 1).resolve(getNameElement());
         } else {
             return getLastElement();
         }
@@ -107,10 +109,11 @@ abstract class RelativePath extends Abst
 
     public final Element[] getElements() {
         Element[] elements = new Element[length];
-        if (parent != null) {
-            System.arraycopy(parent.getElements(), 0, elements, 0, length - 1);
+        Path path = this;
+        for (int i = 1; i <= length; i++) {
+            elements[length - i] = path.getNameElement();
+            path = path.getFirstElements();
         }
-        elements[length - 1] = getNameElement();
         return elements;
     }
 
@@ -124,6 +127,14 @@ abstract class RelativePath extends Abst
         return parent;
     }
 
+    public String getString() {
+        if (parent != null) {
+            return parent.getString() + Path.DELIMITER + getElementString();
+        } else {
+            return getElementString();
+        }
+    }
+
     //--------------------------------------------------------------< Object >
 
     public boolean equals(Object that) {

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootPath.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootPath.java?rev=997384&r1=997383&r2=997384&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootPath.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootPath.java
Wed Sep 15 16:17:41 2010
@@ -24,17 +24,21 @@ import org.apache.jackrabbit.spi.Path;
 final class RootPath extends AbstractPath {
 
     /** Singleton instance */
-    public static final RootPath INSTANCE = new RootPath();
+    public static final RootPath ROOT_PATH = new RootPath();
 
     /** Serial version UID */
     private static final long serialVersionUID = 8621451607549214925L;
 
+    /** Name of the root element */
+    public static final Name NAME =
+        NameFactoryImpl.getInstance().create(Name.NS_DEFAULT_URI, "");
+
     /** Hidden constructor */
     private RootPath() {
     }
 
     public Name getName() {
-        return RootElement.INSTANCE.getName();
+        return NAME;
     }
 
     /**
@@ -151,11 +155,11 @@ final class RootPath extends AbstractPat
     }
 
     public Element[] getElements() {
-        return new Element[] { RootElement.INSTANCE };
+        return new Element[] { ROOT_PATH };
     }
 
     public Element getNameElement() {
-        return RootElement.INSTANCE;
+        return ROOT_PATH;
     }
 
     public String getString() {
@@ -166,7 +170,7 @@ final class RootPath extends AbstractPat
 
     /** Returns the singleton instance of this class */
     public Object readResolve() {
-        return INSTANCE;
+        return ROOT_PATH;
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java?rev=997384&r1=997383&r2=997384&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java
Wed Sep 15 16:17:41 2010
@@ -32,7 +32,7 @@ public class ElementTest extends TestCas
     }
 
     public void testCurrentElement() {
-        Element element = CurrentElement.INSTANCE;
+        Element element = CurrentPath.CURRENT_PATH;
         assertTrue(element.denotesCurrent());
         assertFalse(element.denotesIdentifier());
         assertFalse(element.denotesName());
@@ -45,7 +45,7 @@ public class ElementTest extends TestCas
     }
 
     public void testIdentifierElement() {
-        Element element = new IdentifierElement("test");
+        Element element = new IdentifierPath("test");
         assertFalse(element.denotesCurrent());
         assertTrue(element.denotesIdentifier());
         assertFalse(element.denotesName());
@@ -59,7 +59,7 @@ public class ElementTest extends TestCas
 
     public void testNameElement() {
         Element element =
-            NameElement.create(createName("test"), Path.INDEX_UNDEFINED);
+            new NamePath(null, createName("test"), Path.INDEX_UNDEFINED);
         assertFalse(element.denotesCurrent());
         assertFalse(element.denotesIdentifier());
         assertTrue(element.denotesName());
@@ -72,7 +72,7 @@ public class ElementTest extends TestCas
     }
 
     public void testIndexedNameElement() {
-        Element element = NameElement.create(createName("test"), 123);
+        Element element = new NamePath(null, createName("test"), 123);
         assertFalse(element.denotesCurrent());
         assertFalse(element.denotesIdentifier());
         assertTrue(element.denotesName());
@@ -85,7 +85,7 @@ public class ElementTest extends TestCas
     }
 
     public void testParentElement() {
-        Element element = ParentElement.INSTANCE;
+        Element element = ParentPath.PARENT_PATH;
         assertFalse(element.denotesCurrent());
         assertFalse(element.denotesIdentifier());
         assertFalse(element.denotesName());
@@ -98,7 +98,7 @@ public class ElementTest extends TestCas
     }
 
     public void testRootElement() {
-        Element element = RootElement.INSTANCE;
+        Element element = RootPath.ROOT_PATH;
         assertFalse(element.denotesCurrent());
         assertFalse(element.denotesIdentifier());
         assertFalse(element.denotesName());

Modified: jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/Path.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/Path.java?rev=997384&r1=997383&r2=997384&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/Path.java (original)
+++ jackrabbit/trunk/jackrabbit-spi/src/main/java/org/apache/jackrabbit/spi/Path.java Wed
Sep 15 16:17:41 2010
@@ -154,6 +154,15 @@ public interface Path extends Serializab
     int getNormalizedIndex();
 
     /**
+     * Returns the identifier of a single identifier element. Returns null
+     * for non-identifier paths or identifier paths with other relative path
+     * elements.
+     *
+     * @return identifier, or <code>null</code>
+     */
+    String getIdentifier();
+
+    /**
      * Tests whether this is the root path, i.e. "/".
      *
      * @return <code>true</code> if this is the root path,
@@ -514,6 +523,14 @@ public interface Path extends Serializab
         public int getNormalizedIndex();
 
         /**
+         * Returns the identifier of an identifier element, or
+         * <code>null</code> for other kinds of elements.
+         *
+         * @return identifier, or <code>null</code>
+         */
+        String getIdentifier();
+
+        /**
          * Returns <code>true</code> if this element denotes the <i>root</i>
element,
          * otherwise returns <code>false</code>.
          *
@@ -566,5 +583,6 @@ public interface Path extends Serializab
          * @return String representation of a {@link Path.Element}.
          */
         public String getString();
+
     }
 }



Mime
View raw message