jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r428023 - in /jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name: NameFormat.java Path.java QName.java
Date Wed, 02 Aug 2006 15:25:45 GMT
Author: stefan
Date: Wed Aug  2 08:25:45 2006
New Revision: 428023

URL: http://svn.apache.org/viewvc?rev=428023&view=rev
Log:
some minor cleanups and javadoc improvements

Modified:
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameFormat.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/Path.java
    jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/QName.java

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameFormat.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameFormat.java?rev=428023&r1=428022&r2=428023&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameFormat.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/NameFormat.java Wed
Aug  2 08:25:45 2006
@@ -28,7 +28,7 @@
 public class NameFormat {
 
     /**
-     * The reqular expression pattern used to validate and doParse
+     * The reqular expression pattern used to validate and parse
      * qualified names.
      * <p/>
      * The pattern contains the following groups:
@@ -38,7 +38,8 @@
      * <li>group 3 is localName
      * </ul>
      */
-    private static final Pattern NAME_PATTERN = Pattern.compile("(([^ /:\\[\\]*'\"|](?:[^/:\\[\\]*'\"|]*[^
/:\\[\\]*'\"|])?):)?"
+    private static final Pattern NAME_PATTERN = Pattern.compile(
+            "(([^ /:\\[\\]*'\"|](?:[^/:\\[\\]*'\"|]*[^ /:\\[\\]*'\"|])?):)?"
             + "([^ /:\\[\\]*'\"|](?:[^/:\\[\\]*'\"|]*[^ /:\\[\\]*'\"|])?)");
 
     /**

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/Path.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/Path.java?rev=428023&r1=428022&r2=428023&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/Path.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/Path.java Wed Aug
 2 08:25:45 2006
@@ -384,12 +384,18 @@
                 if (last.denotesRoot()) {
                     // the first element is the root element;
                     // ".." would refer to the parent of root
-                    throw new MalformedPathException("Path can not be canonicalized: unresolvable
'..' element");
+                    throw new MalformedPathException(
+                            "Path can not be canonicalized: unresolvable '..' element");
                 }
                 queue.removeLast();
-                last = queue.isEmpty() ? PARENT_ELEMENT : (PathElement) queue.getLast();
+                if (queue.isEmpty()) {
+                    last = PARENT_ELEMENT;
+                } else {
+                    last = (PathElement) queue.getLast();
+                }
             } else if (!elem.denotesCurrent()) {
-                queue.add(last = elem);
+                last = elem;
+                queue.add(last);
             }
         }
         if (queue.isEmpty()) {
@@ -939,26 +945,15 @@
             // no need to check the path format, assuming all names correct
             return new Path(elements, isNormalized);
         }
-
-        /**
-         * {@inheritDoc}
-         */
-        public Object clone() throws CloneNotSupportedException {
-            super.clone();
-            PathBuilder clone = new PathBuilder();
-            clone.queue.addAll(queue);
-            return clone;
-        }
     }
 
-    //---------------------------------------------------------< Path Elements >
-
+    //---------------------------------------------< PathElement & subclasses >
     /**
      * Object representation of a single JCR path element. A PathElement
      * object contains the qualified name and optional index of a single
      * JCR path element.
      * <p/>
-     * Once created, a NameElement object is immutable.
+     * Once created, a PathElement object is immutable.
      */
     public abstract static class PathElement {
 
@@ -973,9 +968,11 @@
          */
         private final int index;
 
-
         /**
-         * Creates a path element with the given qualified name and index.
+         * Private constructor for creating a path element with the given
+         * qualified name and index. Instead of using this constructor directly
+         * the factory methods {@link #create(QName)} and {@link #create(QName, int)}
+         * should be used.
          *
          * @param name  qualified name
          * @param index index
@@ -986,12 +983,12 @@
         }
 
         /**
-         * Creates a new path element with the given qualified name and index.
-         * If the name is equals to the name of a special element, like the
-         * {@link #PARENT_ELEMENT},{@link #CURRENT_ELEMENT} or the
-         * {@link #ROOT_ELEMENT}, then it's instance is returned.
+         * Creates a path element with the given qualified name.
+         * The created path element does not contain an explicit index.
          * <p/>
-         * the private constructor must never be called but from these 2 methods.
+         * If the specified name denotes a <i>special</i> path element (either
+         * {@link Path#PARENT_ELEMENT}, {@link Path#CURRENT_ELEMENT} or
+         * {@link Path#ROOT_ELEMENT}) then the associated constant is returned.
          *
          * @param name the name of the element
          * @return a path element
@@ -1012,30 +1009,34 @@
         }
 
         /**
-         * Creates a new path element with the given qualified name and index.
-         * If the name is equals to the name of a special element, like the
-         * {@link #PARENT_ELEMENT},{@link #CURRENT_ELEMENT} or the
-         * {@link #ROOT_ELEMENT}, then it's instance is returned.
+         * Same as {@link #create(QName)} except that an explicit index can be
+         * specified.
          * <p/>
-         * the private constructor must never be called but from these 2 methods.
+         * Note that an IllegalArgumentException will be thrown if the specified
+         * name denotes a <i>special</i> path element (either
+         * {@link Path#PARENT_ELEMENT}, {@link Path#CURRENT_ELEMENT} or
+         * {@link Path#ROOT_ELEMENT}) since an explicit index is not allowed
+         * in this context.
          *
          * @param name  the name of the element
          * @param index the 1-based index.
          * @return a path element
-         * @throws IllegalArgumentException if the name is <code>null</code>
or
-         *                                  if the given index is less than 1.
+         * @throws IllegalArgumentException if the name is <code>null</code>,
+         *                                  if the given index is less than 1
+         *                                  or if name denoting a special path
+         *                                  element and an index greater than 1
+         *                                  have been specified.
          */
         public static PathElement create(QName name, int index) {
             if (index < INDEX_DEFAULT) {
                 throw new IllegalArgumentException("index is 1-based.");
             } else if (name == null) {
                 throw new IllegalArgumentException("name must not be null");
-            } else if (name.equals(PARENT_ELEMENT.getName())) {
-                return PARENT_ELEMENT;
-            } else if (name.equals(CURRENT_ELEMENT.getName())) {
-                return CURRENT_ELEMENT;
-            } else if (name.equals(ROOT_ELEMENT.getName())) {
-                return ROOT_ELEMENT;
+            } else if (name.equals(PARENT_ELEMENT.getName())
+                    || name.equals(CURRENT_ELEMENT.getName())
+                    || name.equals(ROOT_ELEMENT.getName())) {
+                throw new IllegalArgumentException(
+                        "special path elements (root, '.' and '..') can not have an explicit
index");
             } else {
                 return new NameElement(name, index);
             }
@@ -1305,10 +1306,10 @@
         }
 
         /**
-         * Returns the JCR name of this path element.
-         *
-         * @param resolver
-         * @return ""
+         * {@inheritDoc}
+         * <p/>
+         * Returns <code>""</code>
+         * @return <code>""</code>
          */
         public String toJCRName(NamespaceResolver resolver) {
             return "";
@@ -1379,10 +1380,10 @@
         }
 
         /**
-         * Returns the JCR name of this path element.
-         *
-         * @param resolver
-         * @return {@link #LITERAL}
+         * {@inheritDoc}
+         * <p/>
+         * Returns <code>"."</code>
+         * @return <code>"."</code>
          */
         public String toJCRName(NamespaceResolver resolver) {
             return LITERAL;
@@ -1452,10 +1453,10 @@
         }
 
         /**
-         * Returns the JCR name of this path element.
-         *
-         * @param resolver
-         * @return {@link #LITERAL}
+         * {@inheritDoc}
+         * <p/>
+         * Returns <code>".."</code>
+         * @return <code>".."</code>
          */
         public String toJCRName(NamespaceResolver resolver) {
             return LITERAL;

Modified: jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/QName.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/QName.java?rev=428023&r1=428022&r2=428023&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/QName.java (original)
+++ jackrabbit/trunk/jackrabbit/src/main/java/org/apache/jackrabbit/name/QName.java Wed Aug
 2 08:25:45 2006
@@ -512,7 +512,7 @@
     /** The internalized namespace URI of this qualified name. */
     private final String namespaceURI;
 
-    /** The internalized local part of this qualified name. */
+    /** The local part of this qualified name. */
     private final String localName;
 
     /**
@@ -534,27 +534,15 @@
         if (localName == null) {
             throw new IllegalArgumentException("invalid localName specified");
         }
-        // internalize only namespaceURI to improve performance of QName
-        // comparisons. Please note that we do not internalize the localname
-        // since this could blow perm space for big repositories.
+        // internalize namespaceURI to improve performance of QName comparisons.
+        // Please note that we do *not* internalize localName since this could
+        // blow perm space for large repositories
         this.namespaceURI = namespaceURI.intern();
         this.localName = localName;
         hash = 0;
     }
 
-    /**
-     * Returns a new instance of this class with the same namespace URI and
-     * local name as has been deserialized.
-     * <p>
-     * If just sing plain serialization, the strings are just created but not
-     * internalized.
-     */
-    private Object readResolve() {
-        return new QName(namespaceURI, localName);
-    }
-
     //------------------------------------------------------< factory methods >
-
     /**
      * Parses the given prefixed JCR name into a qualified name using the
      * given namespace resolver.
@@ -708,8 +696,7 @@
         }
         if (obj instanceof QName) {
             QName other = (QName) obj;
-            // namespaceURI is internalized, we only have to compare their
-            // references
+            // we can use == operator for namespaceURI since it is internalized
             return namespaceURI == other.namespaceURI
                     && localName.equals(other.localName);
         }
@@ -763,12 +750,23 @@
         if (this == o) {
             return 0;
         }
+
         QName other = (QName) o;
-        // == comparison ok, because of .intern() strings
+        // we can use == operator for namespaceURI since it is internalized
         if (namespaceURI == other.namespaceURI) {
             return localName.compareTo(other.localName);
         } else {
             return namespaceURI.compareTo(other.namespaceURI);
         }
+    }
+
+    //-------------------------------------------------< Serializable support >
+    /**
+     * Creates a new <code>QName</code> instance using the proper constructor
+     * during deserialization in order to make sure that internalized strings
+     * are used where appropriate.
+     */
+    private Object readResolve() {
+        return new QName(namespaceURI, localName);
     }
 }



Mime
View raw message