7
7
package org .hibernate .validator .internal .util .annotation ;
8
8
9
9
import java .lang .annotation .Annotation ;
10
- import java .lang .reflect .Constructor ;
11
- import java .lang .reflect .InvocationHandler ;
12
- import java .lang .reflect .InvocationTargetException ;
13
- import java .lang .reflect .Proxy ;
14
10
import java .security .AccessController ;
15
11
import java .security .PrivilegedAction ;
16
12
17
- import org .hibernate .validator .internal .util .privilegedactions .ConstructorInstance ;
18
13
import org .hibernate .validator .internal .util .privilegedactions .GetClassLoader ;
19
- import org .hibernate .validator .internal .util .privilegedactions .GetDeclaredConstructor ;
14
+ import org .hibernate .validator .internal .util .privilegedactions .NewProxyInstance ;
20
15
21
16
/**
22
17
* Creates live annotations (actually {@link AnnotationProxy} instances) from {@code AnnotationDescriptor}s.
@@ -32,31 +27,11 @@ private AnnotationFactory() {
32
27
}
33
28
34
29
public static <T extends Annotation > T create (AnnotationDescriptor <T > descriptor ) {
35
- @ SuppressWarnings ("unchecked" )
36
- Class <T > proxyClass = (Class <T >) Proxy .getProxyClass (
30
+ return run ( NewProxyInstance .action (
37
31
run ( GetClassLoader .fromClass ( descriptor .getType () ) ),
38
- descriptor .getType ()
39
- );
40
- InvocationHandler handler = new AnnotationProxy ( descriptor );
41
- try {
42
- return getProxyInstance ( proxyClass , handler );
43
- }
44
- catch (RuntimeException e ) {
45
- throw e ;
46
- }
47
- catch (Exception e ) {
48
- throw new RuntimeException ( e );
49
- }
50
- }
51
-
52
- private static <T extends Annotation > T getProxyInstance (Class <T > proxyClass , InvocationHandler handler ) throws
53
- SecurityException , NoSuchMethodException , IllegalArgumentException , InstantiationException ,
54
- IllegalAccessException , InvocationTargetException {
55
- final Constructor <T > constructor = run ( GetDeclaredConstructor .action (
56
- proxyClass ,
57
- InvocationHandler .class
32
+ descriptor .getType (),
33
+ new AnnotationProxy ( descriptor )
58
34
) );
59
- return run ( ConstructorInstance .action ( constructor , handler ) );
60
35
}
61
36
62
37
/**
0 commit comments