/* URN5Namespace.java * * Copyright (c) 2002, Tuomas Lukka * * You may use and distribute under the terms of either the GNU Lesser * General Public License, either version 2 of the license or, * at your choice, any later version. Alternatively, you may use and * distribute under the terms of the XPL. * * See the LICENSE.lgpl and LICENSE.xpl files for the specific terms of * the licenses. * * This software 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 README * file for more details. * */ /* * Written by Tuomas Lukka */ package gzz.util; import java.util.*; import java.security.SecureRandom; import java.io.*; import java.lang.String; /** A class which is able to generate globally unique URN-5 * identifiers. * URN-5 identifiers are globally unique, nonhierarchical identifiers. *
* The names generated by the same instance share the same "random number" * part and differ only by the "local part". * See http://www.iana.org/assignments/urn-informal/urn-5 *
* The java.security.SecureRandom class is used as a source of random numbers.
*/
public class URN5Namespace {
/** 21 bytes ^= 28 base64 namespace chars */
public static final int NAMESPACECHARS = 28;
/** 64 characters for encoding.
*/
private static String base64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
/** The random number generator to use for generating the initial string.
*/
private static SecureRandom sr;
private String namespace;
private long nextNumber = 1;
public URN5Namespace() {
if(sr == null)
sr = new SecureRandom();
namespace = "";
for(int i=0; i