org.snapscript.platform.standard.DelegateMethodInvocation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.platform.standard;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.snapscript.core.error.InternalStateException;
import org.snapscript.core.function.Invocation;
import org.snapscript.core.scope.Scope;
public class DelegateMethodInvocation implements Invocation {
private final Method method;
public DelegateMethodInvocation(Method method) {
this.method = method;
}
@Override
public Object invoke(Scope scope, Object value, Object... arguments) throws Exception {
try {
return method.invoke(value, arguments);
}catch(InvocationTargetException cause) {
Throwable target = cause.getTargetException();
if(target != null) {
throw new InternalStateException("Error occured invoking " + method, target);
}
throw cause;
}catch(InternalError cause) {
Throwable target = cause.getCause();
if(target != null) {
throw new InternalStateException("Error occured invoking " + method, target);
}
throw cause;
}
}
}