Skip to content

Commit

Permalink
Update DIDL license and change coding style to DSpace standard
Browse files Browse the repository at this point in the history
git-svn-id: http://scm.dspace.org/svn/repo/trunk@1676 9c30dcfa-912a-0410-8fc2-9e0234be79fd
  • Loading branch information
ScottYeadon committed Nov 19, 2006
1 parent e79235b commit 983b9f9
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 230 deletions.
1 change: 1 addition & 0 deletions dspace/CHANGES
@@ -1,5 +1,6 @@
(Scott Yeadon)
- Fix bug in TableRow toString() method where NPE is thrown if tablename not set
- Update DIDL license and change coding style to DSpace standard

(Stuart Lewis)
- SF Patch #1596113 [dspace]/bin/update-handle-prefix needs to index-all
Expand Down
163 changes: 113 additions & 50 deletions dspace/src/org/dspace/app/didl/UUID.java
@@ -1,87 +1,142 @@
/******************************************************************************
* DSPACE DIDL MODULE UUID GENERATOR
* AUTHOR
* Los Alamos National Laboratory
* Research Library
* Digital Library Research & Prototyping Team
* Henry Jerez
* 2004, 2005
*CONTACT
* proto@gws.lanl.gov
*VERSION
* Beta 1
* date 07/26/2005
* ACKNOWLEDGMENT
* Development of this code is part of the aDORe repository project by the Research Library of the Los Alamos National Laboratory.
* BASED ON:
* Implementation of UUID version 4 (the one that uses random/pseudo-random
* numbers)
* By: Ashraf Amrou
* Old Dominion University
* Aug 14, 2003
*****************************************************************************/
/*
* Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
package org.dspace.app.didl;

import java.io.*;
import java.io.Serializable;
/**
* This class implements UUID version 4
* The values for the various fields are crypto random values set by
* the factory class UUIDFactory
* This class implements UUID version 4. The values for the various fields are
* crypto random values set by the factory class UUIDFactory
*
* Development of this code was part of the aDORe repository project by the
* Research Library of the Los Alamos National Laboratory.
*
* This code is based on the implementation of UUID version 4 (the one that
* uses random/pseudo-random numbers by Ashraf Amrou of the Old Dominion University
* (Aug 14, 2003)
**/
public final class UUID implements java.io.Serializable {
public final class UUID implements Serializable
{
private long hi;
private long lo;
///////////////////////////////////////////////////

/**
* Construct a Version 4 UUID object form another UUID object
* Construct a Version 4 UUID object from another UUID object
*
* @param uuid
* the UUID to use as a base for the new UUID
**/
public UUID(UUID uuid) {
public UUID(UUID uuid)
{
this.hi = uuid.hi;
this.lo = uuid.lo;
}
///////////////////////////////////////////////////

/**
* Construct a Version 4 UUID object form the two given long values.
* These values are (pseudo)random numbers (best if crypto quality)
*
* @param _hi
* first long value
*
* @param _lo
* second long value
*
**/
public UUID(long _hi, long _lo) {
public UUID(long _hi, long _lo)
{
this.hi = _hi;
this.lo = _lo;
// IETF variant (10)b
lo &= 0x3FFFFFFFFFFFFFFFL; lo |= 0x8000000000000000L;
// set multicast bit (so that it there is no chance it will clash with other UUIDs generated based on real IEEE 802 addresses)
// set multicast bit (so that it there is no chance it will clash
// with other UUIDs generated based on real IEEE 802 addresses)
lo |= 0x0000800000000000L;
// version 4 (100)b: the one based on random/pseudo-random numbers
hi &= 0xFFFFFFFFFFFF0FFFL; hi |= 0x0000000000004000L;
}
///////////////////////////////////////////////////

/**
* Returns true if equal
* Compare UUID objects
*
* @param obj
* the object to compare this UUID against
*
* @return true or false
**/
public boolean equals( Object obj ) {
public boolean equals(Object obj)
{
if(this == obj) // comparing to myself
return true;
if(obj instanceof UUID)
return equals((UUID)obj);
return false;
}
///////////////////////////////////////////////////

/**
* Returns true if equal
* Compare UUIDs
*
* @param uuid
* the UUID to compare this UUID against
*
* @return true or false
**/
public boolean equals(UUID uuid) {
public boolean equals(UUID uuid)
{
return (hi == uuid.hi && lo == uuid.lo);
}
///////////////////////////////////////////////////
public int hashCode(){


/**
* Generate a hash for the UUID
*
* @return hash code for the UUID
*
**/
public int hashCode()
{
return new Long(hi ^ lo).hashCode();
//return new Long(((((long)(new Long(hi).hashCode())) << 32) + ((long)(new Long(lo).hashCode())))).hashCode();
}
///////////////////////////////////////////////////


/**
* Returns the string representation of this UUID
* Obtain a string representation of the UUID object
*
* @return the string representation of this UUID
*
**/
public String toString() {
public String toString()
{
return (/**"urn:uuid:" + **/
hexDigits(hi >> 32, 4) // time_low: 4 hexOctet (8 hex digits)
+ "-" +
Expand All @@ -93,16 +148,24 @@ public String toString() {
+ "-" +
hexDigits(lo, 6)); // node: 6 hexOctet (12 hex digits)
}
///////////////////////////////////////////////////

/**
* Returns the Hex value of the nHexOctets lest significant octets from the long value lVal as a String
* Obtain the Hex value of a given number of least significant octets
* from a long value as a String
*
* @param lVal
* the long value to retrieve octets from
*
* @param nHexOctets
* number of hex octets to return
*
* @return hex value of least significant octets as a string
*
**/
private static String hexDigits(long lVal, int nHexOctets) {
long tmp = 1L << (nHexOctets * 2 * 4); // e.g., if nHexOctets is 2, tmp = (1 0000 0000 0000 0000)b & tmp - 1 = (1111 1111 1111 1111)b
long result = lVal & (tmp - 1); // get ride of the uneeded most significant bits
result = tmp | result; // make sure the digit at position (nDigits + 1) equals 1 (to preserve leading zeroes)
return Long.toHexString(result).substring(1); // getride ot the digit at position nDigits + 1
}
///////////////////////////////////////////////////
}

}
96 changes: 57 additions & 39 deletions dspace/src/org/dspace/app/didl/UUIDFactory.java
@@ -1,58 +1,76 @@
/******************************************************************************
* DSPACE DIDL MODULE UUID GENERATOR
* AUTHOR
* Los Alamos National Laboratory
* Research Library
* Digital Library Research & Prototyping Team
* Henry Jerez
* 2004, 2005
*CONTACT
* proto@gws.lanl.gov
*VERSION
* Beta 1
* date 07/26/2005
* ACKNOWLEDGMENT
* Development of this code is part of the aDORe repository project by the Research Library of the Los Alamos National Laboratory.
* BASED ON:
*Implementation of UUID version 4 (the one that uses random/pseudo-random
* numbers)
* By: Ashraf Amrou
* Old Dominion University
* Aug 14, 2003
*****************************************************************************/
/*
* Copyright (c) 2004-2005, Hewlett-Packard Company and Massachusetts
* Institute of Technology. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Hewlett-Packard Company nor the name of the
* Massachusetts Institute of Technology nor the names of their
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
package org.dspace.app.didl;

import java.security.SecureRandom;
import java.util.Random;
/**
* Factory class for generating UUID version 4. All what this class does is
* creating UUID version 4 objects using crypto-quality random numbers.
*
* Development of this code was part of the aDORe repository project by the
* Research Library of the Los Alamos National Laboratory.
*
* This code is based on the implementation of UUID version 4 (the one that
* uses random/pseudo-random numbers by Ashraf Amrou of the Old Dominion University
* (Aug 14, 2003)
*
**/
public final class UUIDFactory{
public final class UUIDFactory
{
/** Random number generator */
private Random rand = null;

/**
* Random number generator
**/
private java.util.Random rand = null;
/**
* an instance
**/
/** an instance */
private static UUIDFactory generator = new UUIDFactory();
///////////////////////////////////////////////////
/**
* private constructor (Singleton class)
**/
private UUIDFactory() {

/** private constructor (Singleton class) */
private UUIDFactory()
{
// crypto-quality random number generator
rand = new SecureRandom();
}
///////////////////////////////////////////////////

/**
*
* Customers of this class call this method to generete new UUID objects
*
* @return a new UUID object
*
**/
public synchronized static UUID generateUUID(){
public synchronized static UUID generateUUID()
{
return new UUID(generator.rand.nextLong(),generator.rand.nextLong());
}
///////////////////////////////////////////////////
}
}

0 comments on commit 983b9f9

Please sign in to comment.