List of usage examples for java.lang.reflect InvocationTargetException getCause
public Throwable getCause()
From source file:rb.app.RBBase.java
/** * Set the Q_a variable from the mTheta object. *//* w w w .j a v a2s . com*/ protected void read_in_Q_a() { Method meth; try { // Get a reference to get_n_A_functions, which does not // take any arguments meth = mAffineFnsClass.getMethod("get_n_A_functions", null); } catch (NoSuchMethodException nsme) { throw new RuntimeException("getMethod for get_n_A_functions failed", nsme); } Integer Q_a; try { Object Q_a_obj = meth.invoke(mTheta, null); Q_a = (Integer) Q_a_obj; } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite.getCause()); } mQ_a = Q_a.intValue(); }
From source file:org.xenmaster.web.Hook.java
protected void parseAndExecuteMethod(Method m, Object[] args) throws Exception { Class<?>[] types = m.getParameterTypes(); // Check method signature if ((types != null && types.length != 0) && ((types.length > 0 && args == null) || (types.length != args.length))) { Logger.getLogger(getClass()).info("Hook call made with incorrect number of arguments: " + commandName); current = new CommandException("Illegal number of arguments in " + m.getName() + " call", commandName); } else if (args != null) { for (int j = 0; j < types.length; j++) { Class<?> type = types[j]; Object value = args[j]; if (value == null) { throw new IllegalArgumentException( "An argument for " + clazz.getSimpleName() + '.' + m.getName() + " was null"); } else if (value instanceof String) { String str = value.toString(); if (str.startsWith("LocalRef:")) { Integer localRef = Integer.parseInt(str.substring(str.indexOf(":") + 1)); if (!store.containsKey(localRef)) { current = new CommandException("Local object reference does not exist", commandName); }//from w w w . j av a 2 s . c o m args[j] = store.get(localRef).value; } else { args[j] = APIUtil.deserializeToTargetType(value, type); } } else { args[j] = APIUtil.deserializeToTargetType(value, type); } } } try { if (Modifier.isStatic(m.getModifiers())) { current = m.invoke(null, args); } else { if (current == null) { throw new IllegalArgumentException("Instance method called as a static method."); } m.setAccessible(true); current = m.invoke(current, args); } } catch (InvocationTargetException ex) { // If it has a cause, it will be parsed by the next handler if (ex.getCause() == null) { Logger.getLogger(getClass()).info("Failed to invoke method", ex); current = new CommandException(ex, commandName); } else { Logger.getLogger(getClass()).info("Hook call threw Exception", ex.getCause()); if (ex.getCause() instanceof BadAPICallException) { current = new DetailedCommandException(commandName, ((BadAPICallException) ex.getCause())); } else { current = new CommandException(ex.getCause(), commandName); } } } }
From source file:org.apache.tapestry5.internal.spring.SpringModuleDef.java
private ContributionDef createContributionToMasterObjectProvider() { return new AbstractContributionDef() { @Override/* w w w. j a v a2s .c o m*/ public String getServiceId() { return "MasterObjectProvider"; } @Override public void contribute(ModuleBuilderSource moduleSource, ServiceResources resources, OrderedConfiguration configuration) { final OperationTracker tracker = resources.getTracker(); final ApplicationContext context = resources.getService(SERVICE_ID, ApplicationContext.class); //region CUSTOMIZATION final ObjectProvider springBeanProvider = new ObjectProvider() { public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) { try { T bean = context.getBean(objectType); if (!objectType.isInterface()) { return bean; } // We proxify here because Tapestry calls toString method on proxy, which realizes the underlying service, with scope issues return (T) Proxy.newProxyInstance(objectType.getClassLoader(), new Class<?>[] { objectType }, new AbstractInvocationHandler() { @Override protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if (methodName.equals("equals")) { // Only consider equal when proxies are identical. return (proxy == args[0]); } if (methodName.equals("hashCode")) { // Use hashCode of proxy. return System.identityHashCode(proxy); } if (methodName.equals("toString")) { return "Current Spring " + objectType.getSimpleName(); } try { return method.invoke(bean, args); } catch (InvocationTargetException e) { throw e.getCause(); } } }); } catch (NoUniqueBeanDefinitionException e) { String message = String.format( "Spring context contains %d beans assignable to type %s.", e.getNumberOfBeansFound(), PlasticUtils.toTypeName(objectType)); throw new IllegalArgumentException(message, e); } catch (NoSuchBeanDefinitionException e) { return null; } } }; //endregion final ObjectProvider springBeanProviderInvoker = new ObjectProvider() { @Override public <T> T provide(final Class<T> objectType, final AnnotationProvider annotationProvider, final ObjectLocator locator) { return tracker.invoke("Resolving dependency by searching Spring ApplicationContext", () -> springBeanProvider.provide(objectType, annotationProvider, locator)); } }; ObjectProvider outerCheck = new ObjectProvider() { @Override public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) { // I think the following line is the only reason we put the // SpringBeanProvider here, // rather than in SpringModule. if (!applicationContextCreated.get()) return null; return springBeanProviderInvoker.provide(objectType, annotationProvider, locator); } }; configuration.add("SpringBean", outerCheck, "after:AnnotationBasedContributions", "after:ServiceOverride"); } }; }
From source file:rb.app.RBBase.java
public float[] mesh_transform(double[] mu, float[] x) { Method meth;/* w w w . ja va2s. co m*/ try { // Get a reference to get_n_L_functions, which does not // take any arguments Class partypes[] = new Class[2]; partypes[0] = double[].class; partypes[1] = float[].class; meth = mAffineFnsClass.getMethod("mesh_transform", partypes); } catch (NoSuchMethodException nsme) { throw new RuntimeException("getMethod for mesh_transform failed", nsme); } float[] xt; try { Object arglist[] = new Object[2]; arglist[0] = mu; arglist[1] = x; Object theta_obj = meth.invoke(mTheta, arglist); xt = (float[]) theta_obj; } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite.getCause()); } return xt; }
From source file:rb.app.RBBase.java
/** * Evaluate theta_q_a (for the q^th bilinear form) at the current parameter. *///from ww w . j a v a 2 s .c o m public double eval_theta_q_a(int q) { Method meth; try { // Get a reference to get_n_L_functions, which does not // take any arguments Class partypes[] = new Class[2]; partypes[0] = Integer.TYPE; partypes[1] = double[].class; meth = mAffineFnsClass.getMethod("evaluateA", partypes); } catch (NoSuchMethodException nsme) { throw new RuntimeException("getMethod for evaluateA failed", nsme); } Double theta_val; try { Object arglist[] = new Object[2]; arglist[0] = new Integer(q); arglist[1] = current_parameters.getArray(); Object theta_obj = meth.invoke(mTheta, arglist); theta_val = (Double) theta_obj; } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite.getCause()); } return theta_val.doubleValue(); }
From source file:rb.app.RBBase.java
public FieldVector<Complex> complex_eval_theta_q_a() { Method meth;/*from ww w .j ava 2 s. com*/ //Complex c; try { // Get a reference to get_n_L_functions, which does not // take any arguments Class partypes[] = new Class[1]; partypes[0] = double[].class; meth = mAffineFnsClass.getMethod("evaluateA_array", partypes); } catch (NoSuchMethodException nsme) { FieldVector<Complex> c = new ArrayFieldVector<Complex>(mQ_a, new Complex(0d, 0d)); for (int i = 0; i < mQ_a; i++) c.setEntry(i, complex_eval_theta_q_a(i)); return c; //throw new RuntimeException("getMethod for evaluateA failed", nsme); } double[][] theta_val; try { Object arglist[] = new Object[1]; arglist[0] = current_parameters.getArray(); Object theta_obj = meth.invoke(mTheta, arglist); theta_val = (double[][]) theta_obj; } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite.getCause()); } FieldVector<Complex> c = new ArrayFieldVector<Complex>(mQ_a, new Complex(0d, 0d)); for (int i = 0; i < mQ_a; i++) c.setEntry(i, new Complex(theta_val[i][0], theta_val[i][1])); return c; }
From source file:org.ff4j.aop.FeatureAdvisor.java
private Object callAlterBeanMethod(final MethodInvocation pMInvoc, String alterBean, Logger targetLogger) throws Throwable { Method method = pMInvoc.getMethod(); targetLogger.debug("FeatureFlipping on method:{} class:{}", method.getName(), method.getDeclaringClass().getName()); // invoke same method (interface) with another spring bean (ff.alterBean()) try {/*w w w.ja v a 2 s . c om*/ return method.invoke(appCtx.getBean(alterBean, method.getDeclaringClass()), pMInvoc.getArguments()); } catch (InvocationTargetException invocationTargetException) { if (!ff4j.isAlterBeanThrowInvocationTargetException() && invocationTargetException.getCause() != null) { throw invocationTargetException.getCause(); } throw makeIllegalArgumentException( "ff4j-aop: Cannot invoke method " + method.getName() + " on bean " + alterBean, invocationTargetException); } catch (Exception exception) { throw makeIllegalArgumentException( "ff4j-aop: Cannot invoke method " + method.getName() + " on bean " + alterBean, exception); } }
From source file:rb.app.RBBase.java
public Complex complex_eval_theta_q_a(int q) { Method meth;/*from w w w . j av a 2 s. c o m*/ //Complex c; try { // Get a reference to get_n_L_functions, which does not // take any arguments Class partypes[] = new Class[3]; partypes[0] = Integer.TYPE; partypes[1] = double[].class; partypes[2] = boolean.class; meth = mAffineFnsClass.getMethod("evaluateA", partypes); } catch (NoSuchMethodException nsme) { throw new RuntimeException("getMethod for evaluateA failed", nsme); } Double theta_val_r, theta_val_i; try { Object arglist[] = new Object[3]; arglist[0] = new Integer(q); arglist[1] = current_parameters.getArray(); arglist[2] = true; Object theta_obj = meth.invoke(mTheta, arglist); theta_val_r = (Double) theta_obj; arglist[2] = false; theta_val_i = (Double) meth.invoke(mTheta, arglist); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite.getCause()); } Complex c = new Complex(theta_val_r.doubleValue(), theta_val_i.doubleValue()); return c; }
From source file:rb.app.RBBase.java
public Complex complex_eval_theta_q_f(int q) { Method meth;/*from w w w . ja va 2s . c o m*/ //Complex c; try { // Get a reference to get_n_L_functions, which does not // take any arguments Class partypes[] = new Class[3]; partypes[0] = Integer.TYPE; partypes[1] = double[].class; partypes[2] = boolean.class; meth = mAffineFnsClass.getMethod("evaluateF", partypes); } catch (NoSuchMethodException nsme) { throw new RuntimeException("getMethod for evaluateF failed", nsme); } Double theta_val_r, theta_val_i; try { Object arglist[] = new Object[3]; arglist[0] = new Integer(q); arglist[1] = current_parameters.getArray(); arglist[2] = true; Object theta_obj = meth.invoke(mTheta, arglist); theta_val_r = (Double) theta_obj; arglist[2] = false; theta_val_i = (Double) meth.invoke(mTheta, arglist); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite.getCause()); } Complex c = new Complex(theta_val_r.doubleValue(), theta_val_i.doubleValue()); return c; }
From source file:org.ff4j.aop.FeatureAdvisor.java
private Object callAlterClazzMethod(final MethodInvocation pMInvoc, Object targetBean, Logger targetLogger) throws Throwable { Method method = pMInvoc.getMethod(); String declaringClass = method.getDeclaringClass().getName(); targetLogger.debug("FeatureFlipping on method:{} class:{}", method.getName(), declaringClass); try {// w w w. j a va 2 s . co m return method.invoke(targetBean, pMInvoc.getArguments()); } catch (IllegalAccessException e) { throw makeIllegalArgumentException("ff4j-aop: Cannot invoke " + method.getName() + " on alterbean " + declaringClass + " please check visibility", e); } catch (InvocationTargetException invocationTargetException) { if (!ff4j.isAlterBeanThrowInvocationTargetException() && invocationTargetException.getCause() != null) { throw invocationTargetException.getCause(); } throw makeIllegalArgumentException("ff4j-aop: Cannot invoke " + method.getName() + " on alterbean " + declaringClass + " please check signatures", invocationTargetException); } catch (Exception exception) { throw makeIllegalArgumentException("ff4j-aop: Cannot invoke " + method.getName() + " on alterbean " + declaringClass + " please check signatures", exception); } }