List of usage examples for java.lang.reflect InvocationTargetException getCause
public Throwable getCause()
From source file:com.chiorichan.event.EventBus.java
public Map<Class<? extends Event>, Set<RegisteredListener>> createRegisteredListeners(Listener listener, final EventCreator plugin) { Validate.notNull(plugin, "Creator can not be null"); Validate.notNull(listener, "Listener can not be null"); Map<Class<? extends Event>, Set<RegisteredListener>> ret = new HashMap<Class<? extends Event>, Set<RegisteredListener>>(); Set<Method> methods; try {/*from w w w . j a va 2 s . c om*/ Method[] publicMethods = listener.getClass().getMethods(); methods = new HashSet<Method>(publicMethods.length, Float.MAX_VALUE); for (Method method : publicMethods) { methods.add(method); } for (Method method : listener.getClass().getDeclaredMethods()) { methods.add(method); } } catch (NoClassDefFoundError e) { Loader.getLogger() .severe("Plugin " + plugin.getDescription().getFullName() + " has failed to register events for " + listener.getClass() + " because " + e.getMessage() + " does not exist."); return ret; } for (final Method method : methods) { final EventHandler eh = method.getAnnotation(EventHandler.class); if (eh == null) continue; final Class<?> checkClass; if (method.getParameterTypes().length != 1 || !Event.class.isAssignableFrom(checkClass = method.getParameterTypes()[0])) { Loader.getLogger() .severe(plugin.getDescription().getFullName() + " attempted to register an invalid EventHandler method signature \"" + method.toGenericString() + "\" in " + listener.getClass()); continue; } final Class<? extends Event> eventClass = checkClass.asSubclass(Event.class); method.setAccessible(true); Set<RegisteredListener> eventSet = ret.get(eventClass); if (eventSet == null) { eventSet = new HashSet<RegisteredListener>(); ret.put(eventClass, eventSet); } for (Class<?> clazz = eventClass; Event.class.isAssignableFrom(clazz); clazz = clazz.getSuperclass()) { // This loop checks for extending deprecated events if (clazz.getAnnotation(Deprecated.class) != null) { Warning warning = clazz.getAnnotation(Warning.class); WarningState warningState = Loader.getInstance().getWarningState(); if (!warningState.printFor(warning)) { break; } Loader.getLogger().log(Level.WARNING, String.format( "\"%s\" has registered a listener for %s on method \"%s\", but the event is Deprecated." + " \"%s\"; please notify the authors %s.", plugin.getDescription().getFullName(), clazz.getName(), method.toGenericString(), (warning != null && warning.reason().length() != 0) ? warning.reason() : "Server performance will be affected", Arrays.toString(plugin.getDescription().getAuthors().toArray())), warningState == WarningState.ON ? new AuthorNagException(null) : null); break; } } EventExecutor executor = new EventExecutor() { public void execute(Listener listener, Event event) throws EventException { try { if (!eventClass.isAssignableFrom(event.getClass())) { return; } method.invoke(listener, event); } catch (InvocationTargetException ex) { throw new EventException(ex.getCause()); } catch (Throwable t) { throw new EventException(t); } } }; if (useTimings) { eventSet.add(new TimedRegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled())); } else { eventSet.add( new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled())); } } return ret; }
From source file:com.litemvc.LiteMvcFilter.java
@SuppressWarnings("unchecked") private boolean tryToExecuteMethod(HttpServletRequest request, HttpServletResponse response, Matcher matcher, Binding binding, Object handler) throws Exception { Method[] methods = binding.getHandlerClass().getMethods(); for (Method method : methods) { if (isMappedMethod(request, method, binding)) { Class<?>[] parmTypes = method.getParameterTypes(); int matchCount = 1; ArrayList<Object> args = new ArrayList<Object>(); for (Class<?> clazz : parmTypes) { if (clazz.equals(HttpServletRequest.class)) { args.add(request);/*from ww w . j a va 2 s. c o m*/ } if (clazz.equals(HttpServletResponse.class)) { args.add(response); } if (clazz.equals(String.class)) { args.add(matcher.group(matchCount)); matchCount++; } } for (Object oParmName : request.getParameterMap().keySet()) { String parmName = (String) oParmName; if (PropertyUtils.isWriteable(handler, parmName)) { BeanUtils.setProperty(handler, parmName, request.getParameter(parmName)); } } boolean isError = false; String result = null; try { result = (String) method.invoke(handler, args.toArray()); } catch (Exception e) { Throwable cause = e; if (e instanceof InvocationTargetException) { InvocationTargetException ite = (InvocationTargetException) e; cause = ite.getCause(); } if (exceptionsMap.containsKey(cause.getClass())) { result = exceptionsMap.get(cause.getClass()); isError = true; } else { throw e; } } if (result == null) { return true; } Action action = null; if (!isError) { // we only check global results in case of an error. action = binding.getAction(result); } if (action == null) { action = globalResults.get(result); } if (action == null) { throw new UnmappedResultException(result, isError); } if (action instanceof TemplateAction) { TemplateAction templateAction = (TemplateAction) action; String templateName = templateAction.getTemplateName(); if (templateAction.isEvaluate()) { JexlContext jc = JexlHelper.createContext(); jc.getVars().put("handler", handler); templateName = "" + templateAction.getExpression().evaluate(jc); } processTemplate(request, response, templateName, handler); return true; } if (action instanceof DispatcherAction) { request.setAttribute("handler", handler); DispatcherAction location = (DispatcherAction) action; request.getRequestDispatcher(location.getLocation()).forward(request, response); return true; } if (action instanceof RedirectAction) { RedirectAction redirectAction = (RedirectAction) action; String location = redirectAction.getLocation(); if (redirectAction.isEvaluate()) { JexlContext jc = JexlHelper.createContext(); jc.getVars().put("handler", handler); location = "" + redirectAction.getExpression().evaluate(jc); } response.sendRedirect(location); return true; } if (!customActionProcessor(binding, request, response, action)) { throw new RuntimeException("unkown action type: " + action.getClass().getName()); } return true; } } return false; }
From source file:org.eclipse.jubula.client.ui.rcp.handlers.project.SaveProjectAsHandler.java
/** * {@inheritDoc}/*from www. ja va 2s. c om*/ */ public Object executeImpl(ExecutionEvent event) { VersionDialog dialog = openInputDialog(); if (dialog.getReturnCode() == Window.OK) { final String newProjectName = dialog.getProjectName(); IRunnableWithProgress op = createOperation(newProjectName, dialog.getProjectVersion()); try { PlatformUI.getWorkbench().getProgressService().busyCursorWhile(op); fireReady(); } catch (InvocationTargetException ite) { // Exception occurred during operation log.error(ite.getLocalizedMessage(), ite.getCause()); } catch (InterruptedException e) { // Operation was canceled. // We have to clear the GUI because all of // the save work was done in the Master Session, which has been // rolled back. Utils.clearClient(); } } return null; }
From source file:annis.AnnisBaseRunner.java
protected void runCommand(String command, String args) { String methodName = "do" + command.substring(0, 1).toUpperCase() + command.substring(1); log.debug("looking for: " + methodName); try {//from w w w . j a v a 2 s.c o m long start = new Date().getTime(); Method commandMethod = getClass().getMethod(methodName, String.class); commandMethod.invoke(this, args); System.out.println("Time: " + (new Date().getTime() - start) + " ms"); if (history != null) { history.flush(); } } catch (InvocationTargetException e) { // FIXME: Exception-Handling is all over the place (refactor into a handleException method) Throwable cause = e.getCause(); try { throw cause; } catch (AnnisQLSyntaxException ee) { error(ee.getMessage()); } catch (Throwable ee) { log.error("Uncaught exception: ", ee); error("Uncaught Exception: " + ee.getMessage()); } } catch (IllegalAccessException e) { log.error("BUG: IllegalAccessException should never be thrown", e); throw new AnnisRunnerException("BUG: can't access method: " + methodName, e); } catch (SecurityException e) { log.error("BUG: SecurityException should never be thrown", e); error(e); } catch (NoSuchMethodException e) { throw new UsageException("don't know how to do: " + command); } catch (IOException e) { log.error("IOException was thrown", e); } }
From source file:com.runwaysdk.controller.ServletDispatcher.java
/** * Invokes the failure method of the given action for the given controller. * //from w ww . j a v a 2s. c o m * @param actionName * @param baseClass * @param controllerClass * @param controller * @param objects * * @throws IllegalAccessException * @throws NoSuchMethodException * @throws IOException */ private void dispatchFailure(String actionName, Class<?> baseClass, Class<?> controllerClass, Object controller, Object[] objects) throws IllegalAccessException, NoSuchMethodException, IOException { try { String failureName = "fail" + CommonGenerationUtil.upperFirstCharacter(actionName); Method failureBase = RequestScraper.getMethod(failureName, baseClass); controllerClass.getMethod(failureName, ((Class[]) failureBase.getParameterTypes())).invoke(controller, objects); } catch (InvocationTargetException e) { if (e.getCause() instanceof UndefinedControllerActionException) { throw (UndefinedControllerActionException) e.getCause(); } this.handleInvocationTargetException(e); } }
From source file:de.thkwalter.et.ortskurve.StartpunktbestimmungTest.java
/** * Test fr die Methode {@link Startpunktbestimmung#startpunktBestimmen()}. * //from ww w .j a v a 2 s .c o m * @throws ApplicationRuntimeException * @throws NoSuchMethodException * @throws SecurityException * @throws InvocationTargetException * @throws IllegalAccessException * @throws IllegalArgumentException */ @Test(expected = ApplicationRuntimeException.class) public void testStartpunktBestimmen2() throws Throwable { Vector2D[] messpunkteZurStartpunktbestimmung = new Vector2D[] { new Vector2D(1.0, 0.0), new Vector2D(2.0, 0.0), new Vector2D(3.0, 0.0) }; // Die zu testende Methode wird aufgerufen Method methode = Startpunktbestimmung.class.getDeclaredMethod("startpunktBestimmen", Vector2D[].class); methode.setAccessible(true); try { methode.invoke(Startpunktbestimmung.class, (Object) messpunkteZurStartpunktbestimmung); } catch (InvocationTargetException invocationTargetException) { throw invocationTargetException.getCause(); } }
From source file:com.amazon.carbonado.repo.jdbc.OracleSupportStrategy.java
/** * @return original blob if too large and post-insert update is required, null otherwise * @throws PersistException instead of FetchException since this code is * called during an insert operation/*from ww w . j a v a 2s.co m*/ */ @Override com.amazon.carbonado.lob.Blob setBlobValue(PreparedStatement ps, int column, com.amazon.carbonado.lob.Blob blob) throws PersistException { try { long length = blob.getLength(); if (length > BLOB_CHUNK_LIMIT || ((long) ((int) length)) != length) { if (mBLOB_empty_lob == null) { return super.setBlobValue(ps, column, blob); } try { ps.setBlob(column, (java.sql.Blob) mBLOB_empty_lob.invoke(null)); return blob; } catch (InvocationTargetException e) { throw mRepo.toPersistException(e.getCause()); } catch (Exception e) { throw mRepo.toPersistException(e); } } if (blob instanceof OracleBlob) { ps.setBlob(column, ((OracleBlob) blob).getInternalBlobForPersist()); return null; } ps.setBinaryStream(column, blob.openInputStream(), (int) length); return null; } catch (SQLException e) { throw mRepo.toPersistException(e); } catch (FetchException e) { throw e.toPersistException(); } }
From source file:com.amazon.carbonado.repo.jdbc.OracleSupportStrategy.java
/** * @return original clob if too large and post-insert update is required, null otherwise *///from ww w.ja v a2s. c o m @Override com.amazon.carbonado.lob.Clob setClobValue(PreparedStatement ps, int column, com.amazon.carbonado.lob.Clob clob) throws PersistException { try { long length = clob.getLength(); if (length > CLOB_CHUNK_LIMIT || ((long) ((int) length)) != length) { if (mCLOB_empty_lob == null) { return super.setClobValue(ps, column, clob); } try { ps.setClob(column, (java.sql.Clob) mCLOB_empty_lob.invoke(null)); return clob; } catch (InvocationTargetException e) { throw mRepo.toPersistException(e.getCause()); } catch (Exception e) { throw mRepo.toPersistException(e); } } if (clob instanceof OracleClob) { ps.setClob(column, ((OracleClob) clob).getInternalClobForPersist()); return null; } ps.setCharacterStream(column, clob.openReader(), (int) length); return null; } catch (SQLException e) { throw mRepo.toPersistException(e); } catch (FetchException e) { throw e.toPersistException(); } }
From source file:org.sonatype.nexus.test.booter.Jetty7NexusBooter.java
/** * Stops, and cleans up the started Nexus instance. May be invoked any times, it will NOOP if not needed to do * anything. Will try to ditch the used classloader. The {@link #clean()} method will be invoked on every invocation * of this method, making it more plausible for JVM to recover/GC all the stuff from memory in case of any glitch. * // ww w. ja v a2s .c o m * @throws Exception */ public void stopNexus() throws Exception { try { if (jetty7 != null) { jetty7.getClass().getMethod("stopJetty").invoke(jetty7); } } catch (InvocationTargetException e) { if (e.getCause() instanceof IllegalStateException) { // swallow it, it is Jetty7 that throws this when we stop but did not start... } else { throw (Exception) e.getCause(); } } finally { clean(); } }
From source file:rb.app.RBBase.java
public boolean is_custom_mesh_transform() { Method meth;/*from w ww .java 2s . c om*/ try { Class partypes[] = null; meth = mAffineFnsClass.getMethod("is_custom_mesh_transform", partypes); } catch (NoSuchMethodException nsme) { return false; } try { Object arglist[] = null; Object theta_obj = meth.invoke(mTheta, arglist); boolean val = (Boolean) theta_obj; return val; } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite.getCause()); } }