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 2010/09/09 18:24:59 UTC

svn commit: r995482 - in /jackrabbit/trunk/jackrabbit-spi-commons/src: main/java/org/apache/jackrabbit/spi/commons/name/ test/java/org/apache/jackrabbit/spi/commons/name/

Author: jukka
Date: Thu Sep  9 16:24:58 2010
New Revision: 995482

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

Add new path element implementation classes.

Added:
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractElement.java   (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentElement.java   (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierElement.java   (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java   (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentElement.java   (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootElement.java   (with props)
    jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java   (with props)

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractElement.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractElement.java?rev=995482&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractElement.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractElement.java Thu Sep  9 16:24:58 2010
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.commons.name;
+
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.Path.Element;
+
+/**
+ * Abstract base class for path elements.
+ */
+abstract class AbstractElement implements Element {
+
+    /** Serial version UID */
+    private static final long serialVersionUID = 5259174485452841973L;
+
+    /**
+     * Returns <code>false</code>, except when overridden by the
+     * {@link RootElement} subclass.
+     *
+     * @return <code>false</code>
+     */
+    public boolean denotesRoot() {
+        return false;
+    }
+
+    /**
+     * Returns <code>false</code>, except when overridden by the
+     * {@link ParentElement} subclass.
+     *
+     * @return <code>false</code>
+     */
+    public boolean denotesParent() {
+        return false;
+    }
+
+    /**
+     * Returns <code>false</code>, except when overridden by the
+     * {@link CurrentElement} subclass.
+     *
+     * @return <code>false</code>
+     */
+    public boolean denotesCurrent() {
+        return false;
+    }
+
+    /**
+     * Returns <code>false</code>, except when overridden by the
+     * {@link NameElement} subclass.
+     *
+     * @return <code>false</code>
+     */
+    public boolean denotesName() {
+        return false;
+    }
+
+    /**
+     * Returns <code>false</code>, except when overridden by the
+     * {@link IdentifierElement} subclass.
+     *
+     * @return <code>false</code>
+     */
+    public boolean denotesIdentifier() {
+        return false;
+    }
+
+    /**
+     * Returns {@link Path#INDEX_UNDEFINED}, except when overridden by the
+     * {@link NameElement} subclass.
+     *
+     * @return {@link Path#INDEX_UNDEFINED}
+     */
+    public int getIndex() {
+        return Path.INDEX_UNDEFINED;
+    }
+
+    /**
+     * Returns {@link Path#INDEX_DEFAULT}, except when overridden by the
+     * {@link NameElement} subclass.
+     *
+     * @return {@link Path#INDEX_DEFAULT}
+     */
+    public int getNormalizedIndex() {
+        return Path.INDEX_DEFAULT;
+    }
+
+    //--------------------------------------------------------------< Object >
+
+    public final String toString() {
+        return getString();
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/AbstractElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentElement.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentElement.java?rev=995482&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentElement.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentElement.java Thu Sep  9 16:24:58 2010
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.commons.name;
+
+import org.apache.jackrabbit.spi.Name;
+
+/**
+ * Singleton class for the current path element, i.e. ".".
+ */
+final class CurrentElement extends AbstractElement {
+
+    /** Singleton instance */
+    public static final CurrentElement INSTANCE = new CurrentElement();
+
+    /** Serial version UID */
+    private static final long serialVersionUID = -6810207399807634755L;
+
+    /** Name of the current element */
+    private static final Name NAME =
+        NameFactoryImpl.getInstance().create(Name.NS_DEFAULT_URI, ".");
+
+    /** Hidden constructor */
+    private CurrentElement() {
+    }
+
+    /**
+     * Returns <code>true</code>, as this is the current path element.
+     *
+     * @return <code>true</code>
+     */
+    @Override
+    public boolean denotesCurrent() {
+        return true;
+    }
+
+    /**
+     * Returns the pseudo-name "." of the current path element.
+     *
+     * @return "."
+     */
+    public Name getName() {
+        return NAME;
+    }
+
+    /**
+     * Returns the "." string representation of the current path element.
+     *
+     * @return "."
+     */
+    public String getString() {
+        return ".";
+    }
+
+    //--------------------------------------------------------< Serializable >
+
+    /** Returns the singleton instance of this class */
+    public Object readResolve() {
+        return INSTANCE;
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/CurrentElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierElement.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierElement.java?rev=995482&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierElement.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierElement.java Thu Sep  9 16:24:58 2010
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.commons.name;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path.Element;
+
+/**
+ * Identifier path element.
+ */
+final class IdentifierElement extends AbstractElement {
+
+    /** Serial version UID */
+    private static final long serialVersionUID = 1508076769330719028L;
+
+    /**
+     * Identifier of the path element.
+     */
+    private final String identifier;
+
+    /**
+     * Creates a path element from the given identifier.
+     *
+     * @param identifier identifier of this element
+     */
+    public IdentifierElement(String identifier) {
+        this.identifier = identifier;
+    }
+
+    /**
+     * Returns <code>true</code>, as this is an identifier path element.
+     *
+     * @return <code>true</code>
+     */
+    @Override
+    public boolean denotesIdentifier() {
+        return true;
+    }
+
+    /**
+     * Returns <code>null</code> as identifier path elements have no name.
+     *
+     * @return <code>null</code>
+     */
+    public Name getName() {
+        return null;
+    }
+
+    /**
+     * Returns a string representation of this path element. The identifier
+     * is expressed using the <code>[identifier]</code> syntax.
+     *
+     * @return string representation of this path element
+     */
+    public String getString() {
+        return "[" + identifier + "]";
+    }
+
+    //--------------------------------------------------------------< Object >
+
+    /**
+     * Check for path element equality. Returns true if the given object is
+     * an identifier element and contains the same identifier as this one.
+     *
+     * @param that the object to compare with
+     * @return <code>true</code> if the path elements are equal
+     */
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        } else if (that instanceof Element) {
+            Element element = (Element) that;
+            return element.denotesIdentifier()
+                && getString().equals(element.getString());
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Computes a hash code for this path element.
+     *
+     * @return hash code
+     * @see Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        return identifier.hashCode();
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/IdentifierElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java?rev=995482&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java Thu Sep  9 16:24:58 2010
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.commons.name;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.Path.Element;
+
+/**
+ * Named path element with an optional index.
+ */
+final class NameElement extends AbstractElement {
+
+    /** Serial version UID */
+    private static final long serialVersionUID = -6655583285077651379L;
+
+    /**
+     * Name of the path element.
+     */
+    private final Name name;
+
+    /**
+     * Optional index of the path element. Set to {@link Path#INDEX_UNDEFINED}
+     * (i.e. 0) if not explicitly specified, otherwise contains the 1-based
+     * index.
+     */
+    private final int index;
+
+    /**
+     * Creates a named path element with the given name and optional index.
+     *
+     * @param name name of this element
+     * @param index index of this element, or {@link Path#INDEX_UNDEFINED}
+     */
+    public NameElement(Name name, int index) {
+        if (name != null && index >= 0) {
+            this.index = index;
+            this.name = name;
+        } else {
+            throw new IllegalArgumentException(
+                    "new NameElement(" + name + ", " + index + ")");
+        }
+    }
+
+    /**
+     * Returns <code>true</code>, as this is a named path element.
+     *
+     * @return <code>true</code>
+     */
+    @Override
+    public boolean denotesName() {
+        return true;
+    }
+
+    /**
+     * Returns the name of this path element.
+     *
+     * @param name of this element
+     */
+    public Name getName() {
+        return name;
+    }
+
+    /**
+     * Returns the 1-based index of this path element, or
+     * {@link Path#INDEX_UNDEFINED} if the index is undefined.
+     *
+     * @param index of this element, or {@link Path#INDEX_UNDEFINED}
+     */
+    @Override
+    public int getIndex() {
+        return index;
+    }
+
+    /**
+     * Returns the normalized index of this path element.
+     *
+     * @return normalized index of this element
+     */
+    @Override
+    public int getNormalizedIndex() {
+        if (index != Path.INDEX_UNDEFINED) {
+            return index;
+        } else {
+            return Path.INDEX_DEFAULT;
+        }
+    }
+
+    /**
+     * Returns a string representation of this path element. The element
+     * name is expressed using the <code>{uri}name</code> syntax and the
+     * index is added as <code>[index]</code> if it's defined and greater
+     * than one.
+     *
+     * @return string representation of this path element
+     */
+    public String getString() {
+        if (index > Path.INDEX_DEFAULT) {
+            return name + "[" + index + "]";
+        } else {
+            return name.toString();
+        }
+    }
+
+    //--------------------------------------------------------------< Object >
+
+    /**
+     * Check for path element equality. Returns true if the given object is
+     * a named path element and contains the same name and index as this one.
+     *
+     * @param that the object to compare with
+     * @return <code>true</code> if the path elements are equal
+     */
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        } else if (that instanceof Element) {
+            Element element = (Element) that;
+            return element.denotesName()
+                && name.equals(element.getName())
+                && getNormalizedIndex() == element.getNormalizedIndex();
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Computes a hash code for this path element.
+     *
+     * @return hash code
+     * @see Object#hashCode()
+     */
+    @Override
+    public int hashCode() {
+        int h = 17;
+        h = 37 * h + getNormalizedIndex();
+        h = 37 * h + name.hashCode();
+        return h;
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/NameElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentElement.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentElement.java?rev=995482&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentElement.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentElement.java Thu Sep  9 16:24:58 2010
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.commons.name;
+
+import org.apache.jackrabbit.spi.Name;
+
+/**
+ * Singleton class for the parent path element, i.e. "..".
+ */
+final class ParentElement extends AbstractElement {
+
+    /** Singleton instance */
+    public static final ParentElement INSTANCE = new ParentElement();
+
+    /** Serial version UID */
+    private static final long serialVersionUID = -7445693011766172219L;
+
+    /** Name of the parent element */
+    private static final Name NAME =
+        NameFactoryImpl.getInstance().create(Name.NS_DEFAULT_URI, "..");
+
+    /** Hidden constructor */
+    private ParentElement() {
+    }
+
+    /**
+     * Returns <code>true</code>, as this is the parent path element.
+     *
+     * @return <code>true</code>
+     */
+    @Override
+    public boolean denotesParent() {
+        return true;
+    }
+
+    /**
+     * Returns the pseudo-name ".." of the parent path element.
+     *
+     * @return ".."
+     */
+    public Name getName() {
+        return NAME;
+    }
+
+    /**
+     * Returns the ".." string representation of the parent path element.
+     *
+     * @return ".."
+     */
+    public String getString() {
+        return "..";
+    }
+
+    //--------------------------------------------------------< Serializable >
+
+    /** Returns the singleton instance of this class */
+    public Object readResolve() {
+        return INSTANCE;
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/ParentElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootElement.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootElement.java?rev=995482&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootElement.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootElement.java Thu Sep  9 16:24:58 2010
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.commons.name;
+
+import org.apache.jackrabbit.spi.Name;
+
+/**
+ * Singleton class for the root path element, i.e. "/".
+ */
+final class RootElement extends AbstractElement {
+
+    /** Singleton instance */
+    public static final RootElement INSTANCE = new RootElement();
+
+    /** Serial version UID */
+    private static final long serialVersionUID = -8309331612073587196L;
+
+    /** Name of the root element */
+    private static final Name NAME =
+        NameFactoryImpl.getInstance().create(Name.NS_DEFAULT_URI, "");
+
+    /** Hidden constructor */
+    private RootElement() {
+    }
+
+    /**
+     * Returns <code>true</code>, as this is the root path element.
+     *
+     * @return <code>true</code>
+     */
+    @Override
+    public boolean denotesRoot() {
+        return true;
+    }
+
+    /**
+     * Returns the pseudo-name "" of the root path element.
+     *
+     * @return ""
+     */
+    public Name getName() {
+        return NAME;
+    }
+
+    /**
+     * Returns the "{}" string representation of the root path element.
+     *
+     * @return "{}"
+     */
+    public String getString() {
+        return "{}";
+    }
+
+    //--------------------------------------------------------< Serializable >
+
+    /** Returns the singleton instance of this class */
+    public Object readResolve() {
+        return INSTANCE;
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/name/RootElement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=995482&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java Thu Sep  9 16:24:58 2010
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.commons.name;
+
+import junit.framework.TestCase;
+
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.Path.Element;
+
+/**
+ * Test cases for various kinds of path elements.
+ */
+public class ElementTest extends TestCase {
+
+    private Name createName(String name) {
+        return NameFactoryImpl.getInstance().create(Name.NS_DEFAULT_URI, name);
+    }
+
+    public void testCurrentElement() {
+        Element element = CurrentElement.INSTANCE;
+        assertTrue(element.denotesCurrent());
+        assertFalse(element.denotesIdentifier());
+        assertFalse(element.denotesName());
+        assertFalse(element.denotesParent());
+        assertFalse(element.denotesRoot());
+        assertEquals(createName("."), element.getName());
+        assertEquals(Path.INDEX_UNDEFINED, element.getIndex());
+        assertEquals(Path.INDEX_DEFAULT, element.getNormalizedIndex());
+        assertEquals(".", element.getString());
+    }
+
+    public void testIdentifierElement() {
+        Element element = new IdentifierElement("test");
+        assertFalse(element.denotesCurrent());
+        assertTrue(element.denotesIdentifier());
+        assertFalse(element.denotesName());
+        assertFalse(element.denotesParent());
+        assertFalse(element.denotesRoot());
+        assertNull(element.getName());
+        assertEquals(Path.INDEX_UNDEFINED, element.getIndex());
+        assertEquals(Path.INDEX_DEFAULT, element.getNormalizedIndex());
+        assertEquals("[test]", element.getString());
+    }
+
+    public void testNameElement() {
+        Element element =
+            new NameElement(createName("test"), Path.INDEX_UNDEFINED);
+        assertFalse(element.denotesCurrent());
+        assertFalse(element.denotesIdentifier());
+        assertTrue(element.denotesName());
+        assertFalse(element.denotesParent());
+        assertFalse(element.denotesRoot());
+        assertEquals(createName("test"), element.getName());
+        assertEquals(Path.INDEX_UNDEFINED, element.getIndex());
+        assertEquals(Path.INDEX_DEFAULT, element.getNormalizedIndex());
+        assertEquals("{}test", element.getString());
+    }
+
+    public void testIndexedNameElement() {
+        Element element = new NameElement(createName("test"), 123);
+        assertFalse(element.denotesCurrent());
+        assertFalse(element.denotesIdentifier());
+        assertTrue(element.denotesName());
+        assertFalse(element.denotesParent());
+        assertFalse(element.denotesRoot());
+        assertEquals(createName("test"), element.getName());
+        assertEquals(123, element.getIndex());
+        assertEquals(123, element.getNormalizedIndex());
+        assertEquals("{}test[123]", element.getString());
+    }
+
+    public void testParentElement() {
+        Element element = ParentElement.INSTANCE;
+        assertFalse(element.denotesCurrent());
+        assertFalse(element.denotesIdentifier());
+        assertFalse(element.denotesName());
+        assertTrue(element.denotesParent());
+        assertFalse(element.denotesRoot());
+        assertEquals(createName(".."), element.getName());
+        assertEquals(Path.INDEX_UNDEFINED, element.getIndex());
+        assertEquals(Path.INDEX_DEFAULT, element.getNormalizedIndex());
+        assertEquals("..", element.getString());
+    }
+
+    public void testRootElement() {
+        Element element = RootElement.INSTANCE;
+        assertFalse(element.denotesCurrent());
+        assertFalse(element.denotesIdentifier());
+        assertFalse(element.denotesName());
+        assertFalse(element.denotesParent());
+        assertTrue(element.denotesRoot());
+        assertEquals(createName(""), element.getName());
+        assertEquals(Path.INDEX_UNDEFINED, element.getIndex());
+        assertEquals(Path.INDEX_DEFAULT, element.getNormalizedIndex());
+        assertEquals("{}", element.getString());
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/spi/commons/name/ElementTest.java
------------------------------------------------------------------------------
    svn:eol-style = native