1 package org.apache.axis.tool.core; 2 3 import java.io.File; 4 import java.io.IOException; 5 import java.lang.reflect.Method; 6 import java.net.URL; 7 import java.net.URLClassLoader; 8 import java.util.ArrayList; 9 import java.util.Enumeration; 10 11 import sun.misc.URLClassPath; 12 27 public class ClassFileHandler { 28 29 30 37 public ArrayList getClassesAtLocation(String location) throws IOException { 39 File fileEndpoint = new File(location); 40 if (!fileEndpoint.exists()) 41 throw new IOException("the location is invalid"); 42 URL[] urlList = {fileEndpoint.toURL()}; 43 URLClassPath classLoader = new URLClassPath(urlList); 44 Enumeration enum = classLoader.getResources(""); 45 46 while (enum.hasMoreElements()) { 47 Object o = enum.nextElement(); 48 System.out.println("o = " + o); 49 } 50 return null; 51 52 } 53 54 public ArrayList getMethodNamesFromClass(String classFileName,String location) throws IOException, ClassNotFoundException{ 55 ArrayList returnList = new ArrayList(); 56 File fileEndpoint = new File(location); 57 if (!fileEndpoint.exists()) 58 throw new IOException("the location is invalid"); 59 URL[] urlList = {fileEndpoint.toURL()}; 60 URLClassLoader clazzLoader = new URLClassLoader(urlList); 61 Class clazz = clazzLoader.loadClass(classFileName); 62 Method[] methods = clazz.getDeclaredMethods(); 63 64 for (int i = 0; i < methods.length; i++) { 65 returnList.add(methods[i].getName()); 66 67 } 68 return returnList; 69 } 70 71 } 72 | Popular Tags |