ExtensionLoader { protected synchronized void loadFromFile(String path) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Loading extension of extensible {} from path: {}", interfaceName, path); } String file = StringUtils.isBlank(extensible.file()) ? interfaceName : extensible.file().trim(); String fullFileName = path + file; try { ClassLoader classLoader = ClassLoaderUtils.getClassLoader(getClass()); loadFromClassLoader(classLoader, fullFileName); } catch (Throwable t) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Failed to load extension of extensible " + interfaceName + " from path:" + fullFileName, t); } } } ExtensionLoader(Class<T> interfaceClass, ExtensionLoaderListener<T> listener); protected  ExtensionLoader(Class<T> interfaceClass); protected  ExtensionLoader(Class<T> interfaceClass, boolean autoLoad, ExtensionLoaderListener<T> listener); ConcurrentMap<String, ExtensionClass<T>> getAllExtensions(); ExtensionClass<T> getExtensionClass(String alias); T getExtension(String alias); T getExtension(String alias, Class[] argTypes, Object[] args); void loadExtension(Class loadedClass); void addListener(ExtensionLoaderListener<T> listener);  }
@Test public void testLoadFromFile() throws Exception { ExtensionLoader loader = new ExtensionLoader<Filter>(Filter.class, false, null); loader.loadFromFile("META-INF/ext1/"); Assert.assertTrue(loader.getAllExtensions().isEmpty()); loader = new ExtensionLoader<Filter>(Filter.class, false, null); loader.loadFromFile("META-INF/ext2/"); Assert.assertFalse(loader.getAllExtensions().isEmpty()); ExtensionClass extensionClass = loader.getExtensionClass("rightxx0"); Assert.assertNotNull(extensionClass); Assert.assertTrue(extensionClass.getOrder() == 123); loader = new ExtensionLoader<Filter>(Filter.class, false, new TestErrorLoadListener()); loader.loadFromFile("META-INF/ext3/"); Assert.assertFalse(loader.getAllExtensions().isEmpty()); extensionClass = loader.getExtensionClass("rightxx0"); Assert.assertNotNull(extensionClass); extensionClass = loader.getExtensionClass("rightxx1"); Assert.assertNotNull(extensionClass); Assert.assertTrue(extensionClass.getOrder() == 128); loader = new ExtensionLoader<Filter>(Filter.class, false, new TestLoadListener()); loader.loadFromFile("META-INF/ext4/"); Assert.assertFalse(loader.getAllExtensions().isEmpty()); extensionClass = loader.getExtensionClass("rightxx0"); Assert.assertNotNull(extensionClass); Assert.assertTrue(extensionClass.getOrder() == 123); extensionClass = loader.getExtensionClass("rightxx1"); Assert.assertNotNull(extensionClass); Assert.assertTrue(extensionClass.getOrder() == 128); }