KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > utils > cache > JavaClass


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.utils.cache;
18
19 import java.lang.reflect.Method JavaDoc;
20 import java.util.Hashtable JavaDoc;
21 import java.io.Serializable JavaDoc;
22
23 /**
24  * A simple cache of previously loaded classes, and their methods.
25  *
26  * @author Sam Ruby <rubys@us.ibm.com>
27  */

28 public class JavaClass implements Serializable JavaDoc {
29
30     private static Hashtable JavaDoc classes = new Hashtable JavaDoc();
31     private Hashtable JavaDoc methods = new Hashtable JavaDoc();
32
33     private Class JavaDoc jc;
34
35     /**
36      * Find (or create if necessary) a JavaClass associated with a given
37      * class
38      */

39     public static synchronized JavaClass find(Class JavaDoc jc) {
40         JavaClass result = (JavaClass) classes.get(jc);
41
42         if (result == null) {
43             result = new JavaClass(jc);
44             classes.put(jc, result);
45         }
46
47         return result;
48     }
49
50     /**
51      * Create a cache entry for this java.lang.Class
52      */

53     public JavaClass(Class JavaDoc jc) {
54         this.jc = jc;
55         classes.put(jc, this);
56     }
57     
58     /**
59      * Return the java.lang.Class associated with this entry
60      */

61     public Class JavaDoc getJavaClass() {
62         return jc;
63     }
64
65     /**
66      * Lookup a method based on name. This method returns an array just in
67      * case there is more than one.
68      * @param name name of method
69      */

70     public Method JavaDoc[] getMethod(String JavaDoc name) {
71         JavaMethod jm = (JavaMethod) methods.get(name);
72
73         if (jm == null) {
74             methods.put(name, jm=new JavaMethod(jc, name));
75         }
76
77         return jm.getMethod();
78     }
79 };
80
Popular Tags