| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.uruma.util; |
| 17 | |
|
| 18 | |
import java.lang.reflect.Constructor; |
| 19 | |
import java.lang.reflect.InvocationTargetException; |
| 20 | |
|
| 21 | |
import org.seasar.framework.beans.BeanDesc; |
| 22 | |
import org.seasar.framework.beans.factory.BeanDescFactory; |
| 23 | |
import org.seasar.framework.exception.IllegalAccessRuntimeException; |
| 24 | |
import org.seasar.framework.exception.InstantiationRuntimeException; |
| 25 | |
import org.seasar.framework.exception.InvocationTargetRuntimeException; |
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
public class ClassUtil { |
| 33 | 0 | private ClassUtil() { |
| 34 | |
|
| 35 | 0 | } |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
@SuppressWarnings("unchecked") |
| 49 | |
public static <T> T newInstance(final Class<? extends T> clazz, |
| 50 | |
final Object... args) { |
| 51 | 5476 | BeanDesc beanDesc = BeanDescFactory.getBeanDesc(clazz); |
| 52 | 5476 | Constructor constructor = beanDesc.getSuitableConstructor(args); |
| 53 | 5476 | Object object = null; |
| 54 | |
try { |
| 55 | 5476 | object = constructor.newInstance(args); |
| 56 | 0 | } catch (InstantiationException ex) { |
| 57 | 0 | throw new InstantiationRuntimeException(clazz, ex); |
| 58 | 0 | } catch (IllegalAccessException ex) { |
| 59 | 0 | throw new IllegalAccessRuntimeException(clazz, ex); |
| 60 | 0 | } catch (InvocationTargetException ex) { |
| 61 | 0 | throw new InvocationTargetRuntimeException(clazz, ex); |
| 62 | 5476 | } |
| 63 | 5476 | return (T) object; |
| 64 | |
} |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
public static <T> T newInstance(final Class<? extends T> clazz) { |
| 76 | 3776 | return ClassUtil.<T> newInstance(clazz, (Object[]) null); |
| 77 | |
} |
| 78 | |
} |