1 5 package xdoclet.modules.sun.sunone.ejb; 6 7 import java.net.InetAddress ; 8 import java.security.SecureRandom ; 9 import java.util.*; 10 11 import xjavadoc.*; 12 13 import xdoclet.XDocletException; 14 import xdoclet.XDocletMessages; 15 import xdoclet.tagshandler.AbstractProgramElementTagsHandler; 16 import xdoclet.tagshandler.MethodTagsHandler; 17 import xdoclet.util.Translator; 18 19 25 public class SunONETagsHandler extends AbstractProgramElementTagsHandler 26 { 27 28 private final static SecureRandom seeder = new SecureRandom (); 30 31 34 private static String hexServerIP = null; 35 38 protected MethodTagsHandler handler = new MethodTagsHandler(); 39 40 43 protected Map attributes = Collections.synchronizedMap(new HashMap()); 44 45 48 protected int index = 0; 49 50 58 public static String generateGUID() throws XDocletException 59 { 60 return generateGUID(getCurrentClass()); 61 } 62 63 71 public static String generateGUID(Object o) throws XDocletException 72 { 73 StringBuffer tmpBuffer = new StringBuffer (16); 74 75 if (hexServerIP == null) { 76 InetAddress localInetAddress = null; 77 78 try { 79 localInetAddress = InetAddress.getLocalHost(); 81 } 82 catch (java.net.UnknownHostException uhe) { 83 System.err.println("Could not get the local IP address using InetAddress.getLocalHost()!"); 84 uhe.printStackTrace(); 86 return null; 87 } 88 89 byte serverIP[] = localInetAddress.getAddress(); 90 91 hexServerIP = hexFormat(getInt(serverIP), 8); 92 } 93 94 String hashcode = hexFormat(System.identityHashCode(o), 8); 95 96 tmpBuffer.append(hexServerIP); 97 tmpBuffer.append(hashcode); 98 99 long timeNow = System.currentTimeMillis(); 100 int timeLow = (int) timeNow & 0xFFFFFFFF; 101 int node = seeder.nextInt(); 102 103 StringBuffer guid = new StringBuffer (32); 104 105 guid.append(hexFormat(timeLow, 8)); 106 guid.append(tmpBuffer.toString()); 107 guid.append(hexFormat(node, 8)); 108 return "{" + guid.substring(0, 8) + "-" + guid.substring(8, 12) + "-" 109 + guid.substring(12, 16) + "-" + guid.substring(16, 20) + "-" 110 + guid.substring(20, 32) + "}"; 111 } 112 113 private static int getInt(byte bytes[]) 114 { 115 int i = 0; 116 int j = 24; 117 118 for (int k = 0; j >= 0; k++) { 119 int l = bytes[k] & 0xff; 120 121 i += l << j; 122 j -= 8; 123 } 124 return i; 125 } 126 127 private static String hexFormat(int i, int j) 128 { 129 String s = Integer.toHexString(i); 130 131 return padHex(s, j) + s; 132 } 133 134 private static String padHex(String s, int i) 135 { 136 StringBuffer tmpBuffer = new StringBuffer (); 137 138 if (s.length() < i) { 139 for (int j = 0; j < i - s.length(); j++) { 140 tmpBuffer.append('0'); 141 } 142 } 143 return tmpBuffer.toString(); 144 } 145 146 } 147 | Popular Tags |