jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r586058 [4/4] - in /jackrabbit/trunk/jackrabbit-spi-commons: ./ src/main/java/org/apache/jackrabbit/conversion/ src/main/java/org/apache/jackrabbit/identifier/ src/main/java/org/apache/jackrabbit/lock/ src/main/java/org/apache/jackrabbit/na...
Date Thu, 18 Oct 2007 18:35:01 GMT
Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QNodeTypeDefinitionImpl.java Thu Oct 18 11:34:57 2007
@@ -19,7 +19,9 @@
 import org.apache.jackrabbit.spi.QNodeTypeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeDefinition;
-import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.name.NameFactoryImpl;
 
 import javax.jcr.PropertyType;
 import java.util.Collection;
@@ -36,12 +38,12 @@
     /**
      * The name of the node definition.
      */
-    private final QName name;
+    private final Name name;
 
     /**
      * The names of the declared super types of this node type definition.
      */
-    private final QName[] supertypes;
+    private final Name[] supertypes;
 
     /**
      * Indicates whether this is a mixin node type definition.
@@ -56,7 +58,7 @@
     /**
      * The name of the primary item or <code>null</code> if none is defined.
      */
-    private final QName primaryItemName;
+    private final Name primaryItemName;
 
     /**
      * The list of property definitions.
@@ -69,7 +71,7 @@
     private final QNodeDefinition[] childNodeDefs;
 
     /**
-     * Unmodifiable collection of dependent node type <code>QName</code>s.
+     * Unmodifiable collection of dependent node type <code>Name</code>s.
      * @see #getDependencies()
      */
     private transient Collection dependencies;
@@ -80,7 +82,7 @@
      * @param nt the qualified node type definition.
      */
     public QNodeTypeDefinitionImpl(QNodeTypeDefinition nt) {
-        this(nt.getQName(), nt.getSupertypes(), nt.isMixin(),
+        this(nt.getName(), nt.getSupertypes(), nt.isMixin(),
                 nt.hasOrderableChildNodes(), nt.getPrimaryItemName(),
                 nt.getPropertyDefs(), nt.getChildNodeDefs());
     }
@@ -98,11 +100,11 @@
      * @param declaredPropDefs       the declared property definitions.
      * @param declaredNodeDefs       the declared child node definitions.
      */
-    public QNodeTypeDefinitionImpl(QName name,
-                                   QName[] supertypes,
+    public QNodeTypeDefinitionImpl(Name name,
+                                   Name[] supertypes,
                                    boolean isMixin,
                                    boolean hasOrderableChildNodes,
-                                   QName primaryItemName,
+                                   Name primaryItemName,
                                    QPropertyDefinition[] declaredPropDefs,
                                    QNodeDefinition[] declaredNodeDefs) {
         this.name = name;
@@ -117,15 +119,15 @@
     /**
      * {@inheritDoc}
      */
-    public QName getQName() {
+    public Name getName() {
         return name;
     }
 
     /**
      * {@inheritDoc}
      */
-    public QName[] getSupertypes() {
-        QName[] sTypes = new QName[supertypes.length];
+    public Name[] getSupertypes() {
+        Name[] sTypes = new Name[supertypes.length];
         System.arraycopy(supertypes, 0, sTypes, 0, supertypes.length);
         return sTypes;
     }
@@ -147,7 +149,7 @@
     /**
      * {@inheritDoc}
      */
-    public QName getPrimaryItemName() {
+    public Name getPrimaryItemName() {
         return primaryItemName;
     }
 
@@ -182,12 +184,12 @@
             // child node definitions
             for (int i = 0; i < childNodeDefs.length; i++) {
                 // default primary type
-                QName ntName = childNodeDefs[i].getDefaultPrimaryType();
+                Name ntName = childNodeDefs[i].getDefaultPrimaryType();
                 if (ntName != null && !name.equals(ntName)) {
                     deps.add(ntName);
                 }
                 // required primary type
-                QName[] ntNames = childNodeDefs[i].getRequiredPrimaryTypes();
+                Name[] ntNames = childNodeDefs[i].getRequiredPrimaryTypes();
                 for (int j = 0; j < ntNames.length; j++) {
                     if (ntNames[j] != null && !name.equals(ntNames[j])) {
                         deps.add(ntNames[j]);
@@ -201,7 +203,8 @@
                     String[] ca = propertyDefs[i].getValueConstraints();
                     if (ca != null) {
                         for (int j = 0; j < ca.length; j++) {
-                            QName ntName = QName.valueOf(ca[j]);
+                            NameFactory factory = NameFactoryImpl.getInstance();
+                            Name ntName = factory.create(ca[j]);
                             if (!name.equals(ntName)) {
                                 deps.add(ntName);
                             }

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QPropertyDefinitionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QPropertyDefinitionImpl.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QPropertyDefinitionImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/QPropertyDefinitionImpl.java Thu Oct 18 11:34:57 2007
@@ -18,7 +18,7 @@
 
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QValue;
-import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.Name;
 
 import java.util.Arrays;
 
@@ -56,7 +56,7 @@
      * @param propDef some other property definition.
      */
     public QPropertyDefinitionImpl(QPropertyDefinition propDef) {
-        this(propDef.getQName(), propDef.getDeclaringNodeType(),
+        this(propDef.getName(), propDef.getDeclaringNodeType(),
                 propDef.isAutoCreated(), propDef.isMandatory(),
                 propDef.getOnParentVersion(), propDef.isProtected(),
                 propDef.getDefaultValues(), propDef.isMultiple(),
@@ -81,7 +81,7 @@
      * @throws NullPointerException if <code>valueConstraints</code> is
      *                              <code>null</code>.
      */
-    public QPropertyDefinitionImpl(QName name, QName declaringNodeType,
+    public QPropertyDefinitionImpl(Name name, Name declaringNodeType,
                                    boolean isAutoCreated, boolean isMandatory,
                                    int onParentVersion, boolean isProtected,
                                    QValue[] defaultValues, boolean isMultiple,
@@ -176,7 +176,7 @@
             if (definesResidual()) {
                 sb.append('*');
             } else {
-                sb.append(getQName().toString());
+                sb.append(getName().toString());
             }
             sb.append('/');
             sb.append(getRequiredType());

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/SerializableBatch.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/SerializableBatch.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/SerializableBatch.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/SerializableBatch.java Thu Oct 18 11:34:57 2007
@@ -21,7 +21,7 @@
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.spi.Name;
 
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFormatException;
@@ -83,19 +83,19 @@
     //----------------------------< Batch >-------------------------------------
 
     public void addNode(NodeId parentId,
-                        QName nodeName,
-                        QName nodetypeName,
+                        Name nodeName,
+                        Name nodetypeName,
                         String uuid) {
         recording.add(new AddNode(parentId, nodeName, nodetypeName, uuid));
     }
 
-    public void addProperty(NodeId parentId, QName propertyName, QValue value) {
+    public void addProperty(NodeId parentId, Name propertyName, QValue value) {
         recording.add(new AddProperty(parentId, propertyName,
                 new QValue[]{value}, false));
     }
 
     public void addProperty(NodeId parentId,
-                            QName propertyName,
+                            Name propertyName,
                             QValue[] values) {
         recording.add(new AddProperty(parentId, propertyName, values, true));
     }
@@ -118,13 +118,13 @@
         recording.add(new ReorderNodes(parentId, srcNodeId, beforeNodeId));
     }
 
-    public void setMixins(NodeId nodeId, QName[] mixinNodeTypeIds) {
+    public void setMixins(NodeId nodeId, Name[] mixinNodeTypeIds) {
         recording.add(new SetMixins(nodeId, mixinNodeTypeIds));
     }
 
     public void move(NodeId srcNodeId,
                      NodeId destParentNodeId,
-                     QName destName) {
+                     Name destName) {
         recording.add(new Move(srcNodeId, destParentNodeId, destName));
     }
 
@@ -146,13 +146,13 @@
 
         private final NodeId parentId;
 
-        private final QName nodeName;
+        private final Name nodeName;
 
-        private final QName nodetypeName;
+        private final Name nodetypeName;
 
         private final String uuid;
 
-        AddNode(NodeId parentId, QName nodeName, QName nodetypeName, String uuid) {
+        AddNode(NodeId parentId, Name nodeName, Name nodetypeName, String uuid) {
             this.parentId = parentId;
             this.nodeName = nodeName;
             this.nodetypeName = nodetypeName;
@@ -171,13 +171,13 @@
 
         private final NodeId parentId;
 
-        private final QName propertyName;
+        private final Name propertyName;
 
         private final QValue[] values;
 
         private final boolean isMultiValued;
 
-        AddProperty(NodeId parentId, QName propertyName,
+        AddProperty(NodeId parentId, Name propertyName,
                     QValue[] values, boolean isMultiValued) {
             this.parentId = parentId;
             this.propertyName = propertyName;
@@ -265,9 +265,9 @@
 
         private final NodeId nodeId;
 
-        private final QName[] mixinNodeTypeIds;
+        private final Name[] mixinNodeTypeIds;
 
-        SetMixins(NodeId nodeId, QName[] mixinNodeTypeIds) {
+        SetMixins(NodeId nodeId, Name[] mixinNodeTypeIds) {
             this.nodeId = nodeId;
             this.mixinNodeTypeIds = mixinNodeTypeIds;
         }
@@ -286,9 +286,9 @@
 
         private final NodeId destParentNodeId;
 
-        private final QName destName;
+        private final Name destName;
 
-        Move(NodeId srcNodeId, NodeId destParentNodeId, QName destName) {
+        Move(NodeId srcNodeId, NodeId destParentNodeId, Name destName) {
             this.srcNodeId = srcNodeId;
             this.destParentNodeId = destParentNodeId;
             this.destName = destName;

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/QValueFactoryImpl.java Thu Oct 18 11:34:57 2007
@@ -16,10 +16,14 @@
  */
 package org.apache.jackrabbit.value;
 
+import org.apache.jackrabbit.name.PathFactoryImpl;
+import org.apache.jackrabbit.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.NameFactory;
 import org.apache.jackrabbit.util.TransientFileFactory;
 import org.apache.jackrabbit.util.ISO8601;
 
@@ -47,13 +51,16 @@
  */
 public final class QValueFactoryImpl implements QValueFactory {
 
-    private static final QValueFactory instance = new QValueFactoryImpl();
+    private static final QValueFactory INSTANCE = new QValueFactoryImpl();
+
+    private static final PathFactory PATH_FACTORY = PathFactoryImpl.getInstance();
+    private static final NameFactory NAME_FACTORY = NameFactoryImpl.getInstance();
 
     private QValueFactoryImpl() {
     }
 
     public static QValueFactory getInstance() {
-        return instance;
+        return INSTANCE;
     }
 
     //------------------------------------------------------< QValueFactory >---
@@ -74,9 +81,9 @@
             case PropertyType.LONG:
                 return new QValueImpl(Long.valueOf(value));
             case PropertyType.PATH:
-                return new QValueImpl(Path.valueOf(value));
+                return new QValueImpl(PATH_FACTORY.create(value));
             case PropertyType.NAME:
-                return new QValueImpl(QName.valueOf(value));
+                return new QValueImpl(NAME_FACTORY.create(value));
             case PropertyType.STRING:
             case PropertyType.REFERENCE:
                 return new QValueImpl(value, type);
@@ -99,9 +106,9 @@
     }
 
     /**
-     * @see QValueFactory#create(QName)
+     * @see QValueFactory#create(Name)
      */
-    public QValue create(QName value) {
+    public QValue create(Name value) {
         if (value == null) {
             throw new IllegalArgumentException("Cannot create QValue from null value.");
         }
@@ -191,7 +198,7 @@
             type = PropertyType.BOOLEAN;
         }
 
-        private QValueImpl(QName value) {
+        private QValueImpl(Name value) {
             val = value;
             type = PropertyType.NAME;
         }
@@ -236,13 +243,13 @@
         }
 
         /**
-         * @see QValue#getQName()
+         * @see QValue#getName()
          */
-        public QName getQName() throws RepositoryException {
+        public Name getName() throws RepositoryException {
             if (type == PropertyType.NAME) {
-                return (QName) val;
+                return (Name) val;
             } else {
-                return QName.valueOf(getString());
+                return NAME_FACTORY.create(getString());
             }
         }
 
@@ -264,7 +271,7 @@
             if (type == PropertyType.PATH) {
                 return (Path) val;
             } else {
-                return Path.valueOf(getString());
+                return PATH_FACTORY.create(getString());
             }
         }
 
@@ -592,9 +599,9 @@
         }
 
         /**
-         * @see QValue#getQName()
+         * @see QValue#getName()
          */
-        public QName getQName() throws RepositoryException {
+        public Name getName() throws RepositoryException {
             throw new UnsupportedOperationException();
         }
 

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/ValueFormat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/ValueFormat.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/ValueFormat.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/value/ValueFormat.java Thu Oct 18 11:34:57 2007
@@ -16,13 +16,10 @@
  */
 package org.apache.jackrabbit.value;
 
-import org.apache.jackrabbit.name.NamespaceResolver;
-import org.apache.jackrabbit.name.NameException;
-import org.apache.jackrabbit.name.NoPrefixDeclaredException;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.Path;
-import org.apache.jackrabbit.name.PathFormat;
-import org.apache.jackrabbit.name.NameFormat;
+import org.apache.jackrabbit.conversion.NamePathResolver;
+import org.apache.jackrabbit.conversion.NameException;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
 
@@ -42,12 +39,12 @@
     /**
      *
      * @param jcrValue
-     * @param nsResolver
+     * @param resolver
      * @param factory
      * @return
      * @throws RepositoryException
      */
-    public static QValue getQValue(Value jcrValue, NamespaceResolver nsResolver,
+    public static QValue getQValue(Value jcrValue, NamePathResolver resolver,
                                    QValueFactory factory) throws RepositoryException {
         if (jcrValue == null) {
             throw new IllegalArgumentException("null value");
@@ -61,20 +58,20 @@
         } else if (jcrValue.getType() == PropertyType.DATE) {
             return factory.create(jcrValue.getDate());
         } else {
-            return getQValue(jcrValue.getString(), jcrValue.getType(), nsResolver, factory);
+            return getQValue(jcrValue.getString(), jcrValue.getType(), resolver, factory);
         }
     }
 
     /**
      *
      * @param jcrValues
-     * @param nsResolver
+     * @param resolver
      * @param factory
      * @return
      * @throws RepositoryException
      */
     public static QValue[] getQValues(Value[] jcrValues,
-                                      NamespaceResolver nsResolver,
+                                      NamePathResolver resolver,
                                       QValueFactory factory) throws RepositoryException {
         if (jcrValues == null) {
             throw new IllegalArgumentException("null value");
@@ -82,7 +79,7 @@
         List qValues = new ArrayList();
         for (int i = 0; i < jcrValues.length; i++) {
             if (jcrValues[i] != null) {
-                qValues.add(getQValue(jcrValues[i], nsResolver, factory));
+                qValues.add(getQValue(jcrValues[i], resolver, factory));
             }
         }
         return (QValue[]) qValues.toArray(new QValue[qValues.size()]);
@@ -92,13 +89,13 @@
      * 
      * @param jcrValue
      * @param propertyType
-     * @param nsResolver
+     * @param resolver
      * @param factory
      * @return
      * @throws RepositoryException
      */
     public static QValue getQValue(String jcrValue, int propertyType,
-                                   NamespaceResolver nsResolver,
+                                   NamePathResolver resolver,
                                    QValueFactory factory) throws RepositoryException {
         QValue qValue;
         switch (propertyType) {
@@ -115,7 +112,7 @@
                 break;
             case PropertyType.NAME:
                 try {
-                    QName qName = NameFormat.parse(jcrValue, nsResolver);
+                    Name qName = resolver.getQName(jcrValue);
                     qValue = factory.create(qName);
                 } catch (NameException e) {
                     throw new RepositoryException(e);
@@ -123,7 +120,7 @@
                 break;
             case PropertyType.PATH:
                 try {
-                    Path qPath = PathFormat.parse(jcrValue, nsResolver).getNormalizedPath();
+                    Path qPath = resolver.getQPath(jcrValue).getNormalizedPath();
                     qValue = factory.create(qPath);
                 } catch (NameException e) {
                     throw new RepositoryException(e);
@@ -136,12 +133,13 @@
     }
 
     /**
-     * @param nsResolver
+     * @param qualifiedValue
+     * @param resolver
      * @return
      * @throws RepositoryException
      */
     public static Value getJCRValue(QValue qualifiedValue,
-                                    NamespaceResolver nsResolver,
+                                    NamePathResolver resolver,
                                     ValueFactory factory) throws RepositoryException {
         Value jcrValue;
         int propertyType = qualifiedValue.getType();
@@ -154,22 +152,12 @@
                 jcrValue = factory.createValue(qualifiedValue.getString(), propertyType);
                 break;
             case PropertyType.PATH:
-                try {
-                    Path qPath = qualifiedValue.getPath();
-                    jcrValue = factory.createValue(PathFormat.format(qPath, nsResolver), propertyType);
-                } catch (NoPrefixDeclaredException npde) {
-                    // should never get here...
-                    throw new RepositoryException("internal error: encountered unregistered namespace", npde);
-                }
+                Path qPath = qualifiedValue.getPath();
+                jcrValue = factory.createValue(resolver.getJCRPath(qPath), propertyType);
                 break;
             case PropertyType.NAME:
-                try {
-                    QName qName = qualifiedValue.getQName();
-                    jcrValue = factory.createValue(NameFormat.format(qName, nsResolver), propertyType);
-                } catch (NoPrefixDeclaredException npde) {
-                    // should never get here...
-                    throw new RepositoryException("internal error: encountered unregistered namespace", npde);
-                }
+                Name qName = qualifiedValue.getName();
+                jcrValue = factory.createValue(resolver.getJCRName(qName), propertyType);
                 break;
             case PropertyType.BINARY:
                 jcrValue = factory.createValue(qualifiedValue.getStream());

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/DummyNamespaceResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/DummyNamespaceResolver.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/DummyNamespaceResolver.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/DummyNamespaceResolver.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,49 @@
+/*
+ * 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.conversion;
+
+import javax.jcr.NamespaceException;
+
+import org.apache.jackrabbit.namespace.NamespaceResolver;
+
+/**
+ * Dummy namespace resolver for use in unit testing. This namespace resolver
+ * maps each valid XML prefix string to the same string as the namespace URI
+ * and vice versa.
+ */
+class DummyNamespaceResolver implements NamespaceResolver {
+
+    /**
+     * Returns the given prefix.
+     *
+     * @param prefix namespace prefix
+     * @return the given prefix
+     */
+    public String getURI(String prefix) throws NamespaceException {
+        return prefix;
+    }
+
+    /**
+     * Returns the given namespace URI as the corresponding prefix.
+     *
+     * @param uri namespace URI
+     * @return the given URI
+     */
+    public String getPrefix(String uri) {
+        return uri;
+    }
+}

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

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/DummyNamespaceResolver.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/NameParserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/NameParserTest.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/NameParserTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/NameParserTest.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,90 @@
+/*
+ * 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.conversion;
+
+import org.apache.jackrabbit.namespace.NamespaceResolver;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.name.NameFactoryImpl;
+import org.apache.jackrabbit.name.JcrName;
+import junit.framework.TestCase;
+
+import javax.jcr.NamespaceException;
+
+/**
+ * <code>NameParserTest</code>...
+ */
+public class NameParserTest extends TestCase {
+
+    private final NameFactory factory = NameFactoryImpl.getInstance();
+    private final NamespaceResolver resolver = new DummyNamespaceResolver();
+
+    private JcrName[] tests = JcrName.getTests();
+
+    private static int NUM_TESTS = 1;
+
+
+    public void testParse() throws Exception {
+        for (int i=0; i<tests.length; i++) {
+            JcrName t = tests[i];
+            long t1 = System.currentTimeMillis();
+            for (int j=0; j<NUM_TESTS; j++) {
+                try {
+                    Name n = NameParser.parse(t.jcrName, resolver, factory);
+                    if (!t.isValid()) {
+                        fail("Should throw IllegalNameException: " + t.jcrName);
+                    }
+                    assertEquals("\"" + t.jcrName + "\".uri", t.prefix, n.getNamespaceURI());
+                    assertEquals("\"" + t.jcrName + "\".localName", t.name, n.getLocalName());
+                } catch (IllegalNameException e) {
+                    if (t.isValid()) {
+                        throw e;
+                    }
+                } catch (NamespaceException e) {
+                    if (t.isValid()) {
+                        throw e;
+                    }
+                }
+            }
+            long t2 = System.currentTimeMillis();
+            if (NUM_TESTS>1) {
+                System.out.println("testCreate():\t" + t + "\t" + (t2-t1) + "\tms");
+            }
+        }
+    }
+
+    public void testCheckFormat() throws Exception {
+        for (int i=0; i<tests.length; i++) {
+            JcrName t = tests[i];
+            long t1 = System.currentTimeMillis();
+            for (int j=0; j<NUM_TESTS; j++) {
+                // check just creation
+                boolean isValid = true;
+                try {
+                    NameParser.checkFormat(t.jcrName);
+                } catch (IllegalNameException e) {
+                    isValid = false;
+                }
+                assertEquals("\"" + t.jcrName + "\".checkFormat()", t.isValid(),  isValid);
+            }
+            long t2 = System.currentTimeMillis();
+            if (NUM_TESTS>1) {
+                System.out.println("testCheckFormat():\t" + t + "\t" + (t2-t1) + "\tms");
+            }
+        }
+    }
+}
\ No newline at end of file

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

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/NameParserTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/ParsingNameResolverTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/ParsingNameResolverTest.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/ParsingNameResolverTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/ParsingNameResolverTest.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,107 @@
+/*
+ * 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.conversion;
+
+import javax.jcr.NamespaceException;
+
+import junit.framework.TestCase;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.name.NameFactoryImpl;
+
+/**
+ * Test cases for the {@link org.apache.jackrabbit.conversion.ParsingNameResolver} class.
+ */
+public class ParsingNameResolverTest extends TestCase {
+
+    /**
+     * Name resolver being tested.
+     */
+    private NameResolver resolver =
+        new ParsingNameResolver(NameFactoryImpl.getInstance(), new DummyNamespaceResolver());
+
+    /**
+     * Checks that the given name resolves to the given namespace URI and
+     * local part.
+     *
+     * @param name JCR name
+     * @param uri namespace URI
+     * @param local local part
+     */
+    private void assertValidName(String name, String uri, String local) {
+        try {
+            Name qname = resolver.getQName(name);
+            assertEquals(name, uri, qname.getNamespaceURI());
+            assertEquals(name, local, qname.getLocalName());
+            assertEquals(name, name, resolver.getJCRName(qname));
+        } catch (NameException e) {
+            fail(name);
+        } catch (NamespaceException e) {
+            fail(name);
+        }
+    }
+
+    /**
+     * Tests that valid names are properly resolved.
+     */
+    public void testValidNames() {
+        assertValidName("x", "", "x");
+        assertValidName("name", "", "name");
+        assertValidName("space name", "", "space name");
+        assertValidName("x:y", "x", "y");
+        assertValidName("prefix:name", "prefix", "name");
+        assertValidName("prefix:space name", "prefix", "space name");
+    }
+
+    /**
+     * Checks that the given name fails to resolve.
+     *
+     * @param name JCR name
+     */
+    private void assertInvalidName(String name) {
+        try {
+            resolver.getQName(name);
+            fail(name);
+        } catch (NameException e) {
+        } catch (NamespaceException e) {
+        }
+    }
+
+    /**
+     * Tests that resolution of invalid names fails.
+     */
+    public void testInvalidNames() {
+        assertInvalidName("");
+        assertInvalidName(":name");
+        assertInvalidName(".");
+        assertInvalidName("..");
+        assertInvalidName("pre:");
+        assertInvalidName(" name");
+        assertInvalidName(" prefix: name");
+        assertInvalidName("prefix: name");
+        assertInvalidName("prefix:name ");
+        assertInvalidName("pre fix:name");
+        assertInvalidName("prefix :name");
+        assertInvalidName("name/name");
+        assertInvalidName("name[]");
+        assertInvalidName("name[1]");
+        assertInvalidName("name[name");
+        assertInvalidName("name]name");
+        assertInvalidName("name*name");
+        assertInvalidName("prefix:name:name");
+    }
+
+}

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

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/ParsingNameResolverTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/ParsingPathResolverTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/ParsingPathResolverTest.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/ParsingPathResolverTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/ParsingPathResolverTest.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,136 @@
+/*
+ * 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.conversion;
+
+import junit.framework.TestCase;
+
+import javax.jcr.NamespaceException;
+
+import org.apache.jackrabbit.name.PathFactoryImpl;
+import org.apache.jackrabbit.name.NameFactoryImpl;
+import org.apache.jackrabbit.spi.Path;
+
+/**
+ * Test cases for the {@link ParsingPathResolver} class.
+ */
+public class ParsingPathResolverTest extends TestCase {
+
+    /**
+     * Path resolver being tested.
+     */
+    private PathResolver resolver = new ParsingPathResolver(PathFactoryImpl.getInstance(),
+            new ParsingNameResolver(NameFactoryImpl.getInstance(), new DummyNamespaceResolver()));
+
+    /**
+     * Checks that the given path resolves properly.
+     *
+     * @param path JCR path
+     */
+    private void assertValidPath(String path) {
+        try {
+            Path qpath = resolver.getQPath(path);
+            assertEquals(path, path, resolver.getJCRPath(qpath));
+        } catch (NameException e) {
+            fail(path);
+        } catch (NamespaceException e) {
+            fail(path);
+        }
+    }
+
+    /**
+     * Checks that the given path fails to resolve.
+     *
+     * @param path JCR path
+     */
+    private void assertInvalidPath(String path) {
+        try {
+            resolver.getQPath(path);
+            fail(path);
+        } catch (NameException e) {
+        } catch (NamespaceException e) {
+        }
+    }
+
+    /**
+     * Tests that valid paths are properly resolved.
+     */
+    public void testValidPaths() {
+        assertValidPath("/");
+        assertValidPath(".");
+        assertValidPath("..");
+        assertValidPath("x");
+        assertValidPath("x:y");
+        assertValidPath("x[2]");
+        assertValidPath("x:y[123]");
+
+        assertValidPath("/a/b/c");
+        assertValidPath("/prefix:name/prefix:name");
+        assertValidPath("/name[2]/name[2]");
+        assertValidPath("/prefix:name[2]/prefix:name[2]");
+
+        assertValidPath("a/b/c");
+        assertValidPath("prefix:name/prefix:name");
+        assertValidPath("name[2]/name[2]");
+        assertValidPath("prefix:name[2]/prefix:name[2]");
+
+        assertValidPath("/a/../b");
+        assertValidPath("./../.");
+        assertValidPath("/a/./b");
+        assertValidPath("/a/b/../..");
+        assertValidPath("/a/b/c/../d/..././f");
+        assertValidPath("../a/b/../../../../f");
+        assertValidPath("a/../..");
+        assertValidPath("../../a/.");
+
+        // TODO: Should these paths be detected as invalid by the parser?
+        assertValidPath("/..");
+        assertValidPath("/a/b/../../..");
+    }
+
+    /**
+     * Tests that resolution of invalid paths fails.
+     */
+    public void testInvalidPaths() {
+        assertInvalidPath("");
+        assertInvalidPath("//");
+        //assertInvalidPath("x/");  // TODO: was valid with jcr-commons-path but not with pathresolver? check again
+        assertInvalidPath("x:");
+        assertInvalidPath("x:/");
+        assertInvalidPath("x[]");
+        //assertInvalidPath("x:y/"); // TODO: was valid with jcr-commons-path but not with pathresolver? check again
+        //assertInvalidPath("x:y[1]/"); // TODO: was valid with jcr-commons-path but not with pathresolver? check again
+        assertInvalidPath("x:y[");
+        assertInvalidPath("x:y[]");
+        assertInvalidPath("x:y[1");
+        assertInvalidPath("x:y[1]2");
+        assertInvalidPath("x:y[1]]");
+        assertInvalidPath("x:y[[1]");
+        assertInvalidPath(" /a/b/c/");
+        assertInvalidPath("/a/b/c/ ");
+        assertInvalidPath("/:name/prefix:name");
+        assertInvalidPath("/prefix:name ");
+        assertInvalidPath("/prefix: name");
+        assertInvalidPath("/ prefix:name");
+        assertInvalidPath("/prefix : name");
+        assertInvalidPath("/name[0]/name[2]");
+        assertInvalidPath("/prefix:name[2]foo/prefix:name[2]");
+        assertInvalidPath(":name/prefix:name");
+        assertInvalidPath("name[0]/name[2]");
+        assertInvalidPath("prefix:name[2]foo/prefix:name[2]");
+    }
+
+}

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

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/ParsingPathResolverTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/PathParserTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/PathParserTest.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/PathParserTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/PathParserTest.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,213 @@
+/*
+ * 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.conversion;
+
+import junit.framework.TestCase;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.jackrabbit.name.JcrPath;
+import org.apache.jackrabbit.name.NameFactoryImpl;
+import org.apache.jackrabbit.name.PathFactoryImpl;
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PathFactory;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * PathParserTest
+ */
+public class PathParserTest extends TestCase {
+
+    private final PathFactory factory = PathFactoryImpl.getInstance();
+    private final NameResolver resolver;
+    private final PathResolver pathResolver;
+
+    private JcrPath[] tests = JcrPath.getTests();
+
+    private static int NUM_TESTS = 1;
+
+    public PathParserTest() {
+        resolver = new ParsingNameResolver(NameFactoryImpl.getInstance(), new DummyNamespaceResolver());
+        pathResolver = new ParsingPathResolver(factory, resolver);
+    }
+
+    public void testParse() throws Exception {
+        for (int i=0; i<tests.length; i++) {
+            JcrPath t = tests[i];
+            long t1 = System.currentTimeMillis();
+            for (int j=0; j<NUM_TESTS; j++) {
+                try {
+                    Path p = PathParser.parse(t.path, resolver, factory);
+                    if (t.normalizedPath==null) {
+                        if (!t.isValid()) {
+                            fail("Should throw MalformedPathException: " + t.path);
+                        }
+                        assertEquals("\"" + t.path + "\".create(false)", t.path,  pathResolver.getJCRPath(p));
+                        assertEquals("\"" + t.path + "\".isNormalized()", t.isNormalized(), p.isNormalized());
+                        assertEquals("\"" + t.path + "\".isAbsolute()", t.isAbsolute(), p.isAbsolute());
+                    } else {
+                        // check with normalization
+                        p = p.getNormalizedPath();
+                        if (!t.isValid()) {
+                            fail("Should throw MalformedPathException: " + t.path);
+                        }
+                        assertEquals("\"" + t.path + "\".create(true)", t.normalizedPath, pathResolver.getJCRPath(p));
+                        assertEquals("\"" + t.path + "\".isAbsolute()", t.isAbsolute(), p.isAbsolute());
+                    }
+                } catch (RepositoryException e) {
+                    if (t.isValid()) {
+                        System.out.println(t.path);
+                        throw e;
+                    }
+                }
+            }
+            long t2 = System.currentTimeMillis();
+            if (NUM_TESTS>1) {
+                System.out.println("testCreate():\t" + t + "\t" + (t2-t1) + "\tms");
+            }
+        }
+    }
+
+    public void testCheckFormat() throws Exception {
+        for (int i=0; i<tests.length; i++) {
+            JcrPath t = tests[i];
+            long t1 = System.currentTimeMillis();
+            for (int j=0; j<NUM_TESTS; j++) {
+                if (t.normalizedPath==null) {
+                    // check just creation
+                    boolean isValid = true;
+                    try {
+                        PathParser.checkFormat(t.path);
+                    } catch (MalformedPathException e) {
+                        isValid = false;
+                    }
+                    assertEquals("\"" + t.path + "\".checkFormat()", t.isValid(),  isValid);
+                }
+            }
+            long t2 = System.currentTimeMillis();
+            if (NUM_TESTS>1) {
+                System.out.println("testCheckFormat():\t" + t + "\t" + (t2-t1) + "\tms");
+            }
+        }
+    }
+
+   public void testNormalizedPaths() throws Exception {
+        List paths = new ArrayList();
+        // normalized paths
+        paths.add(PathParser.parse("/", resolver, factory));
+        paths.add(PathParser.parse("/foo", resolver, factory));
+        paths.add(PathParser.parse("/foo/bar", resolver, factory));
+        paths.add(PathParser.parse("foo/bar", resolver, factory));
+        paths.add(PathParser.parse("foo", resolver, factory));
+        paths.add(PathParser.parse("../../foo/bar", resolver, factory));
+        paths.add(PathParser.parse("..", resolver, factory));
+
+        for (Iterator it = paths.iterator(); it.hasNext(); ) {
+            Path path = (Path) it.next();
+            assertTrue("path is not normalized: " + path, path.isNormalized());
+        }
+
+        paths.clear();
+
+        // not normalized paths
+        paths.add(PathParser.parse("/foo/..", resolver, factory));
+        paths.add(PathParser.parse("/foo/.", resolver, factory));
+        paths.add(PathParser.parse("/foo/../bar", resolver, factory));
+        paths.add(PathParser.parse("/foo/./bar", resolver, factory));
+        paths.add(PathParser.parse("./foo", resolver, factory));
+        paths.add(PathParser.parse(".", resolver, factory));
+        paths.add(PathParser.parse("foo/..", resolver, factory));
+        paths.add(PathParser.parse("../foo/..", resolver, factory));
+        paths.add(PathParser.parse("../foo/.", resolver, factory));
+
+        for (Iterator it = paths.iterator(); it.hasNext(); ) {
+            Path path = (Path) it.next();
+            assertFalse("path is normalized: " + path, path.isNormalized());
+        }
+    }
+
+    public void testAbsolutePaths() throws Exception {
+        List paths = new ArrayList();
+
+        // absolute paths
+        paths.add(PathParser.parse("/", resolver, factory));
+        paths.add(PathParser.parse("/foo", resolver, factory));
+        paths.add(PathParser.parse("/foo/bar", resolver, factory));
+        paths.add(PathParser.parse("/foo/../bar", resolver, factory));
+        paths.add(PathParser.parse("/foo/..", resolver, factory));
+        paths.add(PathParser.parse("/foo/./bar", resolver, factory));
+        paths.add(PathParser.parse("/foo/.././bar/./foo", resolver, factory));
+
+        for (Iterator it = paths.iterator(); it.hasNext(); ) {
+            Path path = (Path) it.next();
+            assertTrue("path is not absolute: " + path, path.isAbsolute());
+        }
+
+        paths.clear();
+
+        // not absoulute paths
+        paths.add(PathParser.parse("foo/..", resolver, factory));
+        paths.add(PathParser.parse("foo/.", resolver, factory));
+        paths.add(PathParser.parse("foo/../bar", resolver, factory));
+        paths.add(PathParser.parse("foo/./bar", resolver, factory));
+        paths.add(PathParser.parse("./foo", resolver, factory));
+        paths.add(PathParser.parse(".", resolver, factory));
+        paths.add(PathParser.parse("foo/..", resolver, factory));
+        paths.add(PathParser.parse("../foo/..", resolver, factory));
+        paths.add(PathParser.parse("../foo/.", resolver, factory));
+
+        for (Iterator it = paths.iterator(); it.hasNext(); ) {
+            Path path = (Path) it.next();
+            assertFalse("path is absolute: " + path, path.isAbsolute());
+        }
+    }
+
+    public void testCanonicalPaths() throws Exception {
+        List paths = new ArrayList();
+
+        // canonical paths
+        paths.add(PathParser.parse("/", resolver, factory));
+        paths.add(PathParser.parse("/foo", resolver, factory));
+        paths.add(PathParser.parse("/foo/bar", resolver, factory));
+
+        for (Iterator it = paths.iterator(); it.hasNext(); ) {
+            Path path = (Path) it.next();
+            assertTrue("path is not canonical: " + path, path.isCanonical());
+        }
+
+        paths.clear();
+
+        // not canonical paths
+        paths.add(PathParser.parse("/foo/..", resolver, factory));
+        paths.add(PathParser.parse("/foo/.", resolver, factory));
+        paths.add(PathParser.parse("/foo/../bar", resolver, factory));
+        paths.add(PathParser.parse("/foo/./bar", resolver, factory));
+        paths.add(PathParser.parse("./foo", resolver, factory));
+        paths.add(PathParser.parse(".", resolver, factory));
+        paths.add(PathParser.parse("/foo/..", resolver, factory));
+        paths.add(PathParser.parse("/../foo/..", resolver, factory));
+        paths.add(PathParser.parse("/../foo/.", resolver, factory));
+
+        for (Iterator it = paths.iterator(); it.hasNext(); ) {
+            Path path = (Path) it.next();
+            assertFalse("path is canonical: " + path, path.isCanonical());
+        }
+    }
+}

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

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/PathParserTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/TestAll.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/TestAll.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/TestAll.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,46 @@
+/*
+ * 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.conversion;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.jackrabbit.name.PathBuilderTest;
+
+/**
+ * Test suite that includes all testcases for the Core module.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     *
+     * @return a <code>Test</code> suite that executes all tests inside this
+     *         package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("conversion tests");
+
+        suite.addTestSuite(ParsingNameResolverTest.class);
+        suite.addTestSuite(ParsingPathResolverTest.class);
+        suite.addTestSuite(NameParserTest.class);
+        suite.addTestSuite(PathParserTest.class);
+
+        return suite;
+    }
+}

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

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/conversion/TestAll.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/JcrName.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/JcrName.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/JcrName.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/JcrName.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,88 @@
+/*
+ * 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.name;
+
+import java.util.ArrayList;
+
+/**
+ * <code>JcrName</code>...
+ */
+public final class JcrName {
+
+    public final String jcrName;
+    public final String prefix;
+    public final String name;
+
+    // create tests
+    private static ArrayList list = new ArrayList();
+    static {
+        // valid names
+        list.add(new JcrName("a", "", "a"));
+        list.add(new JcrName("name", "", "name"));
+        list.add(new JcrName("na me", "", "na me"));
+        list.add(new JcrName("prefix:name", "prefix", "name"));
+        list.add(new JcrName("prefix:na me", "prefix", "na me"));
+        list.add(new JcrName("...", "", "..."));
+        list.add(new JcrName(".a.", "", ".a."));
+
+        // invalid names
+        list.add(new JcrName(":name"));
+        list.add(new JcrName("."));
+        list.add(new JcrName(".."));
+        list.add(new JcrName("pre:"));
+        list.add(new JcrName(""));
+        list.add(new JcrName(" name"));
+        list.add(new JcrName(" prefix: name"));
+        list.add(new JcrName("prefix: name"));
+        list.add(new JcrName("prefix:name "));
+        list.add(new JcrName("pre fix:name"));
+        list.add(new JcrName("prefix :name"));
+        list.add(new JcrName("name/name"));
+        list.add(new JcrName("name[name"));
+        list.add(new JcrName("name]name"));
+        list.add(new JcrName("name*name"));
+        list.add(new JcrName("prefix:name:name"));
+    }
+
+    private static JcrName[] tests = (JcrName[]) list.toArray(new JcrName[list.size()]);
+
+    public static JcrName[] getTests() {
+        return tests;
+    }
+
+    public JcrName(String jcrName) {
+        this(jcrName, null, null);
+    }
+
+    public JcrName(String jcrName, String prefix, String name) {
+        this.jcrName = jcrName;
+        this.prefix = prefix;
+        this.name = name;
+    }
+
+    public boolean isValid() {
+        return name!=null;
+    }
+
+    public String toString() {
+        StringBuffer b = new StringBuffer(jcrName);
+        if (isValid()) {
+            b.append(",VAL");
+        }
+        return b.toString();
+    }
+}
\ No newline at end of file

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

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/JcrName.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/JcrPath.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/JcrPath.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/JcrPath.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/JcrPath.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,142 @@
+/*
+ * 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.name;
+
+import java.util.ArrayList;
+
+/**
+ * <code>PathParserTest</code>...
+ */
+public final class JcrPath {
+
+    private static final int ABS = 1;
+    private static final int NOR = 2;
+    private static final int VAL = 4;
+
+    public final String path;
+    public final String normalizedPath;
+    public final int flags;
+
+    // create tests
+    private static ArrayList list = new ArrayList();
+    static {
+        // absolute paths
+        list.add(new JcrPath("/", NOR|VAL));
+        list.add(new JcrPath("/", NOR|VAL));
+        list.add(new JcrPath("/", NOR|VAL));
+        list.add(new JcrPath("/a/b/c", NOR|VAL));
+        list.add(new JcrPath("/prefix:name/prefix:name", NOR|VAL));
+        list.add(new JcrPath("/name[2]/name[2]", NOR|VAL));
+        list.add(new JcrPath("/prefix:name[2]/prefix:name[2]", NOR|VAL));
+        list.add(new JcrPath("a/b/c/", "a/b/c", NOR|VAL));
+        list.add(new JcrPath("/a/b/c/", "/a/b/c", NOR|VAL));
+        list.add(new JcrPath("/a/..../", "/a/....", NOR|VAL));
+        list.add(new JcrPath("/a/b:.a./", "/a/b:.a.", NOR|VAL));
+
+        // relative paths
+        list.add(new JcrPath("a/b/c", NOR|VAL));
+        list.add(new JcrPath("prefix:name/prefix:name", NOR|VAL));
+        list.add(new JcrPath("name[2]/name[2]", NOR|VAL));
+        list.add(new JcrPath("prefix:name[2]/prefix:name[2]", NOR|VAL));
+        list.add(new JcrPath(".a./.b.", NOR|VAL));
+        list.add(new JcrPath(".../...", NOR|VAL));
+
+        // invalid paths
+        list.add(new JcrPath(""));
+        list.add(new JcrPath(" /a/b/c/"));
+        list.add(new JcrPath("/a/b/c/ "));
+        list.add(new JcrPath("/:name/prefix:name"));
+        list.add(new JcrPath("/prefix:name "));
+        list.add(new JcrPath("/prefix: name"));
+        list.add(new JcrPath("/ prefix:name"));
+        list.add(new JcrPath("/prefix : name"));
+        list.add(new JcrPath("/name[0]/name[2]"));
+        list.add(new JcrPath("/prefix:name[2]foo/prefix:name[2]"));
+        list.add(new JcrPath(":name/prefix:name"));
+        list.add(new JcrPath("name[0]/name[2]"));
+        list.add(new JcrPath("prefix:name[2]foo/prefix:name[2]"));
+
+        // not normalized paths
+        list.add(new JcrPath("/a/../b", "/b", VAL));
+        list.add(new JcrPath("./../.", "..", VAL));
+        list.add(new JcrPath("/a/./b", "/a/b", VAL));
+        list.add(new JcrPath("/a/b/../..", "/", VAL));
+        list.add(new JcrPath("/a/b/c/../d/..././f", "/a/b/d/.../f", VAL));
+        list.add(new JcrPath("../a/b/../../../../f", "../../../f", VAL));
+        list.add(new JcrPath("a/../..", "..", VAL));
+        list.add(new JcrPath("../../a/.", "../../a", VAL));
+
+        // invalid normalized paths
+        list.add(new JcrPath("/..", "/..", 0));
+        list.add(new JcrPath("/a/b/../../..", "/a/b/../../..", 0));
+    }
+
+    /**
+     * creates an invalid path test
+     * @param path
+     */
+    public JcrPath(String path) {
+        this(path, null, 0);
+    }
+
+    /**
+     * @param path
+     * @param flags
+     */
+    public JcrPath(String path, int flags) {
+        this(path, null, flags);
+    }
+
+    public JcrPath(String path, String normalizedPath, int flags) {
+        this.path = path;
+        this.normalizedPath = normalizedPath;
+        this.flags = flags | ((path.length()>0 && path.charAt(0)=='/') ? ABS : 0);
+    }
+
+    public static JcrPath[] getTests() {
+        return (JcrPath[]) list.toArray(new JcrPath[list.size()]);
+    }
+
+    public boolean isAbsolute() {
+        return (flags&ABS) > 0;
+    }
+
+    public boolean isNormalized() {
+        return (flags&NOR) > 0;
+    }
+
+    public boolean isValid() {
+        return (flags&VAL) > 0;
+    }
+
+    public String toString() {
+        StringBuffer b = new StringBuffer(path);
+        if (normalizedPath!=null) {
+            b.append(" -> ").append(normalizedPath);
+        }
+        if (isAbsolute()) {
+            b.append(",ABS");
+        }
+        if (isNormalized()) {
+            b.append(",NOR");
+        }
+        if (isValid()) {
+            b.append(",VAL");
+        }
+        return b.toString();
+    }
+}
\ No newline at end of file

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

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/JcrPath.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/NameFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/NameFactoryTest.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/NameFactoryTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/NameFactoryTest.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,112 @@
+/*
+ * 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.name;
+
+import org.apache.jackrabbit.spi.NameFactory;
+import org.apache.jackrabbit.spi.Name;
+import junit.framework.TestCase;
+
+/**
+ * This Class implements a test case for the 'NameFactoryImpl' class.
+ */
+public class NameFactoryTest extends TestCase {
+
+    private final NameFactory factory;
+    private JcrName[] tests = JcrName.getTests();
+
+    public NameFactoryTest() {
+        factory = NameFactoryImpl.getInstance();
+        tests = JcrName.getTests();
+    }
+
+    public void testEquality() throws Exception {
+        for (int i=0; i<tests.length; i++) {
+            final JcrName t = tests[i];
+            if (t.isValid()) {
+                Name n1 = new Name() {
+                    public String getLocalName() {
+                        return t.jcrName;
+                    }
+
+                    public String getNamespaceURI() {
+                        return t.prefix;
+                    }
+
+                    public int compareTo(Object o) {
+                        throw new UnsupportedOperationException();
+                    }
+                };
+
+                Name n2 = factory.create(t.prefix, t.jcrName);
+                assertTrue(n2.equals(n1));
+            }
+        }
+    }
+
+    public void testCreationFromString() throws Exception {
+        for (int i=0; i<tests.length; i++) {
+            final JcrName t = tests[i];
+            if (t.isValid()) {
+                Name n1 = factory.create(t.prefix, t.jcrName);
+                Name n2 = factory.create(n1.toString());
+
+                assertTrue(n1.getLocalName().equals(n2.getLocalName()));
+                assertTrue(n1.getNamespaceURI().equals(n2.getNamespaceURI()));
+                assertTrue(n2.equals(n1));
+            }
+        }
+    }
+
+    public void testCreationFromOtherString() throws Exception {
+        for (int i=0; i<tests.length; i++) {
+            final JcrName t = tests[i];
+            if (t.isValid()) {
+                Name n1 = new Name() {
+                    public String getLocalName() {
+                        return t.jcrName;
+                    }
+
+                    public String getNamespaceURI() {
+                        return t.prefix;
+                    }
+
+                    public int compareTo(Object o) {
+                        throw new UnsupportedOperationException();
+                    }
+
+                    public String toString() {
+                        return "{" + t.prefix + "}" + t.jcrName;
+                    }
+
+                    public boolean equals(Object obj) {
+                        if (obj instanceof Name) {
+                            Name n = (Name) obj;
+                            return n.getLocalName().equals(t.jcrName) && n.getNamespaceURI().equals(t.prefix);
+                        }
+                        return false;
+                    }
+                };
+
+                Name n2 = factory.create(n1.toString());
+
+                assertTrue(n1.getLocalName().equals(n2.getLocalName()));
+                assertTrue(n1.getNamespaceURI().equals(n2.getNamespaceURI()));
+                assertTrue(n2.equals(n1));
+            }
+        }
+    }
+}

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

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/NameFactoryTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/PathBuilderTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/PathBuilderTest.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/PathBuilderTest.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/PathBuilderTest.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,198 @@
+/*
+ * 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.name;
+
+import org.apache.jackrabbit.spi.Path;
+import org.apache.jackrabbit.spi.PathFactory;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.namespace.NamespaceResolver;
+import org.apache.jackrabbit.conversion.PathResolver;
+import org.apache.jackrabbit.conversion.NameResolver;
+import org.apache.jackrabbit.conversion.ParsingNameResolver;
+import org.apache.jackrabbit.conversion.ParsingPathResolver;
+import org.apache.jackrabbit.conversion.NameParser;
+import junit.framework.TestCase;
+
+import java.util.Vector;
+
+/**
+ * <code>PathBuilderTest</code>...
+ */
+public class PathBuilderTest extends TestCase {
+
+    private final PathFactory factory = PathFactoryImpl.getInstance();
+    private final NamespaceResolver nsResolver = new NamespaceResolver() {
+        public String getURI(String prefix) {
+            return prefix;
+        }
+        public String getPrefix(String uri) {
+            return uri;
+        }
+    };
+    private final PathResolver pathResolver;
+
+    private JcrPath[] tests = JcrPath.getTests();
+
+    public PathBuilderTest() {
+        NameResolver nameResolver = new ParsingNameResolver(NameFactoryImpl.getInstance(), nsResolver);
+        pathResolver = new ParsingPathResolver(factory, nameResolver);
+    }
+
+    public void testBuilder() throws Exception {
+        for (int i=0; i<tests.length; i++) {
+            JcrPath t = tests[i];
+            if (t.isValid()) {
+                if (t.normalizedPath==null) {
+                    // check just creation
+                    Path p = build(t.path, false);
+                    assertEquals("\"" + t.path + "\".create(false)", t.path,  pathResolver.getJCRPath(p));
+                    assertEquals("\"" + t.path + "\".isNormalized()", t.isNormalized(), p.isNormalized());
+                    assertEquals("\"" + t.path + "\".isAbsolute()", t.isAbsolute(), p.isAbsolute());
+                } else {
+                    // check with normalization
+                    Path p = build(t.path, true);
+                    assertEquals("\"" + t.path + "\".create(true)", t.normalizedPath, pathResolver.getJCRPath(p));
+                    assertEquals("\"" + t.path + "\".isAbsolute()", t.isAbsolute(), p.isAbsolute());
+                }
+            }
+        }
+    }
+
+    public void testBuilderReverse() throws Exception {
+        for (int i=0; i<tests.length; i++) {
+            JcrPath t = tests[i];
+            if (t.isValid()) {
+                if (t.normalizedPath==null) {
+                    // check just creation
+                    Path p = buildReverse(t.path, false);
+                    assertEquals("\"" + t.path + "\".create(false)", t.path,  pathResolver.getJCRPath(p));
+                    assertEquals("\"" + t.path + "\".isNormalized()", t.isNormalized(), p.isNormalized());
+                    assertEquals("\"" + t.path + "\".isAbsolute()", t.isAbsolute(), p.isAbsolute());
+                } else {
+                    // check with normalization
+                    Path p = buildReverse(t.path, true);
+                    assertEquals("\"" + t.path + "\".create(true)", t.normalizedPath, pathResolver.getJCRPath(p));
+                    assertEquals("\"" + t.path + "\".isAbsolute()", t.isAbsolute(), p.isAbsolute());
+                }
+            }
+        }
+    }
+
+    private Path build(String path, boolean normalize)
+            throws Exception {
+        PathBuilder builder = new PathBuilder();
+        String[] elems = explode(path, '/', false);
+        if (path.startsWith("/")) {
+            builder.addRoot();
+        }
+        for (int i=0; i<elems.length; i++) {
+            int pos = elems[i].indexOf('[');
+            String elem;
+            Name name;
+            int index;
+            if (pos<0) {
+                elem = elems[i];
+                index = -1;
+            } else {
+                index = Integer.parseInt(elems[i].substring(pos+1, elems[i].length()-1));
+                elem = elems[i].substring(0, pos);
+            }
+            if (".".equals(elem)) {
+                builder.addLast(factory.getCurrentElement());
+            } else if ("..".equals(elems[i])) {
+                builder.addLast(factory.getParentElement());
+            } else {
+                name = NameParser.parse(elem, nsResolver, NameFactoryImpl.getInstance());
+                if (index < 0) {
+                    builder.addLast(name);
+                } else {
+                    builder.addLast(name, index);
+                }
+            }
+        }
+        return normalize ? builder.getPath().getNormalizedPath() : builder.getPath();
+    }
+
+    private Path buildReverse(String path, boolean normalize)
+            throws Exception {
+        PathBuilder builder = new PathBuilder();
+        String[] elems = explode(path, '/', false);
+        for (int i=elems.length-1; i>=0; i--) {
+            int pos = elems[i].indexOf('[');
+            String elem;
+            Name name;
+            int index;
+            if (pos<0) {
+                elem = elems[i];
+                index = -1;
+            } else {
+                index = Integer.parseInt(elems[i].substring(pos+1, elems[i].length()-1));
+                elem = elems[i].substring(0, pos);
+            }
+            if (".".equals(elem)) {
+                builder.addFirst(factory.getCurrentElement());
+            } else if ("..".equals(elems[i])) {
+                builder.addFirst(factory.getParentElement());
+            } else {
+                name = NameParser.parse(elem, nsResolver, NameFactoryImpl.getInstance());
+                if (index < 0) {
+                    builder.addFirst(name);
+                } else {
+                    builder.addFirst(name, index);
+                }
+            }
+        }
+        if (path.startsWith("/")) {
+            builder.addRoot();
+        }
+        return normalize ? builder.getPath().getNormalizedPath() : builder.getPath();
+    }
+
+    /**
+     * returns an array of strings decomposed of the original string, split at
+     * every occurance of 'ch'.
+     * @param str the string to decompose
+     * @param ch the character to use a split pattern
+     * @param respectEmpty if <code>true</code>, empty elements are generated
+     * @return an array of strings
+     */
+    private static String[] explode(String str, int ch, boolean respectEmpty) {
+        if (str == null) {
+            return new String[0];
+        }
+
+        Vector strings = new Vector();
+        int pos     = 0;
+        int lastpos = 0;
+
+        // add snipples
+        while ((pos = str.indexOf(ch, lastpos)) >= 0) {
+            if (pos-lastpos>0 || respectEmpty)
+                strings.add(str.substring(lastpos, pos));
+            lastpos = pos+1;
+        }
+        // add rest
+        if (lastpos < str.length()) {
+            strings.add(str.substring(lastpos));
+        } else if (respectEmpty && lastpos==str.length()) {
+            strings.add("");
+        }
+
+        // return stringarray
+        return (String[]) strings.toArray(new String[strings.size()]);
+    }
+}
\ No newline at end of file

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

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/PathBuilderTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/TestAll.java?rev=586058&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/TestAll.java (added)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/TestAll.java Thu Oct 18 11:34:57 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.name;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Test suite that includes all testcases for the Core module.
+ */
+public class TestAll extends TestCase {
+
+    /**
+     * Returns a <code>Test</code> suite that executes all tests inside this
+     * package.
+     *
+     * @return a <code>Test</code> suite that executes all tests inside this
+     *         package.
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("name tests");
+
+        suite.addTestSuite(NameFactoryTest.class);
+        // TODO: add PathFactory test
+        suite.addTestSuite(PathBuilderTest.class);
+
+        return suite;
+    }
+}

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

Propchange: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/name/TestAll.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java?rev=586058&r1=586057&r2=586058&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java (original)
+++ jackrabbit/trunk/jackrabbit-spi-commons/src/test/java/org/apache/jackrabbit/value/QValueTest.java Thu Oct 18 11:34:57 2007
@@ -36,10 +36,12 @@
 
 import org.apache.jackrabbit.util.ISO8601;
 import org.apache.jackrabbit.uuid.UUID;
-import org.apache.jackrabbit.name.QName;
-import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.spi.Name;
+import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.QValueFactory;
+import org.apache.jackrabbit.name.NameConstants;
+import org.apache.jackrabbit.name.PathFactoryImpl;
 
 /**
  * <code>QValueTest</code>...
@@ -48,6 +50,7 @@
 
     private final Calendar CALENDAR = Calendar.getInstance();
     private static final String REFERENCE = UUID.randomUUID().toString();
+    private static final Path ROOT_PATH = PathFactoryImpl.getInstance().getRootPath();
 
     private static final QValueFactory factory = QValueFactoryImpl.getInstance();
 
@@ -60,7 +63,7 @@
             // ok
         }
         try {
-            factory.create((String) null, PropertyType.DATE);
+            factory.create(null, PropertyType.DATE);
             fail();
         } catch (IllegalArgumentException e) {
             // ok
@@ -92,7 +95,7 @@
     //----------------------------------------------------------< REFERENCE >---
     public void testNullReferenceValue() throws IOException {
         try {
-            factory.create((String) null, PropertyType.REFERENCE);
+            factory.create(null, PropertyType.REFERENCE);
             fail();
         } catch (IllegalArgumentException e) {
             // ok
@@ -117,10 +120,10 @@
     }
 
 
-    //--------------------------------------------------------------< QName >---
+    //---------------------------------------------------------------< Name >---
     public void testNullQNameValue() throws IOException {
         try {
-            factory.create((QName) null);
+            factory.create((Name) null);
             fail();
         } catch (IllegalArgumentException e) {
             // ok
@@ -128,21 +131,21 @@
     }
 
     public void testQNameValueType() throws IOException {
-        QValue v = factory.create(QName.JCR_DATA);
+        QValue v = factory.create(NameConstants.JCR_DATA);
         assertTrue(v.getType() == PropertyType.NAME);
-        v = factory.create(QName.JCR_DATA.toString(), PropertyType.NAME);
+        v = factory.create(NameConstants.JCR_DATA.toString(), PropertyType.NAME);
         assertTrue(v.getType() == PropertyType.NAME);
     }
 
     public void testQNameValueEquality() throws IOException {
-        QValue v = factory.create(QName.JCR_DATA);
-        QValue v2 = factory.create(QName.JCR_DATA.toString(), PropertyType.NAME);
+        QValue v = factory.create(NameConstants.JCR_DATA);
+        QValue v2 = factory.create(NameConstants.JCR_DATA.toString(), PropertyType.NAME);
         assertTrue(v.equals(v2));
     }
 
     public void testQNameValueGetString() throws IOException, RepositoryException {
-        QValue v = factory.create(QName.JCR_DATA);
-        assertTrue(v.getString().equals(QName.JCR_DATA.toString()));
+        QValue v = factory.create(NameConstants.JCR_DATA);
+        assertTrue(v.getString().equals(NameConstants.JCR_DATA.toString()));
     }
 
     //--------------------------------------------------------------< QPath >---
@@ -156,22 +159,22 @@
     }
 
     public void testPathValueType() throws IOException {
-        QValue v = factory.create(Path.ROOT);
+        QValue v = factory.create(ROOT_PATH);
         assertTrue(v.getType() == PropertyType.PATH);
-        v = factory.create(Path.ROOT.toString(), PropertyType.PATH);
+        v = factory.create(ROOT_PATH.toString(), PropertyType.PATH);
         assertTrue(v.getType() == PropertyType.PATH);
     }
 
 
     public void testPathValueEquality() throws IOException {
-        QValue v = factory.create(Path.ROOT);
-        QValue v2 = factory.create(Path.ROOT.toString(), PropertyType.PATH);
+        QValue v = factory.create(ROOT_PATH);
+        QValue v2 = factory.create(ROOT_PATH.toString(), PropertyType.PATH);
         assertTrue(v.equals(v2));
     }
 
     public void testPathValueGetString() throws IOException, RepositoryException {
-        QValue v = factory.create(Path.ROOT);
-        assertTrue(v.getString().equals(Path.ROOT.toString()));
+        QValue v = factory.create(ROOT_PATH);
+        assertTrue(v.getString().equals(ROOT_PATH.toString()));
     }
 
     //-------------------------------------------------------------< BINARY >---



Mime
View raw message