org.apache.commons.id.uuid
Class VersionFourGenerator

java.lang.Object
  extended by org.apache.commons.id.uuid.VersionFourGenerator
All Implemented Interfaces:
IdentifierGenerator, Constants

public final class VersionFourGenerator
extends java.lang.Object
implements IdentifierGenerator, Constants

Class is responsible for generating version 4 UUID's per RFC 4122. This class attempts to use a java.security.SecureRandom with the following instantiation SecureRandom.getInstance("SHA1PRNG", "SUN"). If neither secure random implementation is avialable or an Exception is raised a java.util.Random is used.

Note: Instantiation of SecureRandom is an expensive operation. The constructor therefore creates a static member to hold the SecureRandom. The first call to getInstance may take time; subsequent calls should return quickly.

Version:
$Revision: 480488 $ $Date: 2006-11-29 08:57:26 +0000 (Wed, 29 Nov 2006) $
Author:
Commons-Id team

Field Summary
 
Fields inherited from interface org.apache.commons.id.uuid.Constants
CLOCK_SEQ_HI_AND_RESERVED_BYTE_8, FORMAT_POSITION1, FORMAT_POSITION2, FORMAT_POSITION3, FORMAT_POSITION4, MD5_ENCODING, SHA1_ENCODING, TIME_HI_AND_VERSION_BYTE_6, TIME_HI_BYTE_LEN, TIME_HI_START_POS, TIME_HI_TS_POS, TIME_LOW_BYTE_LEN, TIME_LOW_START_POS, TIME_LOW_TS_POS, TIME_MID_BYTE_LEN, TIME_MID_START_POS, TIME_MID_TS_POS, TOKEN_LENGTHS, TOKENS_IN_UUID, URN_PREFIX, UUID_BIT_LENGTH, UUID_BYTE_LENGTH, UUID_FORMATTED_LENGTH, UUID_UNFORMATTED_LENGTH, VARIANT_FUTURE, VARIANT_IETF_DRAFT, VARIANT_MS, VARIANT_NCS_COMPAT, VERSION_FIVE, VERSION_FOUR, VERSION_ONE, VERSION_THREE, VERSION_TWO, WRONG_VAR_VER_MSG
 
Constructor Summary
VersionFourGenerator()
          Constructs a new VersionFourGenerator.
 
Method Summary
static VersionFourGenerator getInstance()
          Returns a singleton instance of the version four UUID generator.
 java.lang.Object nextIdentifier()
          Returns a new version four UUID.
 java.lang.Object nextIdentifier(boolean secure)
          Returns a new version four UUID.
 UUID nextUUID()
          Returns a new version four UUID.
static void setPRNGProvider(java.lang.String prngName, java.lang.String packageName)
          Allows clients to set the pseudo-random number generator implementation used when generating a version four uuid with the secure option.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VersionFourGenerator

public VersionFourGenerator()

Constructs a new VersionFourGenerator.

Method Detail

getInstance

public static VersionFourGenerator getInstance()

Returns a singleton instance of the version four UUID generator.

Returns:
the singleton instance of the version four UUID generator.

nextIdentifier

public java.lang.Object nextIdentifier()

Returns a new version four UUID.

Specified by:
nextIdentifier in interface IdentifierGenerator
Returns:
Object a new version 4 UUID.

nextIdentifier

public java.lang.Object nextIdentifier(boolean secure)

Returns a new version four UUID.

This overloaded method may produce both UUID's using a SecureRandom as well as using normal Random

Parameters:
secure - indicates whether or not to use SecureRandom in generating the random bits.
Returns:
a new version four UUID that was generated by either a Random or SecureRandom.

nextUUID

public UUID nextUUID()

Returns a new version four UUID.

Returns:
Object a new version 4 UUID.

setPRNGProvider

public static void setPRNGProvider(java.lang.String prngName,
                                   java.lang.String packageName)

Allows clients to set the pseudo-random number generator implementation used when generating a version four uuid with the secure option. The secure option uses a SecureRandom. The packageName string may be null to specify no preferred package.

Parameters:
prngName - the pseudo-random number generator implementation name. For example "SHA1PRNG".
packageName - the package name for the PRNG provider. For example "SUN".


Copyright © 2003-2008 The Apache Software Foundation. All Rights Reserved.