/*
* eXist Open Source Native XML Database
* Copyright (C) 2001-07 The eXist Project
* http://exist-db.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* $Id$
*/
package org.exist.security;
import java.util.UUID;
import org.apache.log4j.Logger;
/**
* UUID or GUID generator. The random code is generated by java's
* UUID-class.
*
* <UL>
* <LI><a href="http://en.wikipedia.org/wiki/UUID">UUID</a></LI>
* <LI><a href="http://en.wikipedia.org/wiki/GUID">GUID</a></LI>
* <LI><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/UUID.html">java.util.UUID</a></LI>
* </UL>
* @author Dannes Wessels
*/
public class UUIDGenerator {
private final static Logger LOG = Logger.getLogger(UUIDGenerator.class);
/**
* Generate random UUID code.
*
* @return UUID code, formatted as f271ec43-bf1f-4030-a269-b11576538f71
*/
public static String getUUID(){
return getUUIDversion4();
}
/**
* Return version 4 UUID code (random).
* Check <a href="http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Version_4_.28random.29">Wikipedia</a>
*/
public static String getUUIDversion4(){
return UUID.randomUUID().toString();
}
/**
* Return version 3 UUID code (derived from value).
* Check <a href="http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Version_3_.28MD5_hash.29">Wikipedia</a>
* @param value Initialization value.
*/
public static String getUUIDversion3(String value){
return UUID.nameUUIDFromBytes(value.getBytes()).toString();
}
}