|
Lines 11-16
Link Here
|
| 11 |
package org.eclipse.rwt.internal.util; |
11 |
package org.eclipse.rwt.internal.util; |
| 12 |
|
12 |
|
| 13 |
import java.lang.reflect.Constructor; |
13 |
import java.lang.reflect.Constructor; |
|
|
14 |
import java.lang.reflect.InvocationTargetException; |
| 14 |
|
15 |
|
| 15 |
|
16 |
|
| 16 |
public final class ClassUtil { |
17 |
public final class ClassUtil { |
|
Lines 33-44
Link Here
|
| 33 |
|
34 |
|
| 34 |
public static Object newInstance( Class type, Class[] paramTypes, Object[] paramValues ) { |
35 |
public static Object newInstance( Class type, Class[] paramTypes, Object[] paramValues ) { |
| 35 |
ParamCheck.notNull( type, "type" ); |
36 |
ParamCheck.notNull( type, "type" ); |
|
|
37 |
Object result = null; |
| 36 |
try { |
38 |
try { |
| 37 |
return createInstance( type, paramTypes, paramValues ); |
39 |
result = createInstance( type, paramTypes, paramValues ); |
| 38 |
} catch( Exception e ) { |
40 |
} catch( RuntimeException rte ) { |
| 39 |
String msg = "Failed to create instance of type: " + type.getName(); |
41 |
throw rte; |
| 40 |
throw new ClassInstantiationException( msg, e ); |
42 |
} catch( InvocationTargetException ite ) { |
|
|
43 |
rethrowRuntimeExceptions( ite ); |
| 44 |
throwInstantiationException( type, ite.getCause() ); |
| 45 |
} catch( Exception exception ) { |
| 46 |
throwInstantiationException( type, exception ); |
| 41 |
} |
47 |
} |
|
|
48 |
return result; |
| 42 |
} |
49 |
} |
| 43 |
|
50 |
|
| 44 |
private static Object createInstance( Class type, Class[] paramTypes, Object[] paramValues ) |
51 |
private static Object createInstance( Class type, Class[] paramTypes, Object[] paramValues ) |
|
Lines 51-57
Link Here
|
| 51 |
return constructor.newInstance( paramValues ); |
58 |
return constructor.newInstance( paramValues ); |
| 52 |
} |
59 |
} |
| 53 |
|
60 |
|
|
|
61 |
private static void rethrowRuntimeExceptions( InvocationTargetException ite ) { |
| 62 |
if( ite.getCause() instanceof RuntimeException ) { |
| 63 |
throw ( RuntimeException )ite.getCause(); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
private static void throwInstantiationException( Class type, Throwable cause ) { |
| 68 |
String msg = "Failed to create instance of type: " + type.getName(); |
| 69 |
throw new ClassInstantiationException( msg, cause ); |
| 70 |
} |
| 71 |
|
| 54 |
private ClassUtil() { |
72 |
private ClassUtil() { |
| 55 |
// prevent instantiation |
73 |
// prevent instantiation |
| 56 |
} |
74 |
} |
| 57 |
} |
75 |
} |