Search in sources :

Example 1 with Invoker

use of org.apache.ibatis.reflection.invoker.Invoker in project mybatis-3 by mybatis.

the class MetaClass method getGenericGetterType.

private Type getGenericGetterType(String propertyName) {
    try {
        Invoker invoker = reflector.getGetInvoker(propertyName);
        if (invoker instanceof MethodInvoker) {
            Field _method = MethodInvoker.class.getDeclaredField("method");
            _method.setAccessible(true);
            Method method = (Method) _method.get(invoker);
            return TypeParameterResolver.resolveReturnType(method, reflector.getType());
        } else if (invoker instanceof GetFieldInvoker) {
            Field _field = GetFieldInvoker.class.getDeclaredField("field");
            _field.setAccessible(true);
            Field field = (Field) _field.get(invoker);
            return TypeParameterResolver.resolveFieldType(field, reflector.getType());
        }
    } catch (NoSuchFieldException e) {
    } catch (IllegalAccessException e) {
    }
    return null;
}
Also used : Field(java.lang.reflect.Field) GetFieldInvoker(org.apache.ibatis.reflection.invoker.GetFieldInvoker) Invoker(org.apache.ibatis.reflection.invoker.Invoker) GetFieldInvoker(org.apache.ibatis.reflection.invoker.GetFieldInvoker) MethodInvoker(org.apache.ibatis.reflection.invoker.MethodInvoker) Method(java.lang.reflect.Method) MethodInvoker(org.apache.ibatis.reflection.invoker.MethodInvoker)

Example 2 with Invoker

use of org.apache.ibatis.reflection.invoker.Invoker in project mybatis-3 by mybatis.

the class BeanWrapper method setBeanProperty.

private void setBeanProperty(PropertyTokenizer prop, Object object, Object value) {
    try {
        Invoker method = metaClass.getSetInvoker(prop.getName());
        Object[] params = { value };
        try {
            method.invoke(object, params);
        } catch (Throwable t) {
            throw ExceptionUtil.unwrapThrowable(t);
        }
    } catch (Throwable t) {
        throw new ReflectionException("Could not set property '" + prop.getName() + "' of '" + object.getClass() + "' with value '" + value + "' Cause: " + t.toString(), t);
    }
}
Also used : ReflectionException(org.apache.ibatis.reflection.ReflectionException) Invoker(org.apache.ibatis.reflection.invoker.Invoker) SystemMetaObject(org.apache.ibatis.reflection.SystemMetaObject) MetaObject(org.apache.ibatis.reflection.MetaObject)

Aggregations

Invoker (org.apache.ibatis.reflection.invoker.Invoker)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 MetaObject (org.apache.ibatis.reflection.MetaObject)1 ReflectionException (org.apache.ibatis.reflection.ReflectionException)1 SystemMetaObject (org.apache.ibatis.reflection.SystemMetaObject)1 GetFieldInvoker (org.apache.ibatis.reflection.invoker.GetFieldInvoker)1 MethodInvoker (org.apache.ibatis.reflection.invoker.MethodInvoker)1