@Test public void instantiatesObjects() { ExtensionObjectFactory factory = new ExtensionObjectFactory(extensionFactory -> DEFAULT_CLASS_LOADER); String className = String.class.getName(); Object object = factory.newInstance(new SpiExtensionFactory(className, "/fake/class/path"), Object.class); assertThat(object, is(instanceOf(String.class))); }
public <T> T newInstance(SpiExtensionFactory extensionFactory, Class<T> type) throws ExtensionLoadingException { try { Class<?> extensionClass = loadClass(extensionFactory); Object instance = extensionClass.newInstance(); return type.cast(instance); } catch (ExtensionLoadingException e) { throw e; } catch (Exception e) { throw new ExtensionLoadingException("error instantiating class=" + extensionFactory.factoryClass(), e); } }
ExtensionObjectFactory { public <T> T newInstance(SpiExtensionFactory extensionFactory, Class<T> type) throws ExtensionLoadingException { try { Class<?> extensionClass = loadClass(extensionFactory); Object instance = extensionClass.newInstance(); return type.cast(instance); } catch (ExtensionLoadingException e) { throw e; } catch (Exception e) { throw new ExtensionLoadingException("error instantiating class=" + extensionFactory.factoryClass(), e); } } }
ExtensionObjectFactory { public <T> T newInstance(SpiExtensionFactory extensionFactory, Class<T> type) throws ExtensionLoadingException { try { Class<?> extensionClass = loadClass(extensionFactory); Object instance = extensionClass.newInstance(); return type.cast(instance); } catch (ExtensionLoadingException e) { throw e; } catch (Exception e) { throw new ExtensionLoadingException("error instantiating class=" + extensionFactory.factoryClass(), e); } } private  ExtensionObjectFactory(); @VisibleForTesting  ExtensionObjectFactory(Function<SpiExtensionFactory, ClassSource> extensionLocator); }
ExtensionObjectFactory { public <T> T newInstance(SpiExtensionFactory extensionFactory, Class<T> type) throws ExtensionLoadingException { try { Class<?> extensionClass = loadClass(extensionFactory); Object instance = extensionClass.newInstance(); return type.cast(instance); } catch (ExtensionLoadingException e) { throw e; } catch (Exception e) { throw new ExtensionLoadingException("error instantiating class=" + extensionFactory.factoryClass(), e); } } private  ExtensionObjectFactory(); @VisibleForTesting  ExtensionObjectFactory(Function<SpiExtensionFactory, ClassSource> extensionLocator); T newInstance(SpiExtensionFactory extensionFactory, Class<T> type); }
ExtensionObjectFactory { public <T> T newInstance(SpiExtensionFactory extensionFactory, Class<T> type) throws ExtensionLoadingException { try { Class<?> extensionClass = loadClass(extensionFactory); Object instance = extensionClass.newInstance(); return type.cast(instance); } catch (ExtensionLoadingException e) { throw e; } catch (Exception e) { throw new ExtensionLoadingException("error instantiating class=" + extensionFactory.factoryClass(), e); } } private  ExtensionObjectFactory(); @VisibleForTesting  ExtensionObjectFactory(Function<SpiExtensionFactory, ClassSource> extensionLocator); T newInstance(SpiExtensionFactory extensionFactory, Class<T> type); static final ExtensionObjectFactory EXTENSION_OBJECT_FACTORY; }