@Test public void testGetServiceByName() { configurationService.clear(); dsm.startup(); ConcreteExample concrete = dsm.getServiceByName(ConcreteExample.class.getName(), ConcreteExample.class); assertNotNull(concrete); assertEquals("azeckoski", concrete.getName()); concrete = null; SampleAnnotationBean sab = dsm .getServiceByName(SampleAnnotationBean.class.getName(), SampleAnnotationBean.class); assertNotNull(sab); assertEquals(null, sab.getSampleValue()); sab = null; }
@SuppressWarnings("unchecked") @Override public <T> T getServiceByName(String name, Class<T> type) { checkRunning(); if (type == null) { throw new IllegalArgumentException("Type cannot be null"); } T service = null; if (ApplicationContext.class.getName().equals(name) && ApplicationContext.class.isAssignableFrom(type)) { service = (T) getApplicationContext(); } else { if (name != null) { try { service = (T) applicationContext.getBean(name, type); } catch (BeansException e) { log.info( "Unable to locate bean by name or id={}." + " Will try to look up bean by type next." + " BeansException: {}", name, e.getMessage()); service = null; } } else { try { service = (T) applicationContext.getBean(type.getName(), type); } catch (BeansException e) { log.info("Unable to locate bean by name or id={}." + " Will try to look up bean by type next." + " BeansException: {}", type.getName(), e.getMessage()); service = null; } } if (name == null && service == null) { try { Map<String, T> map = applicationContext.getBeansOfType(type); if (map.size() == 1) { service = (T) map.values().iterator().next(); } else { log.error("Multiple beans of type {} found. Only one was expected!", type.getName()); } } catch (BeansException e) { log.error(e.getMessage(), e); service = null; } } } return service; }
DSpaceServiceManager implements ServiceManagerSystem { @SuppressWarnings("unchecked") @Override public <T> T getServiceByName(String name, Class<T> type) { checkRunning(); if (type == null) { throw new IllegalArgumentException("Type cannot be null"); } T service = null; if (ApplicationContext.class.getName().equals(name) && ApplicationContext.class.isAssignableFrom(type)) { service = (T) getApplicationContext(); } else { if (name != null) { try { service = (T) applicationContext.getBean(name, type); } catch (BeansException e) { log.info( "Unable to locate bean by name or id={}." + " Will try to look up bean by type next." + " BeansException: {}", name, e.getMessage()); service = null; } } else { try { service = (T) applicationContext.getBean(type.getName(), type); } catch (BeansException e) { log.info("Unable to locate bean by name or id={}." + " Will try to look up bean by type next." + " BeansException: {}", type.getName(), e.getMessage()); service = null; } } if (name == null && service == null) { try { Map<String, T> map = applicationContext.getBeansOfType(type); if (map.size() == 1) { service = (T) map.values().iterator().next(); } else { log.error("Multiple beans of type {} found. Only one was expected!", type.getName()); } } catch (BeansException e) { log.error(e.getMessage(), e); service = null; } } } return service; } }
DSpaceServiceManager implements ServiceManagerSystem { @SuppressWarnings("unchecked") @Override public <T> T getServiceByName(String name, Class<T> type) { checkRunning(); if (type == null) { throw new IllegalArgumentException("Type cannot be null"); } T service = null; if (ApplicationContext.class.getName().equals(name) && ApplicationContext.class.isAssignableFrom(type)) { service = (T) getApplicationContext(); } else { if (name != null) { try { service = (T) applicationContext.getBean(name, type); } catch (BeansException e) { log.info( "Unable to locate bean by name or id={}." + " Will try to look up bean by type next." + " BeansException: {}", name, e.getMessage()); service = null; } } else { try { service = (T) applicationContext.getBean(type.getName(), type); } catch (BeansException e) { log.info("Unable to locate bean by name or id={}." + " Will try to look up bean by type next." + " BeansException: {}", type.getName(), e.getMessage()); service = null; } } if (name == null && service == null) { try { Map<String, T> map = applicationContext.getBeansOfType(type); if (map.size() == 1) { service = (T) map.values().iterator().next(); } else { log.error("Multiple beans of type {} found. Only one was expected!", type.getName()); } } catch (BeansException e) { log.error(e.getMessage(), e); service = null; } } } return service; } DSpaceServiceManager(DSpaceConfigurationService configurationService); protected  DSpaceServiceManager(DSpaceConfigurationService configurationService,
            String... springXmlConfigFiles); }
DSpaceServiceManager implements ServiceManagerSystem { @SuppressWarnings("unchecked") @Override public <T> T getServiceByName(String name, Class<T> type) { checkRunning(); if (type == null) { throw new IllegalArgumentException("Type cannot be null"); } T service = null; if (ApplicationContext.class.getName().equals(name) && ApplicationContext.class.isAssignableFrom(type)) { service = (T) getApplicationContext(); } else { if (name != null) { try { service = (T) applicationContext.getBean(name, type); } catch (BeansException e) { log.info( "Unable to locate bean by name or id={}." + " Will try to look up bean by type next." + " BeansException: {}", name, e.getMessage()); service = null; } } else { try { service = (T) applicationContext.getBean(type.getName(), type); } catch (BeansException e) { log.info("Unable to locate bean by name or id={}." + " Will try to look up bean by type next." + " BeansException: {}", type.getName(), e.getMessage()); service = null; } } if (name == null && service == null) { try { Map<String, T> map = applicationContext.getBeansOfType(type); if (map.size() == 1) { service = (T) map.values().iterator().next(); } else { log.error("Multiple beans of type {} found. Only one was expected!", type.getName()); } } catch (BeansException e) { log.error(e.getMessage(), e); service = null; } } } return service; } DSpaceServiceManager(DSpaceConfigurationService configurationService); protected  DSpaceServiceManager(DSpaceConfigurationService configurationService,
            String... springXmlConfigFiles); boolean isRunning(); ListableBeanFactory getBeanFactory(); @Override ClassPathXmlApplicationContext getApplicationContext(); void notifyServiceManagerReady(); @Override void shutdown(); @Override void startup(); @Override void registerService(String name, Object service); @Override void registerServiceNoAutowire(String name, Object service); @SuppressWarnings("unchecked") @Override T registerServiceClass(String name, Class<T> type); @Override void unregisterService(String name); @SuppressWarnings("unchecked") @Override T getServiceByName(String name, Class<T> type); @SuppressWarnings("unchecked") @Override List<T> getServicesByType(Class<T> type); @Override List<String> getServicesNames(); @Override boolean isServiceExists(String name); @Override Map<String, Object> getServices(); @Override void pushConfig(Map<String, Object> properties); static String[] getSpringPaths(boolean testMode, String[] configPaths,
                                          DSpaceConfigurationService configurationService); }
DSpaceServiceManager implements ServiceManagerSystem { @SuppressWarnings("unchecked") @Override public <T> T getServiceByName(String name, Class<T> type) { checkRunning(); if (type == null) { throw new IllegalArgumentException("Type cannot be null"); } T service = null; if (ApplicationContext.class.getName().equals(name) && ApplicationContext.class.isAssignableFrom(type)) { service = (T) getApplicationContext(); } else { if (name != null) { try { service = (T) applicationContext.getBean(name, type); } catch (BeansException e) { log.info( "Unable to locate bean by name or id={}." + " Will try to look up bean by type next." + " BeansException: {}", name, e.getMessage()); service = null; } } else { try { service = (T) applicationContext.getBean(type.getName(), type); } catch (BeansException e) { log.info("Unable to locate bean by name or id={}." + " Will try to look up bean by type next." + " BeansException: {}", type.getName(), e.getMessage()); service = null; } } if (name == null && service == null) { try { Map<String, T> map = applicationContext.getBeansOfType(type); if (map.size() == 1) { service = (T) map.values().iterator().next(); } else { log.error("Multiple beans of type {} found. Only one was expected!", type.getName()); } } catch (BeansException e) { log.error(e.getMessage(), e); service = null; } } } return service; } DSpaceServiceManager(DSpaceConfigurationService configurationService); protected  DSpaceServiceManager(DSpaceConfigurationService configurationService,
            String... springXmlConfigFiles); boolean isRunning(); ListableBeanFactory getBeanFactory(); @Override ClassPathXmlApplicationContext getApplicationContext(); void notifyServiceManagerReady(); @Override void shutdown(); @Override void startup(); @Override void registerService(String name, Object service); @Override void registerServiceNoAutowire(String name, Object service); @SuppressWarnings("unchecked") @Override T registerServiceClass(String name, Class<T> type); @Override void unregisterService(String name); @SuppressWarnings("unchecked") @Override T getServiceByName(String name, Class<T> type); @SuppressWarnings("unchecked") @Override List<T> getServicesByType(Class<T> type); @Override List<String> getServicesNames(); @Override boolean isServiceExists(String name); @Override Map<String, Object> getServices(); @Override void pushConfig(Map<String, Object> properties); static String[] getSpringPaths(boolean testMode, String[] configPaths,
                                          DSpaceConfigurationService configurationService); static final String CONFIG_PATH; static final String CORE_RESOURCE_PATH; static final String ADDON_RESOURCE_PATH; }