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

com.github.tcurrie.rest.factory.proxy.MethodImplementation Maven / Gradle / Ivy

There is a newer version: 0.2.70
Show newest version
package com.github.tcurrie.rest.factory.proxy;

import com.openpojo.business.BusinessIdentity;

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

public final class MethodImplementation {
    private final T bean;
    private final Method method;

    public static  MethodImplementation create(final T bean, final Method method) {
        return new MethodImplementation<>(bean, method);
    }

    private MethodImplementation(final T bean, final Method method) {
        this.bean = bean;
        this.method = method;
    }

    public U invoke(final Object[] args) throws Throwable {
        try {
            //noinspection unchecked
            return (U) method.invoke(bean, args);
        } catch (InvocationTargetException e) {
            throw e.getCause();
        }
    }

    public String getMethodName() {
        return method.getName();
    }

    public String getBeanName() {
        return method.getDeclaringClass().getCanonicalName();
    }

    @Override
    public String toString() {
        return BusinessIdentity.toString(this);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy