public static Object invokeService(Object bean, String serviceName, Object... args) throws ApplicationServiceException { try { Constructor constructor = findConstructor(serviceName, args); Object object = constructor.newInstance(args); if (object instanceof ApplicationService) { ApplicationService service = (ApplicationService) object; // Prepare Context ApplicationServiceContext context = new ApplicationServiceContext(bean); service.setContext(context); service.process(); if (context.getResult() != null) { System.out.println("service:" + serviceName + " returns value:" + context.getResult()); return context.getResult(); } } } catch (ApplicationServiceException ex) { Logger.getLogger(ApplicationServiceBus.class.getName()).log(Level.SEVERE, null, ex); throw ex; } catch (Exception ex) { Logger.getLogger(ApplicationServiceBus.class.getName()).log(Level.SEVERE, null, ex); throw new ApplicationServiceException("", ex); } return null; }