use of cn.taketoday.core.annotation.MergedAnnotation in project today-framework by TAKETODAY.
the class AspectAutoProxyCreator method addCandidateAdvisors.
protected void addCandidateAdvisors() {
BeanFactory beanFactory = getFactory();
Set<String> aspectBeanNames = beanFactory.getBeanNamesForAnnotation(Aspect.class);
for (String name : aspectBeanNames) {
log.info("Found Aspect: [{}]", name);
Class<?> aspectClass = beanFactory.getType(name);
Assert.state(aspectClass != null, "Cannot determine bean type");
BeanDefinition aspectDef = beanFactory.getBeanDefinition(name);
// around
if (MethodInterceptor.class.isAssignableFrom(aspectClass)) {
Stream<MergedAnnotation<Advice>> adviceAttributes = getAdviceAttributes(aspectDef);
addCandidateAdvisors(aspectDef, null, adviceAttributes);
}
// annotations: @AfterReturning @Around @Before @After @AfterThrowing
Method[] declaredMethods = ReflectionUtils.getDeclaredMethods(aspectClass);
for (Method aspectMethod : declaredMethods) {
Stream<MergedAnnotation<Advice>> adviceAttributes = getAdviceAttributes(aspectMethod);
addCandidateAdvisors(aspectDef, aspectMethod, adviceAttributes);
}
}
}
use of cn.taketoday.core.annotation.MergedAnnotation 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.core.annotation.MergedAnnotation 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());
}
use of cn.taketoday.core.annotation.MergedAnnotation in project today-framework by TAKETODAY.
the class AspectAutoProxyCreator method addCandidateAdvisors.
private void addCandidateAdvisors(BeanDefinition aspectDef, @Nullable Method aspectMethod, Stream<MergedAnnotation<Advice>> adviceAttributes) {
adviceAttributes.forEach(advice -> {
MethodInterceptor interceptor = getInterceptor(aspectDef, aspectMethod, advice);
if (log.isTraceEnabled()) {
log.trace("Found Interceptor: [{}]", interceptor);
}
// Annotations
Class<? extends Annotation>[] annotations = advice.getClassArray(MergedAnnotation.VALUE);
if (ObjectUtils.isNotEmpty(annotations)) {
for (Class<? extends Annotation> annotation : annotations) {
AnnotationMatchingPointcut matchingPointcut = AnnotationMatchingPointcut.forMethodAnnotation(annotation);
DefaultPointcutAdvisor pointcutAdvisor = new DefaultPointcutAdvisor(matchingPointcut, interceptor);
annotationAdvisors.add(pointcutAdvisor);
}
}
});
}
Aggregations