1 18 19 package alt.jiapi.reflect; 20 21 import java.io.InputStream ; 22 import java.io.IOException ; 23 import java.lang.reflect.Modifier ; 24 import java.net.URL ; 25 import java.util.ArrayList ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 import java.util.List ; 29 import java.util.Iterator ; 30 31 import org.apache.log4j.Category; 32 33 import alt.jiapi.Runtime; import alt.jiapi.file.ClassFile; 35 36 85 86 93 public class Loader { 94 97 public Loader() { 98 } 99 100 115 public JiapiClass loadClass(InputStream is) throws ClassNotFoundException , IOException { 116 ClassFile clazz = ClassFile.parse(is); 117 118 JiapiClass jiapiClass = new JiapiClass(clazz); 119 jiapiClass.setLoader(this); 120 121 return jiapiClass; 122 } 123 124 125 140 public JiapiClass loadClass(String className) throws ClassNotFoundException , IOException { 141 return loadClass(className, null); 142 } 143 144 160 public JiapiClass loadClass(String className, URL location) throws ClassNotFoundException , IOException { 161 JiapiClass jiapiClass = null; 162 163 InputStream is = getInputStream(className, location); 164 if (is == null) { 165 throw new ClassNotFoundException (className); 166 } 167 168 ClassFile clazz = ClassFile.parse(is); 169 170 jiapiClass = new JiapiClass(clazz); 171 jiapiClass.setLoader(this); 172 173 return jiapiClass; 174 } 175 176 177 private InputStream getInputStream(String name, URL location) throws IOException { 178 if (location == null) { 179 String resource = "/" + name.replace('.', '/') + ".class"; 180 181 return getClass().getResourceAsStream(resource); 182 } 183 return location.openStream(); 184 } 186 187 public static void main(String [] args) throws Exception { 200 Loader l = new Loader(); 201 JiapiClass clazz = l.loadClass(args[0]); 202 System.out.println(clazz); 203 204 if (args.length > 2) { 205 clazz.addInterface(args[2]); 206 } 207 208 212 clazz.addField("jiapi_generated"); 213 214 if (args.length > 1) { 215 clazz.dump(new java.io.FileOutputStream (args[1])); 216 } 217 218 } 219 } 220 | Popular Tags |