Here you can find the source of invoke(final Object component, final Method method, final Class> type, final String value)
Parameter | Description |
---|---|
component | the component to invoke the method on |
method | the method to invoke |
type | the property type |
value | the property value |
Parameter | Description |
---|---|
ReflectiveOperationException | if an error occurs |
private static void invoke(final Object component, final Method method, final Class<?> type, final String value) throws ReflectiveOperationException
//package com.java2s; import java.lang.reflect.Method; public class Main { /**/*from www. ja v a 2 s. co m*/ * Invoke a method. * * @param component the component to invoke the method on * @param method the method to invoke * @param type the property type * @param value the property value * @throws ReflectiveOperationException if an error occurs */ private static void invoke(final Object component, final Method method, final Class<?> type, final String value) throws ReflectiveOperationException { Object obj = valueOf(type, value); method.invoke(component, obj); } /** * Invoke a method. * * @param component the component to invoke the method on * @param method the method to invoke * @param keyType the key property type * @param valueType the value property type * @param key the property key * @param value the property value * @throws ReflectiveOperationException if an error occurs */ private static void invoke(final Object component, final Method method, final Class<?> keyType, final Class<?> valueType, final String key, final String value) throws ReflectiveOperationException { Object keyObj = valueOf(keyType, key); Object valueObj = valueOf(valueType, value); method.invoke(component, keyObj, valueObj); } /** * Convert a string value to a boxed primitive type. * * @param type the boxed primitive type * @param value the string value * @return a boxed primitive type */ public static Object valueOf(final Class<?> type, final String value) { if (type == String.class) { return value; } if (type == boolean.class) { return Boolean.valueOf(value); } if (type == int.class) { return Integer.valueOf(value); } if (type == long.class) { return Long.valueOf(value); } if (type == float.class) { return Float.valueOf(value); } if (type == double.class) { return Double.valueOf(value); } throw new IllegalArgumentException("Unsupported type " + type.getName()); } }