Author: veithen
Date: Sun May 23 21:39:26 2010
New Revision: 947499
URL: http://svn.apache.org/viewvc?rev=947499&view=rev
Log:
AXIS2-4527 / WSCOMMONS-541: Replaced usages of UUIDGenerator#getUUID by
invocations of more specialized methods in UIDGenerator. Also optimized the
implementation of UIDGenerator.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleManagerImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/UIDGenerator.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/UIDGeneratorImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/UIDGeneratorTest.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java?rev=947499&r1=947498&r2=947499&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
Sun May 23 21:39:26 2010
@@ -26,7 +26,7 @@ import org.apache.axiom.om.OMAttachmentA
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.impl.MTOMConstants;
import org.apache.axiom.om.util.DetachableInputStream;
-import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axiom.util.UIDGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -633,7 +633,7 @@ public class Attachments implements OMAt
partContentID = nextPart.getContentID();
if (partContentID == null & partIndex == 1) {
- String id = "firstPart_" + UUIDGenerator.getUUID();
+ String id = "firstPart_" +
UIDGenerator.generateContentId();
firstPartId = id;
if (size > 0) {
dataHandler = nextPart.getDataHandler();
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleManagerImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleManagerImpl.java?rev=947499&r1=947498&r2=947499&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleManagerImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleManagerImpl.java
Sun May 23 21:39:26 2010
@@ -27,7 +27,7 @@ import java.security.PrivilegedException
import java.util.Hashtable;
import org.apache.axiom.attachments.lifecycle.LifecycleManager;
-import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.axiom.util.UIDGenerator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -60,12 +60,9 @@ public class LifecycleManagerImpl implem
throw new IllegalArgumentException("Given Axis2 Attachment File
Cache Location "
+ dir + " should be a directory.");
}
- // Generate unique id. The UUID generator is used so that we can limit
+ // Generate unique id. The UID generator is used so that we can limit
// synchronization with the java random number generator.
- String id = UUIDGenerator.getUUID();
-
- //Replace colons with underscores
- id = id.replaceAll(":", "_");
+ String id = UIDGenerator.generateUID();
String fileString = "Axis2" + id + ".att";
file = new File(dir, fileString);
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java?rev=947499&r1=947498&r2=947499&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
Sun May 23 21:39:26 2010
@@ -22,7 +22,6 @@ package org.apache.axiom.om;
import java.util.HashMap;
import org.apache.axiom.om.impl.MTOMConstants;
-import org.apache.axiom.om.util.UUIDGenerator;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.util.UIDGenerator;
@@ -182,10 +181,7 @@ public class OMOutputFormat {
public String getMimeBoundary() {
if (mimeBoundary == null) {
- mimeBoundary =
- "MIMEBoundary"
- + UUIDGenerator.getUUID().replace(':', '_');
-
+ mimeBoundary = UIDGenerator.generateMimeBoundary();
}
return mimeBoundary;
}
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=947499&r1=947498&r2=947499&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 21:39:26 2010
@@ -19,6 +19,9 @@
package org.apache.axiom.util;
+/**
+ * Contains utility methods to generate unique IDs of various kinds.
+ */
public final class UIDGenerator {
private static final ThreadLocal impl = new ThreadLocal() {
protected Object initialValue() {
@@ -57,9 +60,56 @@ public final class UIDGenerator {
* represents the bare content ID.
*/
public static String generateContentId() {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
((UIDGeneratorImpl)impl.get()).generateHex(buffer);
buffer.append("@apache.org");
return buffer.toString();
}
+
+ /**
+ * Generates a MIME boundary.
+ * <p>
+ * Valid MIME boundaries are defined by the following production in
RFC2046:
+ * <pre>
+ * boundary := 0*69<bchars> bcharsnospace
+ * bchars := bcharsnospace / " "
+ * bcharsnospace := DIGIT / ALPHA / "'" / "(" / ")" /
+ * "+" / "_" / "," / "-" / "." /
+ * "/" / ":" / "=" / "?"</pre>
+ * <p>
+ * It should be noted that the boundary in general will also appear as a
parameter in the
+ * content type of the MIME package. According to RFC2045 (which defines
the
+ * <tt>Content-Type</tt> header), it will require quoting if it contains
characters from
+ * the following production:
+ * <pre>
+ * tspecials := "(" / ")" / "<" / ">" / "@" /
+ * "," / ";" / ":" / "\" / <"> /
+ * "/" / "[" / "]" / "?" / "="</pre>
+ * <p>
+ * This method produces a boundary that doesn't contain any of these
characters and
+ * therefore doesn't need to be quoted. To avoid accidental collisions,
the returned value
+ * is unique and doesn't overlap with any other type of unique ID returned
by methods in
+ * this class. The implementation is thread safe, but doesn't use
synchronization.
+ *
+ * @return the generated MIME boundary
+ */
+ public static String generateMimeBoundary() {
+ StringBuilder buffer = new StringBuilder("MIMEBoundary_");
+ ((UIDGeneratorImpl)impl.get()).generateHex(buffer);
+ return buffer.toString();
+ }
+
+ /**
+ * Generate a general purpose unique ID. The returned value is the
hexadecimal representation of
+ * a 192 bit value, i.e. it is 48 characters long. The implementation
guarantees a high level of
+ * uniqueness, but makes no provisions to guarantee randomness. It is
thread safe, but doesn't
+ * use synchronization.
+ *
+ * @return the generated unique ID
+ */
+ public static String generateUID() {
+ StringBuilder buffer = new StringBuilder(48);
+ ((UIDGeneratorImpl)impl.get()).generateHex(buffer);
+ return buffer.toString();
+ }
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/UIDGeneratorImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/UIDGeneratorImpl.java?rev=947499&r1=947498&r2=947499&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/UIDGeneratorImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/UIDGeneratorImpl.java
Sun May 23 21:39:26 2010
@@ -67,16 +67,19 @@ class UIDGeneratorImpl {
seqXorOperand = rand.nextLong();
}
- private final long xoredThreadId;
- private final long xoredStartTime;
+ private final String suffix;
private long seq;
UIDGeneratorImpl() {
- xoredThreadId = Thread.currentThread().getId() ^ threadIdXorOperand;
- xoredStartTime = System.currentTimeMillis() ^ startTimeXorOperand;
+ long xoredThreadId = Thread.currentThread().getId() ^
threadIdXorOperand;
+ long xoredStartTime = System.currentTimeMillis() ^ startTimeXorOperand;
+ StringBuilder buffer = new StringBuilder();
+ writeReverseLongHex(xoredStartTime, buffer);
+ writeReverseLongHex(xoredThreadId, buffer);
+ suffix = buffer.toString();
}
- private void writeReverseLongHex(long value, StringBuffer buffer) {
+ private void writeReverseLongHex(long value, StringBuilder buffer) {
for (int i=0; i<16; i++) {
int n = (int)(value >> (4*i)) & 0xF;
buffer.append((char)(n < 10 ? '0' + n : 'a' + n - 10));
@@ -91,9 +94,8 @@ class UIDGeneratorImpl {
*
* @param buffer
*/
- void generateHex(StringBuffer buffer) {
+ void generateHex(StringBuilder buffer) {
writeReverseLongHex(seq++ ^ seqXorOperand, buffer);
- writeReverseLongHex(xoredStartTime, buffer);
- writeReverseLongHex(xoredThreadId, buffer);
+ buffer.append(suffix);
}
}
\ No newline at end of file
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/UIDGeneratorTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/UIDGeneratorTest.java?rev=947499&r1=947498&r2=947499&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/UIDGeneratorTest.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/UIDGeneratorTest.java
Sun May 23 21:39:26 2010
@@ -38,4 +38,8 @@ public class UIDGeneratorTest extends Te
assertTrue(values.add(UIDGenerator.generateContentId()));
}
}
+
+ public void testGenerateMimeBoundaryLength() {
+ assertTrue(UIDGenerator.generateMimeBoundary().length() <= 70);
+ }
}