1 17 18 package org.pentaho.util; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 import org.safehaus.uuid.UUID; 23 import org.safehaus.uuid.UUIDGenerator; 24 import org.pentaho.messages.Messages; 25 26 public class UUIDUtil { 27 private static Log log = LogFactory.getLog(UUIDUtil.class); 28 29 static boolean nativeInitialized = false; 30 31 static UUIDGenerator ug; 32 33 static org.safehaus.uuid.EthernetAddress eAddr; 34 35 static { 36 46 ug = UUIDGenerator.getInstance(); 47 if (nativeInitialized) { 48 try { 49 com.ccg.net.ethernet.EthernetAddress ea = com.ccg.net.ethernet.EthernetAddress.getPrimaryAdapter(); 50 eAddr = new org.safehaus.uuid.EthernetAddress(ea.getBytes()); 51 } catch (Exception ex) { 52 log.error(Messages.getErrorString("UUIDUtil.ERROR_0002_GET_MAC_ADDR"), ex); } catch (UnsatisfiedLinkError ule) { 54 log.error(Messages.getErrorString("UUIDUtil.ERROR_0002_GET_MAC_ADDR"), ule); nativeInitialized = false; 56 } 57 } 58 59 63 if (eAddr == null) { 64 String macAddr = System.getProperty("MAC_ADDRESS"); if (macAddr != null) { 66 macAddr = macAddr.replace('-', ':'); 72 eAddr = new org.safehaus.uuid.EthernetAddress(macAddr); 73 } 74 } 75 76 if (eAddr == null) { 77 eAddr = ug.getDummyAddress(); 79 } 80 81 UUID olduuId = ug.generateTimeBasedUUID(eAddr); 83 if (olduuId == null) { 84 log.error(Messages.getErrorString("UUIDUtil.ERROR_0003_GENERATEFAILED")); } 86 87 } 88 89 public static String getUUIDAsString() { 90 return getUUID().toString(); 91 } 92 93 public static UUID getUUID() { 94 UUID uuId = ug.generateTimeBasedUUID(eAddr); 95 return uuId; 100 } 101 102 } 103 | Popular Tags |