JVoiceXmlConfiguration implements Configuration { @Override public synchronized <T extends Object> Collection<T> loadObjects( final Class<T> baseClass, final String root) throws ConfigurationException { final Collection<T> beans = new java.util.ArrayList<T>(); final Collection<File> files; try { files = getConfigurationFiles(root); } catch (IOException e) { throw new ConfigurationException(e.getMessage(), e); } for (File file : files) { try { LOGGER.info("loading configuration '" + file.getCanonicalPath() + "'..."); final Resource resource = getResource(file); if (resource == null) { continue; } final DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); final XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory); reader.loadBeanDefinitions(resource); final ClasspathExtractor extractor = getClassPathExtractor(file); if (extractor == null) { continue; } final String repository = extractor.getLoaderRepostory(); final JVoiceXmlClassLoader loader = getClassLoader(repository); final URL[] urls = extractor.getClasspathEntries(); loader.addURLs(urls); if (LOGGER.isDebugEnabled()) { for (URL url : urls) { LOGGER.debug("using classpath entry '" + url + "'"); } } factory.setBeanClassLoader(loader); final String[] names = factory.getBeanNamesForType(baseClass); if (names.length == 0) { LOGGER.info("no loadable objects of type '" + baseClass + "' in file '" + file.getCanonicalPath() + "'"); } else { for (String name : names) { LOGGER.info("loading '" + name + "'"); final Object o = factory.getBean(name, baseClass); final T bean = baseClass.cast(o); beans.add(bean); if (bean instanceof ExtendedConfiguration) { final ExtendedConfiguration config = (ExtendedConfiguration) bean; config.setConfigurationFile(file); } } } } catch (IOException | BeansException e) { throw new ConfigurationException(e.getMessage(), e); } } return beans; } JVoiceXmlConfiguration(); @Override synchronized Collection<T> loadObjects(
            final Class<T> baseClass, final String root); @Override synchronized T loadObject(
            final Class<T> baseClass, final String key); @Override synchronized T loadObject(
            final Class<T> baseClass);  }
@Test @SuppressWarnings("rawtypes") public void testLoadObjects() throws Exception { JVoiceXmlConfiguration config = new JVoiceXmlConfiguration(); final Collection<ResourceFactory> factories = config.loadObjects(ResourceFactory.class, "implementation"); Assert.assertEquals(1, factories.size()); final ResourceFactory factory = factories.iterator().next(); Assert.assertEquals(DesktopTelephonySupportFactory.class, factory.getClass()); }