[jboss-remoting-commits] JBoss Remoting SVN: r4843 - remoting3/trunk/api/src/main/java/org/jboss/remoting.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Thu Jan 29 14:19:16 EST 2009


Author: david.lloyd at jboss.com
Date: 2009-01-29 14:19:16 -0500 (Thu, 29 Jan 2009)
New Revision: 4843

Modified:
   remoting3/trunk/api/src/main/java/org/jboss/remoting/QualifiedName.java
Log:
QualifiedName API enhancements

Modified: remoting3/trunk/api/src/main/java/org/jboss/remoting/QualifiedName.java
===================================================================
--- remoting3/trunk/api/src/main/java/org/jboss/remoting/QualifiedName.java	2009-01-20 06:59:56 UTC (rev 4842)
+++ remoting3/trunk/api/src/main/java/org/jboss/remoting/QualifiedName.java	2009-01-29 19:19:16 UTC (rev 4843)
@@ -146,15 +146,14 @@
     }
 
     /**
-     * Parse a qualified name.  A qualified name must consist of either a single forward slash ("{@code /}") or else
+     * Parse an absolute qualified name.  An absolute qualified name must consist of either a single forward slash ("{@code /}") or else
      * a series of path components, each comprised of a single forward slash followed by a URL-encoded series of non-forward-slash
      * characters.
      *
-     * @param path the path
+     * @param path the encoded absolute path
      * @return the qualified name
      */
     public static QualifiedName parse(String path) {
-        List<String> decoded = new ArrayList<String>();
         final int len = path.length();
         if (len < 1) {
             throw new IllegalArgumentException("Empty path");
@@ -165,23 +164,7 @@
         if (len == 1) {
             return ROOT_NAME;
         }
-        int segStart = 0;
-        int segEnd;
-        do {
-            segEnd = path.indexOf('/', segStart + 1);
-            String segment = segEnd == -1 ? path.substring(segStart + 1) : path.substring(segStart + 1, segEnd);
-            if (segment.length() == 0) {
-                throw new IllegalArgumentException(segEnd == -1 ? "Invalid trailing slash" : "Empty segment in path");
-            }
-            try {
-                decoded.add(URLDecoder.decode(segment, "utf-8"));
-            } catch (UnsupportedEncodingException e) {
-                // cannot happen
-                throw new IllegalStateException(e);
-            }
-            segStart = segEnd;
-        } while (segEnd != -1);
-        return new QualifiedName(decoded.toArray(new String[decoded.size()]));
+        return ROOT_NAME.parseRelative(path.substring(1));
     }
 
     /**
@@ -212,6 +195,59 @@
     }
 
     /**
+     * Parse a qualified name relative to this one.  A relative qualified name must consist of
+     * a series of segments comprised of one or more URL-encoded characters separated by forward slashes ("{@code /}").
+     *
+     * @param path the encoded relative path
+     * @return the qualified name
+     */
+    public QualifiedName parseRelative(String path) {
+        if (path == null) {
+            throw new NullPointerException("path is null");
+        }
+        List<String> decoded = new ArrayList<String>();
+        int segStart = 0;
+        int segEnd;
+        do {
+            segEnd = path.indexOf('/', segStart);
+            String segment = segEnd == -1 ? path.substring(segStart) : path.substring(segStart, segEnd);
+            if (segment.length() == 0) {
+                throw new IllegalArgumentException(segEnd == -1 ? "Invalid trailing slash" : "Empty segment in path");
+            }
+            try {
+                decoded.add(URLDecoder.decode(segment, "utf-8"));
+            } catch (UnsupportedEncodingException e) {
+                // cannot happen
+                throw new IllegalStateException(e);
+            }
+            segStart = segEnd + 1;
+        } while (segEnd != -1);
+        final String[] segments = this.segments;
+        final int length = segments.length;
+        final String[] newSegments = new String[length + decoded.size()];
+        System.arraycopy(segments, 0, newSegments, 0, length);
+        for (int i = 0; i < decoded.size(); i ++) {
+            newSegments[i + length] = decoded.get(i);
+        }
+        return new QualifiedName(newSegments);
+    }
+
+    /**
+     * Get a new {@code org.jboss.remoting.QualifiedName} relative to this one.
+     *
+     * @param relativePath the segment to append
+     * @return the new {@code org.jboss.remoting.QualifiedName} instance
+     */
+    public QualifiedName appendRelative(String relativePath) {
+        final String[] segments = this.segments;
+        final int length = segments.length;
+        final String[] newSegments = new String[length + 1];
+        System.arraycopy(segments, 0, newSegments, 0, length);
+        newSegments[length] = relativePath;
+        return new QualifiedName(newSegments);
+    }
+
+    /**
      * Get the number of segments in this name.
      *
      * @return the number of segments




More information about the jboss-remoting-commits mailing list