SpringServiceManager implements ServiceManagerSystem { @SuppressWarnings("unchecked") @Override public <T> List<T> getServicesByType(Class<T> type) { ArrayList<T> l = new ArrayList<T>(); Map<String, T> beans; try { beans = applicationContext.getBeansOfType(type, true, true); l.addAll( (Collection<? extends T>) beans.values() ); } catch (BeansException e) { throw new RuntimeException("Failed to get beans of type ("+type+"): " + e.getMessage(), e); } return l; } SpringServiceManager(ServiceManagerSystem parent, DSpaceConfigurationService configurationService, boolean testMode, boolean developmentMode, String... configPaths); ClassPathXmlApplicationContext getApplicationContext(); ListableBeanFactory getBeanFactory(); @SuppressWarnings("unchecked") @Override T getServiceByName(String name, Class<T> type); @SuppressWarnings("unchecked") @Override List<T> getServicesByType(Class<T> type); @Override void shutdown(); @Override void startup(); @SuppressWarnings("unchecked") @Override T registerServiceClass(String name, Class<T> type); @Override void registerService(String name, Object service); @Override void registerServiceNoAutowire(String name, Object service); @Override void unregisterService(String name); @Override List<String> getServicesNames(); @Override boolean isServiceExists(String name); @Override Map<String, Object> getServices(); @Override void pushConfig(Map<String, Object> settings); static final String configPath; static final String coreResourcePath; static final String addonResourcePath; }
@Test public void testGetServicesByType() { ssm.startup(); List<ConcreteExample> l = ssm.getServicesByType(ConcreteExample.class); assertNotNull(l); assertEquals(1, l.size()); assertEquals("azeckoski", l.get(0).getName()); l = null; List<SampleAnnotationBean> l2 = ssm.getServicesByType(SampleAnnotationBean.class); assertNotNull(l2); assertEquals(1, l2.size()); l2 = null; }