1 /*
2 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
29 import java.lang.ref.WeakReference;
30 import java.lang.reflect.Method;
31 import java.util.List;
32 import java.util.ArrayList;
33
34 /**
35 * A MethodDescriptor describes a particular method that a Java Bean
36 * supports for external access from other components.
37 *
38 * @since 1.1
39 */
40
41 public class MethodDescriptor extends FeatureDescriptor {
42
43 private final MethodRef methodRef = new MethodRef();
44
45 private String[] paramNames;
46
47 private List<WeakReference<Class<?>>> params;
48
49 private ParameterDescriptor parameterDescriptors[];
50
51 /**
52 * Constructs a {@code MethodDescriptor} from a
53 * {@code Method}.
54 *
55 * @param method The low-level method information.
56 */
57 public MethodDescriptor(Method method) {
58 this(method, null);
59 }
60
61
62 /**
63 * Constructs a {@code MethodDescriptor} from a
64 * {@code Method} providing descriptive information for each
65 * of the method's parameters.
66 *
67 * @param method The low-level method information.
68 * @param parameterDescriptors Descriptive information for each of the
69 * method's parameters.
70 */
71 public MethodDescriptor(Method method,
72 ParameterDescriptor parameterDescriptors[]) {
73 setName(method.getName());
74 setMethod(method);
75 this.parameterDescriptors = (parameterDescriptors != null)
76 ? parameterDescriptors.clone()
77 : null;
78 }
79
80 /**
81 * Gets the method that this MethodDescriptor encapsulates.
82 *
83 * @return The low-level description of the method
84 */
85 public synchronized Method getMethod() {
86 Method method = this.methodRef.get();
87 if (method == null) {
88 Class<?> cls = getClass0();
89 String name = getName();
90 if ((cls != null) && (name != null)) {
91 Class<?>[] params = getParams();
92 if (params == null) {
|
1 /*
2 * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
29 import java.lang.ref.WeakReference;
30 import java.lang.reflect.Method;
31 import java.util.List;
32 import java.util.ArrayList;
33
34 /**
35 * A MethodDescriptor describes a particular method that a Java Bean
36 * supports for external access from other components.
37 *
38 * @since 1.1
39 */
40
41 public class MethodDescriptor extends FeatureDescriptor {
42
43 private final MethodRef methodRef = new MethodRef();
44
45 private String[] paramNames;
46
47 private List<WeakReference<Class<?>>> params;
48
49 private ParameterDescriptor[] parameterDescriptors;
50
51 /**
52 * Constructs a {@code MethodDescriptor} from a
53 * {@code Method}.
54 *
55 * @param method The low-level method information.
56 */
57 public MethodDescriptor(Method method) {
58 this(method, null);
59 }
60
61
62 /**
63 * Constructs a {@code MethodDescriptor} from a
64 * {@code Method} providing descriptive information for each
65 * of the method's parameters.
66 *
67 * @param method The low-level method information.
68 * @param parameterDescriptors Descriptive information for each of the
69 * method's parameters.
70 */
71 public MethodDescriptor(Method method,
72 ParameterDescriptor[] parameterDescriptors) {
73 setName(method.getName());
74 setMethod(method);
75 this.parameterDescriptors = (parameterDescriptors != null)
76 ? parameterDescriptors.clone()
77 : null;
78 }
79
80 /**
81 * Gets the method that this MethodDescriptor encapsulates.
82 *
83 * @return The low-level description of the method
84 */
85 public synchronized Method getMethod() {
86 Method method = this.methodRef.get();
87 if (method == null) {
88 Class<?> cls = getClass0();
89 String name = getName();
90 if ((cls != null) && (name != null)) {
91 Class<?>[] params = getParams();
92 if (params == null) {
|