You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2010/05/24 00:51:33 UTC

svn commit: r947514 - in /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom: om/util/UUIDGenerator.java util/UIDGenerator.java

Author: veithen
Date: Sun May 23 22:51:32 2010
New Revision: 947514

URL: http://svn.apache.org/viewvc?rev=947514&view=rev
Log:
AXIS2-4527 / WSCOMMONS-541:
* Restored UUIDGenerator in its 1.2.8 state and deprecated it.
* Added replacement methods to UIDGenerator.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/UUIDGenerator.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/UIDGenerator.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/UUIDGenerator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/UUIDGenerator.java?rev=947514&r1=947513&r2=947514&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/UUIDGenerator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/util/UUIDGenerator.java Sun May 23 22:51:32 2010
@@ -25,21 +25,39 @@ import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Date;
 import java.util.Random;
-import java.util.UUID;
 
 import org.apache.axiom.om.OMException;
 
+/**
+ * @deprecated Please use one of the specialized methods in the
+ *             {@link org.apache.axiom.util.UIDGenerator} class. In contrast to what its name
+ *             suggests, the {@link #getUUID()} method doesn't return a UUID. It also doesn't return
+ *             a valid URN with uuid NID. See AXIS2-4527 for more information.
+ */
 public class UUIDGenerator {
     /** This class will give UUIDs for axis2. */
 
+    private static String baseUUID = null;
+    private static long incrementingValue = 0;
+
+
     private static Random myRand = null;
 
     /**
-     * uses the java UUID which provides the standard uuids.
-     * @return
+     * MD5 a random string with localhost/date etc will return 128 bits construct a string of 18
+     * characters from those bits.
+     *
+     * @return string
      */
-    public static String getUUID() {
-        return "urn:uuid:" + UUID.randomUUID();
+    public static synchronized String getUUID() {
+        if (baseUUID == null) {
+            baseUUID = getInitialUUID();
+            baseUUID = "urn:uuid:" + baseUUID;
+        }
+        if (++incrementingValue >= Long.MAX_VALUE) {
+            incrementingValue = 0;
+        }
+        return baseUUID + (System.currentTimeMillis() + incrementingValue);
     }
 
     protected static String getInitialUUID() {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/UIDGenerator.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/UIDGenerator.java?rev=947514&r1=947513&r2=947514&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/UIDGenerator.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/UIDGenerator.java Sun May 23 22:51:32 2010
@@ -19,6 +19,10 @@
 
 package org.apache.axiom.util;
 
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.UUID;
+
 /**
  * Contains utility methods to generate unique IDs of various kinds.
  */
@@ -112,4 +116,30 @@ public final class UIDGenerator {
         ((UIDGeneratorImpl)impl.get()).generateHex(buffer);
         return buffer.toString();
     }
+    
+    /**
+     * Generate a URN with <tt>uuid</tt> NID (namespace identifier). These URNs have the following
+     * form: <tt>urn:uuid:dae6fae1-93df-4824-bc70-884c9edb5973</tt>. The UUID is generated using
+     * a cryptographically strong pseudo random number generator.
+     * 
+     * @return the generated URN
+     */
+    public static String generateURNString() {
+        return "urn:uuid:" + UUID.randomUUID();
+    }
+    
+    /**
+     * Generate a URN with <tt>uuid</tt> NID (namespace identifier). This method does the
+     * same as {@link #generateURNString()}, but returns a {@link URI} object.
+     * 
+     * @return the generated URN
+     */
+    public static URI generateURN() {
+        try {
+            return new URI(generateURNString());
+        } catch (URISyntaxException ex) {
+            // If we ever get here, then if would mean that there is something badly broken...
+            throw new Error(ex);
+        }
+    }
 }