KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > utils > bytecode > ParamNameExtractor


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 package org.apache.axis.utils.bytecode;
17
18 import org.apache.axis.components.logger.LogFactory;
19 import org.apache.axis.utils.Messages;
20 import org.apache.commons.logging.Log;
21
22 import java.io.IOException JavaDoc;
23 import java.lang.reflect.Method JavaDoc;
24 import java.lang.reflect.Proxy JavaDoc;
25
26 /**
27  * This class retieves function parameter names from bytecode built with
28  * debugging symbols. Used as a last resort when creating WSDL.
29  *
30  * @author <a HREF="mailto:tomj@macromedia.com">Tom Jordahl</a>
31  */

32 public class ParamNameExtractor {
33
34     protected static Log log =
35             LogFactory.getLog(ParamNameExtractor.class.getName());
36
37     /**
38      * Retrieve a list of function parameter names from a method
39      * Returns null if unable to read parameter names (i.e. bytecode not
40      * built with debug).
41      */

42     public static String JavaDoc[] getParameterNamesFromDebugInfo(Method JavaDoc method) {
43         // Don't worry about it if there are no params.
44
int numParams = method.getParameterTypes().length;
45         if (numParams == 0)
46             return null;
47
48         // get declaring class
49
Class JavaDoc c = method.getDeclaringClass();
50         
51         // Don't worry about it if the class is a Java dynamic proxy
52
if(Proxy.isProxyClass(c)) {
53             return null;
54         }
55         
56         try {
57             // get a parameter reader
58
ParamReader pr = new ParamReader(c);
59             // get the paramter names
60
String JavaDoc[] names = pr.getParameterNames(method);
61             return names;
62         } catch (IOException JavaDoc e) {
63             // log it and leave
64
log.info(Messages.getMessage("error00") + ":" + e);
65             return null;
66         }
67     }
68 }
Popular Tags