equal
deleted
inserted
replaced
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 package com.sun.beans.finder; |
25 package com.sun.beans.finder; |
26 |
26 |
27 import com.sun.beans.TypeResolver; |
27 import com.sun.beans.TypeResolver; |
28 import com.sun.beans.WeakCache; |
28 import com.sun.beans.util.Cache; |
29 |
29 |
30 import java.lang.reflect.Method; |
30 import java.lang.reflect.Method; |
31 import java.lang.reflect.Modifier; |
31 import java.lang.reflect.Modifier; |
32 import java.lang.reflect.ParameterizedType; |
32 import java.lang.reflect.ParameterizedType; |
33 import java.lang.reflect.Type; |
33 import java.lang.reflect.Type; |
34 import java.util.Arrays; |
34 import java.util.Arrays; |
35 |
35 |
|
36 import static com.sun.beans.util.Cache.Kind.SOFT; |
36 import static sun.reflect.misc.ReflectUtil.isPackageAccessible; |
37 import static sun.reflect.misc.ReflectUtil.isPackageAccessible; |
37 |
38 |
38 /** |
39 /** |
39 * This utility class provides {@code static} methods |
40 * This utility class provides {@code static} methods |
40 * to find a public method with specified name and parameter types |
41 * to find a public method with specified name and parameter types |
43 * @since 1.7 |
44 * @since 1.7 |
44 * |
45 * |
45 * @author Sergey A. Malenkov |
46 * @author Sergey A. Malenkov |
46 */ |
47 */ |
47 public final class MethodFinder extends AbstractFinder<Method> { |
48 public final class MethodFinder extends AbstractFinder<Method> { |
48 private static final WeakCache<Signature, Method> CACHE = new WeakCache<Signature, Method>(); |
49 private static final Cache<Signature, Method> CACHE = new Cache<Signature, Method>(SOFT, SOFT) { |
|
50 @Override |
|
51 public Method create(Signature signature) { |
|
52 try { |
|
53 MethodFinder finder = new MethodFinder(signature.getName(), signature.getArgs()); |
|
54 return findAccessibleMethod(finder.find(signature.getType().getMethods())); |
|
55 } |
|
56 catch (Exception exception) { |
|
57 throw new SignatureException(exception); |
|
58 } |
|
59 } |
|
60 }; |
49 |
61 |
50 /** |
62 /** |
51 * Finds public method (static or non-static) |
63 * Finds public method (static or non-static) |
52 * that is accessible from public class. |
64 * that is accessible from public class. |
53 * |
65 * |
63 throw new IllegalArgumentException("Method name is not set"); |
75 throw new IllegalArgumentException("Method name is not set"); |
64 } |
76 } |
65 PrimitiveWrapperMap.replacePrimitivesWithWrappers(args); |
77 PrimitiveWrapperMap.replacePrimitivesWithWrappers(args); |
66 Signature signature = new Signature(type, name, args); |
78 Signature signature = new Signature(type, name, args); |
67 |
79 |
68 Method method = CACHE.get(signature); |
80 try { |
69 boolean cached = method != null; |
81 Method method = CACHE.get(signature); |
70 if (cached && isPackageAccessible(method.getDeclaringClass())) { |
82 return (method == null) || isPackageAccessible(method.getDeclaringClass()) ? method : CACHE.create(signature); |
71 return method; |
83 } |
72 } |
84 catch (SignatureException exception) { |
73 method = findAccessibleMethod(new MethodFinder(name, args).find(type.getMethods())); |
85 throw exception.toNoSuchMethodException("Method '" + name + "' is not found"); |
74 if (!cached) { |
86 } |
75 CACHE.put(signature, method); |
|
76 } |
|
77 return method; |
|
78 } |
87 } |
79 |
88 |
80 /** |
89 /** |
81 * Finds public non-static method |
90 * Finds public non-static method |
82 * that is accessible from public class. |
91 * that is accessible from public class. |