KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > didl > UUIDFactory


1 /*
2  * Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
3  * Institute of Technology. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * - Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * - Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * - Neither the name of the Hewlett-Packard Company nor the name of the
17  * Massachusetts Institute of Technology nor the names of their
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
32  * DAMAGE.
33  */

34 package org.dspace.app.didl;
35
36 import java.security.SecureRandom JavaDoc;
37 import java.util.Random JavaDoc;
38 /**
39  * Factory class for generating UUID version 4. All what this class does is
40  * creating UUID version 4 objects using crypto-quality random numbers.
41  *
42  * Development of this code was part of the aDORe repository project by the
43  * Research Library of the Los Alamos National Laboratory.
44  *
45  * This code is based on the implementation of UUID version 4 (the one that
46  * uses random/pseudo-random numbers by Ashraf Amrou of the Old Dominion University
47  * (Aug 14, 2003)
48  *
49  **/

50 public final class UUIDFactory
51 {
52     /** Random number generator */
53     private Random JavaDoc rand = null;
54     
55     /** an instance */
56     private static UUIDFactory generator = new UUIDFactory();
57         
58     /** private constructor (Singleton class) */
59     private UUIDFactory()
60     {
61         // crypto-quality random number generator
62
rand = new SecureRandom JavaDoc();
63     }
64     
65     /**
66      *
67      * Customers of this class call this method to generete new UUID objects
68      *
69      * @return a new UUID object
70      *
71      **/

72     public synchronized static UUID generateUUID()
73     {
74         return new UUID(generator.rand.nextLong(),generator.rand.nextLong());
75     }
76 }
Popular Tags