use of cn.taketoday.util.ClassUtils in project today-framework by TAKETODAY.
the class MapperScannerRegistrar method registerBeanDefinitions.
protected void registerBeanDefinitions(AnnotationMetadata annoMeta, MergedAnnotation<MapperScan> mapperScan, BeanDefinitionRegistry registry, String beanName) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
builder.addPropertyValue("processPropertyPlaceHolders", true);
Class<? extends Annotation> annotationClass = mapperScan.getClass("annotationClass");
if (!Annotation.class.equals(annotationClass)) {
builder.addPropertyValue("annotationClass", annotationClass);
}
Class<?> markerInterface = mapperScan.getClass("markerInterface");
if (!Class.class.equals(markerInterface)) {
builder.addPropertyValue("markerInterface", markerInterface);
}
Class<? extends BeanNameGenerator> generatorClass = mapperScan.getClass("nameGenerator");
if (!BeanNameGenerator.class.equals(generatorClass)) {
builder.addPropertyValue("nameGenerator", BeanUtils.newInstance(generatorClass));
}
Class<? extends MapperFactoryBean<?>> mapperFactoryBeanClass = mapperScan.getClass("factoryBean");
if (!MapperFactoryBean.class.equals(mapperFactoryBeanClass)) {
builder.addPropertyValue("mapperFactoryBeanClass", mapperFactoryBeanClass);
}
String sqlSessionTemplateRef = mapperScan.getString("sqlSessionTemplateRef");
if (StringUtils.hasText(sqlSessionTemplateRef)) {
builder.addPropertyValue("sqlSessionTemplateBeanName", sqlSessionTemplateRef);
}
String sqlSessionFactoryRef = mapperScan.getString("sqlSessionFactoryRef");
if (StringUtils.hasText(sqlSessionFactoryRef)) {
builder.addPropertyValue("sqlSessionFactoryBeanName", sqlSessionFactoryRef);
}
ArrayList<String> basePackages = new ArrayList<>();
basePackages.addAll(Arrays.stream(mapperScan.getStringArray("value")).filter(StringUtils::hasText).toList());
basePackages.addAll(Arrays.stream(mapperScan.getStringArray("basePackages")).filter(StringUtils::hasText).toList());
basePackages.addAll(Arrays.stream(mapperScan.getClassArray("basePackageClasses")).map(ClassUtils::getPackageName).toList());
if (basePackages.isEmpty()) {
basePackages.add(getDefaultBasePackage(annoMeta));
}
String lazyInitialization = mapperScan.getString("lazyInitialization");
if (StringUtils.hasText(lazyInitialization)) {
builder.addPropertyValue("lazyInitialization", lazyInitialization);
}
String defaultScope = mapperScan.getString("defaultScope");
if (StringUtils.hasText(defaultScope)) {
builder.addPropertyValue("defaultScope", defaultScope);
}
builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(basePackages));
builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(beanName, builder.getRawBeanDefinition());
}
use of cn.taketoday.util.ClassUtils in project today-infrastructure by TAKETODAY.
the class MapperScannerRegistrar method registerBeanDefinitions.
protected void registerBeanDefinitions(AnnotationMetadata annoMeta, MergedAnnotation<MapperScan> mapperScan, BeanDefinitionRegistry registry, String beanName) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MapperScannerConfigurer.class);
builder.addPropertyValue("processPropertyPlaceHolders", true);
Class<? extends Annotation> annotationClass = mapperScan.getClass("annotationClass");
if (!Annotation.class.equals(annotationClass)) {
builder.addPropertyValue("annotationClass", annotationClass);
}
Class<?> markerInterface = mapperScan.getClass("markerInterface");
if (!Class.class.equals(markerInterface)) {
builder.addPropertyValue("markerInterface", markerInterface);
}
Class<? extends BeanNameGenerator> generatorClass = mapperScan.getClass("nameGenerator");
if (!BeanNameGenerator.class.equals(generatorClass)) {
builder.addPropertyValue("nameGenerator", BeanUtils.newInstance(generatorClass));
}
Class<? extends MapperFactoryBean<?>> mapperFactoryBeanClass = mapperScan.getClass("factoryBean");
if (!MapperFactoryBean.class.equals(mapperFactoryBeanClass)) {
builder.addPropertyValue("mapperFactoryBeanClass", mapperFactoryBeanClass);
}
String sqlSessionTemplateRef = mapperScan.getString("sqlSessionTemplateRef");
if (StringUtils.hasText(sqlSessionTemplateRef)) {
builder.addPropertyValue("sqlSessionTemplateBeanName", sqlSessionTemplateRef);
}
String sqlSessionFactoryRef = mapperScan.getString("sqlSessionFactoryRef");
if (StringUtils.hasText(sqlSessionFactoryRef)) {
builder.addPropertyValue("sqlSessionFactoryBeanName", sqlSessionFactoryRef);
}
ArrayList<String> basePackages = new ArrayList<>();
basePackages.addAll(Arrays.stream(mapperScan.getStringArray("value")).filter(StringUtils::hasText).toList());
basePackages.addAll(Arrays.stream(mapperScan.getStringArray("basePackages")).filter(StringUtils::hasText).toList());
basePackages.addAll(Arrays.stream(mapperScan.getClassArray("basePackageClasses")).map(ClassUtils::getPackageName).toList());
if (basePackages.isEmpty()) {
basePackages.add(getDefaultBasePackage(annoMeta));
}
String lazyInitialization = mapperScan.getString("lazyInitialization");
if (StringUtils.hasText(lazyInitialization)) {
builder.addPropertyValue("lazyInitialization", lazyInitialization);
}
String defaultScope = mapperScan.getString("defaultScope");
if (StringUtils.hasText(defaultScope)) {
builder.addPropertyValue("defaultScope", defaultScope);
}
builder.addPropertyValue("basePackage", StringUtils.collectionToCommaDelimitedString(basePackages));
builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
registry.registerBeanDefinition(beanName, builder.getRawBeanDefinition());
}
Aggregations