@Test public void pluginConfigInstance() throws Exception { TestConfigs.NoParameterConfig testConfig = PluginConfigFactory.pluginConfigInstance(TestConfigs.NoParameterConfig.class); Assert.assertNull(testConfig.getName()); }
public static <T extends PluginConfig> T pluginConfigInstance(Class<T> type) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException { checkState(!Modifier.isAbstract(type.getModifiers()), "%s is Interface or Abstract, unable to inject", type); try { Constructor<? extends T> pluginConfigConstructor = type.getDeclaredConstructor(); logger.debug("find 'no parameter' constructor with [{}]", type); pluginConfigConstructor.setAccessible(true); return pluginConfigConstructor.newInstance(); } catch (NoSuchMethodException e) { logger.warn("Not find 'no parameter' constructor, use javassist inject with [{}]", type); return UnsafeHelper.allocateInstance2(type); } }
PluginConfigFactory { public static <T extends PluginConfig> T pluginConfigInstance(Class<T> type) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException { checkState(!Modifier.isAbstract(type.getModifiers()), "%s is Interface or Abstract, unable to inject", type); try { Constructor<? extends T> pluginConfigConstructor = type.getDeclaredConstructor(); logger.debug("find 'no parameter' constructor with [{}]", type); pluginConfigConstructor.setAccessible(true); return pluginConfigConstructor.newInstance(); } catch (NoSuchMethodException e) { logger.warn("Not find 'no parameter' constructor, use javassist inject with [{}]", type); return UnsafeHelper.allocateInstance2(type); } } }
PluginConfigFactory { public static <T extends PluginConfig> T pluginConfigInstance(Class<T> type) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException { checkState(!Modifier.isAbstract(type.getModifiers()), "%s is Interface or Abstract, unable to inject", type); try { Constructor<? extends T> pluginConfigConstructor = type.getDeclaredConstructor(); logger.debug("find 'no parameter' constructor with [{}]", type); pluginConfigConstructor.setAccessible(true); return pluginConfigConstructor.newInstance(); } catch (NoSuchMethodException e) { logger.warn("Not find 'no parameter' constructor, use javassist inject with [{}]", type); return UnsafeHelper.allocateInstance2(type); } } private  PluginConfigFactory(); }
PluginConfigFactory { public static <T extends PluginConfig> T pluginConfigInstance(Class<T> type) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException { checkState(!Modifier.isAbstract(type.getModifiers()), "%s is Interface or Abstract, unable to inject", type); try { Constructor<? extends T> pluginConfigConstructor = type.getDeclaredConstructor(); logger.debug("find 'no parameter' constructor with [{}]", type); pluginConfigConstructor.setAccessible(true); return pluginConfigConstructor.newInstance(); } catch (NoSuchMethodException e) { logger.warn("Not find 'no parameter' constructor, use javassist inject with [{}]", type); return UnsafeHelper.allocateInstance2(type); } } private  PluginConfigFactory(); T createPluginConfig(Class<T> type, Map<String, Object> config); static T pluginConfigInstance(Class<T> type); @SuppressWarnings("unchecked") static void injectConfig(T pluginConfig, Map<String, Object> config); static List<Map<String, Object>> getPluginConfigDefaultValues(Class<? extends PluginConfig> configClass); }
PluginConfigFactory { public static <T extends PluginConfig> T pluginConfigInstance(Class<T> type) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException { checkState(!Modifier.isAbstract(type.getModifiers()), "%s is Interface or Abstract, unable to inject", type); try { Constructor<? extends T> pluginConfigConstructor = type.getDeclaredConstructor(); logger.debug("find 'no parameter' constructor with [{}]", type); pluginConfigConstructor.setAccessible(true); return pluginConfigConstructor.newInstance(); } catch (NoSuchMethodException e) { logger.warn("Not find 'no parameter' constructor, use javassist inject with [{}]", type); return UnsafeHelper.allocateInstance2(type); } } private  PluginConfigFactory(); T createPluginConfig(Class<T> type, Map<String, Object> config); static T pluginConfigInstance(Class<T> type); @SuppressWarnings("unchecked") static void injectConfig(T pluginConfig, Map<String, Object> config); static List<Map<String, Object>> getPluginConfigDefaultValues(Class<? extends PluginConfig> configClass); static final PluginConfigFactory INSTANCE; }