本文整理汇总了Java中org.codehaus.groovy.runtime.InvokerInvocationException类的典型用法代码示例。如果您正苦于以下问题:Java InvokerInvocationException类的具体用法?Java InvokerInvocationException怎么用?Java InvokerInvocationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InvokerInvocationException类属于org.codehaus.groovy.runtime包,在下文中一共展示了InvokerInvocationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: will
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
void will(final Closure cl) {
will(new Action() {
public void describeTo(Description description) {
description.appendText("execute closure");
}
public Object invoke(Invocation invocation) throws Throwable {
List<Object> params = Arrays.asList(invocation.getParametersAsArray());
Object result;
try {
List<Object> subParams = params.subList(0, Math.min(invocation.getParametersAsArray().length,
cl.getMaximumNumberOfParameters()));
result = cl.call(subParams.toArray(new Object[0]));
} catch (InvokerInvocationException e) {
throw e.getCause();
}
if (invocation.getInvokedMethod().getReturnType().isInstance(result)) {
return result;
}
return null;
}
});
}
示例2: execute
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
public void execute(Task task) {
closure.setDelegate(task);
closure.setResolveStrategy(Closure.DELEGATE_FIRST);
ClassLoader original = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(closure.getClass().getClassLoader());
try {
if (closure.getMaximumNumberOfParameters() == 0) {
closure.call();
} else {
closure.call(task);
}
} catch (InvokerInvocationException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
}
throw e;
} finally {
Thread.currentThread().setContextClassLoader(original);
}
}
示例3: callControllerAwareMethod
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
/**
* Check whether the script declares a method with the given name that takes a
* corpus parameter, and if so, call it passing the corpus from the given
* controller. If the controller is not a CorpusController, do nothing.
*
* @throws ExecutionException
* if the script method throws an ExecutionException we re-throw it
*/
protected void callControllerAwareMethod(String methodName, Controller c)
throws ExecutionException {
if(!(c instanceof CorpusController)) { return; }
List<MetaMethod> metaMethods =
groovyScript.getMetaClass().respondsTo(groovyScript, methodName,
new Class[]{gate.Corpus.class});
if(!metaMethods.isEmpty()) {
try {
metaMethods.get(0).invoke(groovyScript,
new Corpus[]{((CorpusController)c).getCorpus()});
} catch(InvokerInvocationException iie) {
if(iie.getCause() instanceof ExecutionException) {
throw (ExecutionException)iie.getCause();
} else if(iie.getCause() instanceof RuntimeException) {
throw (RuntimeException)iie.getCause();
} else if(iie.getCause() instanceof Error) {
throw (Error)iie.getCause();
} else {
throw iie;
}
}
}
}
示例4: testChecksReflectPermissionForInvokeOnPackagePrivateMethodsInRestrictedJavaPackages
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
public void testChecksReflectPermissionForInvokeOnPackagePrivateMethodsInRestrictedJavaPackages() throws Exception {
// FIX_JDK9 remove this exemption for JDK9
if (new BigDecimal(System.getProperty("java.specification.version")).compareTo(new BigDecimal("9.0")) >= 0) {
return;
}
cachedMethodUnderTest = createCachedMethod(ClassLoader.class, "getBootstrapClassPath", new Class[0]);
System.setSecurityManager(restrictiveSecurityManager);
try {
cachedMethodUnderTest.invoke(null, new Object[]{});
fail();
}
catch (InvokerInvocationException e) {
assertEquals(CacheAccessControlException.class, e.getCause().getClass());
}
}
示例5: testChecksCreateClassLoaderPermissionForClassLoaderProtectedMethodAccess
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
public void testChecksCreateClassLoaderPermissionForClassLoaderProtectedMethodAccess() throws Exception {
cachedMethodUnderTest = createCachedMethod(ClassLoader.class, "defineClass", new Class[]{String.class, ByteBuffer.class, ProtectionDomain.class});
forbidden = new Permissions();
forbidden.add(new RuntimePermission("createClassLoader"));
System.setSecurityManager(restrictiveSecurityManager);
ClassLoader classLoader = getClass().getClassLoader();
try {
cachedMethodUnderTest.invoke(classLoader, new Object[]{null, null, null});
fail();
}
catch (InvokerInvocationException e) {
assertEquals(CacheAccessControlException.class, e.getCause().getClass());
}
}
示例6: will
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
void will(final Closure cl) {
will(new Action() {
public void describeTo(Description description) {
description.appendText("execute closure");
}
public Object invoke(Invocation invocation) throws Throwable {
List<Object> params = Arrays.asList(invocation.getParametersAsArray());
Object result;
try {
List<Object> subParams = params.subList(0, Math.min(invocation.getParametersAsArray().length,
cl.getMaximumNumberOfParameters()));
result = cl.call(subParams.toArray(new Object[subParams.size()]));
} catch (InvokerInvocationException e) {
throw e.getCause();
}
if (invocation.getInvokedMethod().getReturnType().isInstance(result)) {
return result;
}
return null;
}
});
}
示例7: getProperty
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
public Object getProperty(String name) throws MissingPropertyException {
if (!includeProperties) {
throw propertyMissingException(name);
}
MetaProperty property = getMetaClass().hasProperty(bean, name);
if (property == null) {
return getMetaClass().invokeMissingProperty(bean, name, null, true);
}
if (property instanceof MetaBeanProperty && ((MetaBeanProperty) property).getGetter() == null) {
throw new GroovyRuntimeException(String.format(
"Cannot get the value of write-only property '%s' on %s.", name, getDisplayName()));
}
try {
return property.getProperty(bean);
} catch (InvokerInvocationException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw e;
}
}
示例8: callClosure
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
public static Object callClosure(Closure closure, Object... args) {
try {
return closure.call(args);
} catch (InvokerInvocationException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException)e.getCause();
} else {
throw e;
}
}
}
示例9: setBeanProperty
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
private void setBeanProperty(Object newValue) {
try {
propertyAccessor().write(bean, propertyName, newValue);
} catch (InvokerInvocationException iie) {
if (!(iie.getCause() instanceof PropertyVetoException)) {
throw iie;
}
// ignore veto exceptions, just let the binding fail like a validation does
}
}
示例10: call
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
static <T> T call(Closure<T> closure, Object... args) {
try {
return closure.call(args);
} catch (InvokerInvocationException e) {
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
} else {
throw e;
}
}
}
示例11: invokeMethod
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
public Object invokeMethod(String name, Object args) {
try {
return InvokerHelper.invokeMethod(getResultSet(), name, args);
} catch (SQLException se) {
throw new InvokerInvocationException(se);
}
}
示例12: testChecksReflectPermissionForInvokeOnPrivateMethods
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
public void testChecksReflectPermissionForInvokeOnPrivateMethods() throws Exception {
cachedMethodUnderTest = createCachedMethod("privateMethod");
System.setSecurityManager(restrictiveSecurityManager);
try {
invokesCachedMethod();
fail();
}
catch (InvokerInvocationException e) {
assertEquals(CacheAccessControlException.class, e.getCause().getClass());
}
}
示例13: testNonLoop
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
public void testNonLoop() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
Parameter[] parameters = {new Parameter(ClassHelper.OBJECT_TYPE, "coll")};
Statement statement = createPrintlnStatement(new VariableExpression("coll"));
classNode.addMethod(new MethodNode("oneParamDemo", ACC_PUBLIC, ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));
Class fooClass = loadClass(classNode);
assertTrue("Loaded a new class", fooClass != null);
Object bean = fooClass.newInstance();
assertTrue("Managed to create bean", bean != null);
System.out.println("################ Now about to invoke a method without looping");
Object value = new Integer(10000);
try {
InvokerHelper.invokeMethod(bean, "oneParamDemo", new Object[]{value});
} catch (InvokerInvocationException e) {
System.out.println("Caught: " + e.getCause());
e.getCause().printStackTrace();
fail("Should not have thrown an exception");
}
System.out.println("################ Done");
}
示例14: testLoop
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
public void testLoop() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
Parameter[] parameters = {new Parameter(ClassHelper.OBJECT_TYPE.makeArray(), "coll")};
Statement loopStatement = createPrintlnStatement(new VariableExpression("i"));
ForStatement statement = new ForStatement(new Parameter(ClassHelper.OBJECT_TYPE, "i"), new VariableExpression("coll"), loopStatement);
classNode.addMethod(new MethodNode("iterateDemo", ACC_PUBLIC, ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));
Class fooClass = loadClass(classNode);
assertTrue("Loaded a new class", fooClass != null);
Object bean = fooClass.newInstance();
assertTrue("Managed to create bean", bean != null);
System.out.println("################ Now about to invoke a method with looping");
Object[] array = {new Integer(1234), "abc", "def"};
try {
InvokerHelper.invokeMethod(bean, "iterateDemo", new Object[]{array});
} catch (InvokerInvocationException e) {
System.out.println("Caught: " + e.getCause());
e.getCause().printStackTrace();
fail("Should not have thrown an exception");
}
System.out.println("################ Done");
}
示例15: testManyParam
import org.codehaus.groovy.runtime.InvokerInvocationException; //导入依赖的package包/类
public void testManyParam() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
Parameter[] parameters = {new Parameter(ClassHelper.OBJECT_TYPE, "coll1"), new Parameter(ClassHelper.OBJECT_TYPE, "coll2"), new Parameter(ClassHelper.OBJECT_TYPE, "coll3")};
BlockStatement statement = new BlockStatement();
statement.addStatement(createPrintlnStatement(new VariableExpression("coll1")));
statement.addStatement(createPrintlnStatement(new VariableExpression("coll2")));
statement.addStatement(createPrintlnStatement(new VariableExpression("coll3")));
classNode.addMethod(new MethodNode("manyParamDemo", ACC_PUBLIC, ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));
Class fooClass = loadClass(classNode);
assertTrue("Loaded a new class", fooClass != null);
Object bean = fooClass.newInstance();
assertTrue("Managed to create bean", bean != null);
System.out.println("################ Now about to invoke a method with many parameters");
Object[] array = {new Integer(1000 * 1000), "foo-", "bar~"};
try {
InvokerHelper.invokeMethod(bean, "manyParamDemo", array);
} catch (InvokerInvocationException e) {
System.out.println("Caught: " + e.getCause());
e.getCause().printStackTrace();
fail("Should not have thrown an exception");
}
System.out.println("################ Done");
}