1 18 package org.apache.tools.ant.taskdefs.optional.depend.constantpool; 19 20 import java.io.DataInputStream ; 21 import java.io.IOException ; 22 23 30 public abstract class ConstantPoolEntry { 31 32 33 public static final int CONSTANT_UTF8 = 1; 34 35 36 public static final int CONSTANT_INTEGER = 3; 37 38 39 public static final int CONSTANT_FLOAT = 4; 40 41 42 public static final int CONSTANT_LONG = 5; 43 44 45 public static final int CONSTANT_DOUBLE = 6; 46 47 48 public static final int CONSTANT_CLASS = 7; 49 50 51 public static final int CONSTANT_STRING = 8; 52 53 54 public static final int CONSTANT_FIELDREF = 9; 55 56 57 public static final int CONSTANT_METHODREF = 10; 58 59 60 public static final int CONSTANT_INTERFACEMETHODREF = 11; 61 62 63 public static final int CONSTANT_NAMEANDTYPE = 12; 64 65 69 private int tag; 70 71 74 private int numEntries; 75 76 79 private boolean resolved; 80 81 89 public ConstantPoolEntry(int tagValue, int entries) { 90 tag = tagValue; 91 numEntries = entries; 92 resolved = false; 93 } 94 95 107 public static ConstantPoolEntry readEntry(DataInputStream cpStream) 108 throws IOException { 109 ConstantPoolEntry cpInfo = null; 110 int cpTag = cpStream.readUnsignedByte(); 111 112 switch (cpTag) { 113 114 case CONSTANT_UTF8: 115 cpInfo = new Utf8CPInfo(); 116 117 break; 118 case CONSTANT_INTEGER: 119 cpInfo = new IntegerCPInfo(); 120 121 break; 122 case CONSTANT_FLOAT: 123 cpInfo = new FloatCPInfo(); 124 125 break; 126 case CONSTANT_LONG: 127 cpInfo = new LongCPInfo(); 128 129 break; 130 case CONSTANT_DOUBLE: 131 cpInfo = new DoubleCPInfo(); 132 133 break; 134 case CONSTANT_CLASS: 135 cpInfo = new ClassCPInfo(); 136 137 break; 138 case CONSTANT_STRING: 139 cpInfo = new StringCPInfo(); 140 141 break; 142 case CONSTANT_FIELDREF: 143 cpInfo = new FieldRefCPInfo(); 144 145 break; 146 case CONSTANT_METHODREF: 147 cpInfo = new MethodRefCPInfo(); 148 149 break; 150 case CONSTANT_INTERFACEMETHODREF: 151 cpInfo = new InterfaceMethodRefCPInfo(); 152 153 break; 154 case CONSTANT_NAMEANDTYPE: 155 cpInfo = new NameAndTypeCPInfo(); 156 157 break; 158 default: 159 throw new ClassFormatError ("Invalid Constant Pool entry Type " 160 + cpTag); 161 } 162 163 cpInfo.read(cpStream); 164 165 return cpInfo; 166 } 167 168 176 public boolean isResolved() { 177 return resolved; 178 } 179 180 187 public void resolve(ConstantPool constantPool) { 188 resolved = true; 189 } 190 191 199 public abstract void read(DataInputStream cpStream) throws IOException ; 200 201 206 public int getTag() { 207 return tag; 208 } 209 210 216 public final int getNumEntries() { 217 return numEntries; 218 } 219 220 } 221 222 | Popular Tags |