public ID createInstance(Object[] args) throws IDCreateException { try { String init = getInitStringFromExternalForm(args); if (init != null) return new GUID(this, init); if (args == null || args.length <= 0) return new GUID(this); else if (args.length == 1 && args[0] instanceof Integer) return new GUID(this, ((Integer) args[0]).intValue()); else if (args.length == 1 && args[0] instanceof String) return new GUID(this, ((String) args[0])); else return new GUID(this); } catch (Exception e) { throw new IDCreateException(getName() + " createInstance()", e); //$NON-NLS-1$ } }
/** * Get SecureRandom instance for creation of random number. * * @param algo * the String algorithm specification (e.g. "SHA1PRNG") for * creation of the SecureRandom instance * @param provider * the provider of the implementation of the given algorighm * (e.g. "SUN") * @return SecureRandom * @exception Exception * thrown if SecureRandom instance cannot be created/accessed */ protected static synchronized SecureRandom getRandom(String algo, String provider) throws Exception { // Given algo and provider, get SecureRandom instance if (random == null) { initializeRandom(algo, provider); } return random; }
/** * Protected constructor for factory-based construction * * @param n * the Namespace this identity will belong to * @param provider * the name of the algorithm to use. See {@link SecureRandom} * @param byteLength * the length of the target number (in bytes) */ protected GUID(Namespace n, String algo, String provider, int byteLength) throws IDCreateException { super(n, ""); //$NON-NLS-1$ // Get SecureRandom instance for class try { getRandom(algo, provider); } catch (Exception e) { throw new IDCreateException( "GUID creation failure: " + e.getMessage()); //$NON-NLS-1$ } // make sure we have reasonable byteLength if (byteLength <= 0) byteLength = 1; byte[] newBytes = new byte[byteLength]; // Fill up random bytes random.nextBytes(newBytes); // Set value value = Base64.encode(newBytes); }
/** * Protected constructor for factory-based construction * * @param n * the Namespace this identity will belong to * @param provider * the name of the algorithm to use. See {@link SecureRandom} * @param byteLength * the length of the target number (in bytes) */ protected GUID(Namespace n, String algo, String provider, int byteLength) throws IDCreateException { super(n, ""); //$NON-NLS-1$ // Get SecureRandom instance for class try { getRandom(algo, provider); } catch (Exception e) { throw new IDCreateException( "GUID creation failure: " + e.getMessage()); //$NON-NLS-1$ } // make sure we have reasonable byteLength if (byteLength <= 0) byteLength = 1; byte[] newBytes = new byte[byteLength]; // Fill up random bytes random.nextBytes(newBytes); // Set value value = Base64.encode(newBytes); }
public ID createInstance(Object[] args) throws IDCreateException { try { String init = getInitStringFromExternalForm(args); if (init != null) return new GUID(this, init); if (args == null || args.length <= 0) return new GUID(this); else if (args.length == 1 && args[0] instanceof Integer) return new GUID(this, ((Integer) args[0]).intValue()); else if (args.length == 1 && args[0] instanceof String) return new GUID(this, ((String) args[0])); else return new GUID(this); } catch (Exception e) { throw new IDCreateException(getName() + " createInstance()", e); //$NON-NLS-1$ } }
/** * Get SecureRandom instance for creation of random number. * * @param algo * the String algorithm specification (e.g. "SHA1PRNG") for * creation of the SecureRandom instance * @param provider * the provider of the implementation of the given algorighm * (e.g. "SUN") * @return SecureRandom * @exception Exception * thrown if SecureRandom instance cannot be created/accessed */ protected static synchronized SecureRandom getRandom(String algo, String provider) throws Exception { // Given algo and provider, get SecureRandom instance if (random == null) { initializeRandom(algo, provider); } return random; }