01: /*
02: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
03: *
04: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
05: *
06: * The contents of this file are subject to the terms of either the GNU
07: * General Public License Version 2 only ("GPL") or the Common
08: * Development and Distribution License("CDDL") (collectively, the
09: * "License"). You may not use this file except in compliance with the
10: * License. You can obtain a copy of the License at
11: * http://www.netbeans.org/cddl-gplv2.html
12: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13: * specific language governing permissions and limitations under the
14: * License. When distributing the software, include this License Header
15: * Notice in each file and include the License file at
16: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17: * particular file as subject to the "Classpath" exception as provided
18: * by Sun in the GPL Version 2 section of the License file that
19: * accompanied this code. If applicable, add the following below the
20: * License Header, with the fields enclosed by brackets [] replaced by
21: * your own identifying information:
22: * "Portions Copyrighted [year] [name of copyright owner]"
23: *
24: * Contributor(s):
25: *
26: * Portions Copyrighted 2007 Sun Microsystems, Inc.
27: */
28: package org.netbeans.modules.visualweb.websvcmgr.codegen;
29:
30: import java.lang.reflect.Method;
31: import java.lang.reflect.Type;
32: import java.util.ArrayList;
33: import java.util.List;
34: import org.netbeans.modules.websvc.manager.util.ManagerUtil;
35:
36: /**
37: *
38: * @author quynguyen
39: */
40: public class DataProviderJavaMethod implements DataProviderMethod {
41: private String name;
42: private String returnType;
43: private List<DataProviderParameter> parameters;
44: private List<String> exceptions;
45:
46: public DataProviderJavaMethod(Method method) {
47: this .name = method.getName();
48: this .returnType = ManagerUtil.typeToString(method
49: .getGenericReturnType());
50: if (returnType == null) {
51: returnType = method.getReturnType().getCanonicalName();
52: }
53:
54: this .parameters = new ArrayList<DataProviderParameter>();
55: Type[] methodParameters = method.getGenericParameterTypes();
56: Class[] methodClassParameters = method.getParameterTypes();
57: for (int i = 0; i < methodParameters.length; i++) {
58: String nextParamType = ManagerUtil
59: .typeToString(methodParameters[i]);
60: if (nextParamType == null) {
61: nextParamType = methodClassParameters[i]
62: .getCanonicalName();
63: }
64:
65: parameters.add(new DataProviderParameter(nextParamType,
66: "arg" + i));
67: }
68:
69: this .exceptions = new ArrayList<String>();
70: Type[] methodExceptions = method.getGenericExceptionTypes();
71: Class[] methodClassExceptions = method.getExceptionTypes();
72: for (int i = 0; i < methodExceptions.length; i++) {
73: String nextException = ManagerUtil
74: .typeToString(methodExceptions[i]);
75: if (nextException == null) {
76: nextException = methodClassExceptions[i]
77: .getCanonicalName();
78: }
79:
80: exceptions.add(nextException);
81: }
82: }
83:
84: public String getMethodName() {
85: return name;
86: }
87:
88: public String getMethodReturnType() {
89: return returnType;
90: }
91:
92: public List<DataProviderParameter> getParameters() {
93: return parameters;
94: }
95:
96: public List<String> getExceptions() {
97: return exceptions;
98: }
99: }
|