KickJava   Java API By Example, From Geeks To Geeks.

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


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.Vector JavaDoc;
21
22 /**
23  * A simple cache of previously loaded methods
24  *
25  * @author Sam Ruby <rubys@us.ibm.com>
26  */

27 public class JavaMethod {
28
29     // The list of the methods in the given class with the given name.
30
private Method JavaDoc[] methods = null;
31
32     /**
33      * Create a cache entry for this java.lang.Class
34      * @param jc java.lang.Class which will be searched for methods
35      * @param name name of the method
36      */

37     public JavaMethod(Class JavaDoc jc, String JavaDoc name) {
38         Method JavaDoc[] methods = jc.getMethods();
39         Vector JavaDoc workinglist = new Vector JavaDoc();
40
41         // scan for matching names, saving the match if it is unique,
42
// otherwise accumulating a list
43
for (int i=0; i<methods.length; i++) {
44             if (methods[i].getName().equals(name)) {
45                 workinglist.addElement(methods[i]);
46             }
47         }
48
49         // If a list was found, convert it into an array
50
if (workinglist.size() > 0) {
51             this.methods = new Method JavaDoc[workinglist.size()];
52             workinglist.copyInto(this.methods);
53         }
54     }
55     
56     /**
57      * Lookup a method based on name. This method returns an array just in
58      * case there is more than one.
59      * @param name name of method
60      */

61     public Method JavaDoc[] getMethod() {
62         return methods;
63     }
64 };
65
Popular Tags