1 11 package org.eclipse.jdi.internal.jdwp; 12 13 14 import java.io.DataInputStream ; 15 import java.io.DataOutputStream ; 16 import java.io.IOException ; 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 import org.eclipse.jdi.internal.VirtualMachineImpl; 21 22 23 28 public abstract class JdwpID { 29 30 public static final byte NULL_TAG = 91; public static final byte ARRAY_TAG = 91; public static final byte BYTE_TAG = 66; public static final byte CHAR_TAG = 67; public static final byte OBJECT_TAG = 76; public static final byte FLOAT_TAG = 70; public static final byte DOUBLE_TAG = 68; public static final byte INT_TAG = 73; public static final byte LONG_TAG = 74; public static final byte SHORT_TAG = 83; public static final byte VOID_TAG = 86; public static final byte BOOLEAN_TAG = 90; public static final byte STRING_TAG = 115; public static final byte THREAD_TAG = 116; public static final byte THREAD_GROUP_TAG = 103; public static final byte CLASS_LOADER_TAG = 108; public static final byte CLASS_OBJECT_TAG = 99; 48 49 public static final byte TYPE_TAG_CLASS = 1; public static final byte TYPE_TAG_INTERFACE = 2; public static final byte TYPE_TAG_ARRAY = 3; 53 54 private static HashMap fTagMap = null; 55 private static HashMap fTypeTagMap = null; 56 57 58 protected static final int VALUE_NULL = 0; 59 60 61 protected long fValue = VALUE_NULL; 62 63 protected VirtualMachineImpl fVirtualMachine; 64 65 68 public JdwpID(VirtualMachineImpl vmImpl) { 69 fVirtualMachine = vmImpl; 70 } 71 72 76 public boolean equals(Object object) { 77 return object instanceof JdwpID && fValue == ((JdwpID)object).fValue; 78 } 79 80 84 public int hashCode() { 85 return (int)fValue; 86 } 87 88 91 public final long value() { 92 return fValue; 93 } 94 95 98 public String toString() { 99 return new Long (fValue).toString(); 100 } 101 102 105 protected abstract int getSize(); 106 107 110 public abstract boolean isNull(); 111 112 115 public void read(DataInputStream inStream) throws IOException { 116 fValue = 0; 117 int size = getSize(); 118 for (int i = 0; i < size; i++) { 119 int b = inStream.readUnsignedByte(); fValue = fValue << 8 | b; 121 } 122 } 123 124 127 public void write(DataOutputStream outStream) throws IOException { 128 int size = getSize(); 129 for (int i = size - 1; i >= 0; i--) { 130 byte b = (byte)(fValue >>> 8 * i); outStream.write(b); 132 } 133 } 134 135 138 public static void getConstantMaps() { 139 if (fTagMap != null) 140 return; 141 142 java.lang.reflect.Field [] fields = JdwpID.class.getDeclaredFields(); 143 fTagMap = new HashMap (); 144 fTypeTagMap = new HashMap (); 145 for (int i = 0; i < fields.length; i++) { 146 java.lang.reflect.Field field = fields[i]; 147 if ((field.getModifiers() & java.lang.reflect.Modifier.PUBLIC) == 0 || (field.getModifiers() & java.lang.reflect.Modifier.STATIC) == 0 || (field.getModifiers() & java.lang.reflect.Modifier.FINAL) == 0) 148 continue; 149 150 try { 151 String name = field.getName(); 152 Integer intValue = new Integer (field.getInt(null)); 153 if (name.startsWith("TYPE_TAG_")) { name = name.substring(9); 155 fTypeTagMap.put(intValue, name); 156 } else if (name.endsWith("_TAG")) { fTagMap.put(intValue, name); 158 } 159 } catch (IllegalAccessException e) { 160 } catch (IllegalArgumentException e) { 162 } 166 } 167 } 168 169 172 public static Map tagMap() { 173 getConstantMaps(); 174 return fTagMap; 175 } 176 177 180 public static Map typeTagMap() { 181 getConstantMaps(); 182 return fTypeTagMap; 183 } 184 } 185 | Popular Tags |