/** {@inheritDoc} */ @Override public <T extends Object> void returnData(final Wave sourceWave) { try { // Build parameter list of the searched method final List<Object> parameterValues = new ArrayList<>(); for (final WaveData<?> wd : sourceWave.getWaveItems()) { parameterValues.add(wd.getValue()); } // Add the current wave to process // parameterValues.add(wave); if (sourceWave.getWaveType() == null) { LOGGER.error( "Wave processed without any wave type for service " + this.getClass().getSimpleName()); } // Search the wave handler method final Method method = ClassUtility.getMethodByName( this.getClass(), ClassUtility.underscoreToCamelCase(sourceWave.getWaveType().toString())); if (method != null) { // final Class<T> returnClass = (Class<T>) method.getReturnType(); runTask(sourceWave, method, parameterValues.toArray()); } } catch (final NoSuchMethodException e) { // If no method was found, call the default method processAction(sourceWave); } }
/** {@inheritDoc} */ @Override public void handle(final Wave wave) throws WaveException { try { // Build parameter list of the searched method final List<Object> parameterValues = new ArrayList<>(); for (final WaveData<?> wd : wave.getWaveItems()) { parameterValues.add(wd.getValue()); } // Add the current wave to process parameterValues.add(wave); // Search the wave handler method final Method method = ClassUtility.getMethodByName(this.getClass(), wave.getWaveType().getAction()); if (method != null) { // Call this method with right parameters method.invoke(this, parameterValues.toArray()); } } catch (final NoSuchMethodException e) { // If no method was found, call the default method processAction(wave); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // Propagate the wave exception throw new WaveException(wave, e); } }