equal
deleted
inserted
replaced
22 * or visit www.oracle.com if you need additional information or have any |
22 * or visit www.oracle.com if you need additional information or have any |
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.WeakCache; |
27 import com.sun.beans.util.Cache; |
28 |
28 |
29 import java.lang.reflect.Constructor; |
29 import java.lang.reflect.Constructor; |
30 import java.lang.reflect.Modifier; |
30 import java.lang.reflect.Modifier; |
31 |
31 |
|
32 import static com.sun.beans.util.Cache.Kind.SOFT; |
32 import static sun.reflect.misc.ReflectUtil.isPackageAccessible; |
33 import static sun.reflect.misc.ReflectUtil.isPackageAccessible; |
33 |
34 |
34 /** |
35 /** |
35 * This utility class provides {@code static} methods |
36 * This utility class provides {@code static} methods |
36 * to find a public constructor with specified parameter types |
37 * to find a public constructor with specified parameter types |
39 * @since 1.7 |
40 * @since 1.7 |
40 * |
41 * |
41 * @author Sergey A. Malenkov |
42 * @author Sergey A. Malenkov |
42 */ |
43 */ |
43 public final class ConstructorFinder extends AbstractFinder<Constructor<?>> { |
44 public final class ConstructorFinder extends AbstractFinder<Constructor<?>> { |
44 private static final WeakCache<Signature, Constructor<?>> CACHE = new WeakCache<Signature, Constructor<?>>(); |
45 private static final Cache<Signature, Constructor<?>> CACHE = new Cache<Signature, Constructor<?>>(SOFT, SOFT) { |
|
46 @Override |
|
47 public Constructor create(Signature signature) { |
|
48 try { |
|
49 ConstructorFinder finder = new ConstructorFinder(signature.getArgs()); |
|
50 return finder.find(signature.getType().getConstructors()); |
|
51 } |
|
52 catch (Exception exception) { |
|
53 throw new SignatureException(exception); |
|
54 } |
|
55 } |
|
56 }; |
45 |
57 |
46 /** |
58 /** |
47 * Finds public constructor |
59 * Finds public constructor |
48 * that is declared in public class. |
60 * that is declared in public class. |
49 * |
61 * |
67 throw new NoSuchMethodException("Class is not accessible"); |
79 throw new NoSuchMethodException("Class is not accessible"); |
68 } |
80 } |
69 PrimitiveWrapperMap.replacePrimitivesWithWrappers(args); |
81 PrimitiveWrapperMap.replacePrimitivesWithWrappers(args); |
70 Signature signature = new Signature(type, args); |
82 Signature signature = new Signature(type, args); |
71 |
83 |
72 Constructor<?> constructor = CACHE.get(signature); |
84 try { |
73 if (constructor != null) { |
85 return CACHE.get(signature); |
74 return constructor; |
|
75 } |
86 } |
76 constructor = new ConstructorFinder(args).find(type.getConstructors()); |
87 catch (SignatureException exception) { |
77 CACHE.put(signature, constructor); |
88 throw exception.toNoSuchMethodException("Constructor is not found"); |
78 return constructor; |
89 } |
79 } |
90 } |
80 |
91 |
81 /** |
92 /** |
82 * Creates constructor finder with specified array of parameter types. |
93 * Creates constructor finder with specified array of parameter types. |
83 * |
94 * |