1 package org.apache.maven.shared.dependency.graph.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
23
24
25
26
27 final class Invoker
28 {
29 private Invoker()
30 {
31
32 }
33
34 static <T extends Exception> Object invoke( Object object, String method, ExceptionHandler<T> exceptionHandler )
35 throws T
36 {
37 return invoke( object.getClass(), object, method, exceptionHandler );
38 }
39
40 static <T extends Exception> Object invoke( Class<?> objectClazz, Object object, String method,
41 ExceptionHandler<T> exceptionHandler )
42 throws T
43 {
44 try
45 {
46 return objectClazz.getMethod( method ).invoke( object );
47 }
48 catch ( ReflectiveOperationException e )
49 {
50 throw exceptionHandler.create( e.getMessage(), e );
51 }
52 }
53
54 static Object invoke( Object object, String method, Class<?> clazz, Object arg )
55 throws DependencyGraphBuilderException
56 {
57 try
58 {
59 final Class<?> objectClazz = object.getClass();
60 return objectClazz.getMethod( method, clazz ).invoke( object, arg );
61 }
62 catch ( ReflectiveOperationException e )
63 {
64 throw new DependencyGraphBuilderException( e.getMessage(), e );
65 }
66 }
67
68 static <T extends Exception> Object invoke( Class<?> objectClazz, String staticMethod,
69 Class<?> argClazz, Object arg,
70 ExceptionHandler<T> exceptionHandler )
71 throws T
72 {
73 try
74 {
75 return objectClazz.getMethod( staticMethod, argClazz ).invoke( null, arg );
76 }
77 catch ( ReflectiveOperationException e )
78 {
79 throw exceptionHandler.create( e.getMessage(), e );
80 }
81 }
82
83 static <T extends Exception> Object invoke( Class<?> objectClazz, String staticMethod, Class<?> argClazz1,
84 Class<?> argClazz2, Object arg1, Object arg2,
85 ExceptionHandler<T> exceptionHandler )
86 throws T
87 {
88 try
89 {
90 return objectClazz.getMethod( staticMethod, argClazz1, argClazz2 ).invoke( null, arg1, arg2 );
91 }
92 catch ( ReflectiveOperationException e )
93 {
94 throw exceptionHandler.create( e.getMessage(), e );
95 }
96 }
97 }