use of cn.taketoday.core.io.PatternResourceLoader in project today-framework by TAKETODAY.
the class ParserStrategyUtils method instantiateClass.
/**
* Instantiate a class using an appropriate constructor and return the new
* instance as the specified assignable type. The returned instance will
* have {@link BeanClassLoaderAware}, {@link BeanFactoryAware},
* {@link EnvironmentAware}, and {@link ResourceLoaderAware} contracts
* invoked if they are implemented by the given object.
*/
@SuppressWarnings("unchecked")
static <T> T instantiateClass(Class<?> clazz, Class<T> assignableTo, BootstrapContext loadingContext) {
Assert.notNull(clazz, "Class must not be null");
Assert.isAssignable(assignableTo, clazz);
if (clazz.isInterface()) {
throw new BeanInstantiationException(clazz, "Specified class is an interface");
}
BeanDefinitionRegistry registry = loadingContext.getRegistry();
PatternResourceLoader resourceLoader = loadingContext.getResourceLoader();
Environment environment = loadingContext.getEnvironment();
ClassLoader classLoader = registry instanceof ConfigurableBeanFactory ? ((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader();
T instance = (T) createInstance(clazz, environment, resourceLoader, registry, classLoader);
ParserStrategyUtils.invokeAwareMethods(instance, environment, resourceLoader, registry, classLoader);
return instance;
}
use of cn.taketoday.core.io.PatternResourceLoader in project today-framework by TAKETODAY.
the class ParserStrategyUtils method newInstance.
/**
* Instantiate a class using an appropriate constructor and return the new
* instance as the specified assignable type. The returned instance will
* have {@link BeanClassLoaderAware}, {@link BeanFactoryAware},
* {@link EnvironmentAware}, and {@link ResourceLoaderAware} contracts
* invoked if they are implemented by the given object.
*/
@SuppressWarnings("unchecked")
static <T> T newInstance(Class<?> clazz, Class<T> assignableTo, BootstrapContext loadingContext) {
Assert.notNull(clazz, "Class must not be null");
Assert.isAssignable(assignableTo, clazz);
if (clazz.isInterface()) {
throw new BeanInstantiationException(clazz, "Specified class is an interface");
}
BeanDefinitionRegistry registry = loadingContext.getRegistry();
PatternResourceLoader resourceLoader = loadingContext.getResourceLoader();
Environment environment = loadingContext.getEnvironment();
ClassLoader classLoader = registry instanceof ConfigurableBeanFactory ? ((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader();
T instance = (T) createInstance(clazz, environment, resourceLoader, registry, classLoader);
ParserStrategyUtils.invokeAwareMethods(instance, environment, resourceLoader, registry, classLoader);
return instance;
}
use of cn.taketoday.core.io.PatternResourceLoader in project today-infrastructure by TAKETODAY.
the class ParserStrategyUtils method newInstance.
/**
* Instantiate a class using an appropriate constructor and return the new
* instance as the specified assignable type. The returned instance will
* have {@link BeanClassLoaderAware}, {@link BeanFactoryAware},
* {@link EnvironmentAware}, and {@link ResourceLoaderAware} contracts
* invoked if they are implemented by the given object.
*/
@SuppressWarnings("unchecked")
static <T> T newInstance(Class<?> clazz, Class<T> assignableTo, BootstrapContext loadingContext) {
Assert.notNull(clazz, "Class must not be null");
Assert.isAssignable(assignableTo, clazz);
if (clazz.isInterface()) {
throw new BeanInstantiationException(clazz, "Specified class is an interface");
}
BeanDefinitionRegistry registry = loadingContext.getRegistry();
PatternResourceLoader resourceLoader = loadingContext.getResourceLoader();
Environment environment = loadingContext.getEnvironment();
ClassLoader classLoader = registry instanceof ConfigurableBeanFactory ? ((ConfigurableBeanFactory) registry).getBeanClassLoader() : resourceLoader.getClassLoader();
T instance = (T) createInstance(clazz, environment, resourceLoader, registry, classLoader);
ParserStrategyUtils.invokeAwareMethods(instance, environment, resourceLoader, registry, classLoader);
return instance;
}
Aggregations