KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > tool > core > ClassFileHandler


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 /*
13  * Copyright 2004,2005 The Apache Software Foundation.
14  *
15  * Licensed under the Apache License, Version 2.0 (the "License");
16  * you may not use this file except in compliance with the License.
17  * You may obtain a copy of the License at
18  *
19  * http://www.apache.org/licenses/LICENSE-2.0
20  *
21  * Unless required by applicable law or agreed to in writing, software
22  * distributed under the License is distributed on an "AS IS" BASIS,
23  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24  * See the License for the specific language governing permissions and
25  * limitations under the License.
26  */

27 public class ClassFileHandler {
28
29
30     /**
31      * @deprecated
32      * This needs to be written in a functional manner
33      * @param location
34      * @return
35      * @throws IOException
36      */

37     //todo see whether this is possible
38
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