All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.vality.woody.api.proxy.ReflectionMethodCallerFactory Maven / Gradle / Ivy

There is a newer version: 2.0.8
Show newest version
package dev.vality.woody.api.proxy;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectionMethodCallerFactory implements MethodCallerFactory {
    @Override
    public InstanceMethodCaller getInstance(InvocationTargetProvider targetProvider, Method method) {
        method.setAccessible(true);
        return new InstanceMethodCaller(method) {
            @Override
            public Object call(Object source, Object[] args) throws Throwable {
                Object target = targetProvider.getTarget();
                try {
                    try {
                        return method.invoke(target, args);
                    } finally {
                        targetProvider.releaseTarget(target);
                    }
                } catch (InvocationTargetException e) {
                    Throwable cause = e.getCause();
                    throw cause == null ? e : cause;
                }
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy