use of cn.taketoday.beans.factory.parsing.CompositeComponentDefinition in project today-infrastructure by TAKETODAY.
the class AnnotationDrivenBeanDefinitionParser method parse.
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
// Register component for the surrounding <task:annotation-driven> element.
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
parserContext.pushContainingComponent(compDefinition);
// Nest the concrete post-processor bean in the surrounding component.
BeanDefinitionRegistry registry = parserContext.getRegistry();
String mode = element.getAttribute("mode");
if ("aspectj".equals(mode)) {
// mode="aspectj"
registerAsyncExecutionAspect(element, parserContext);
} else {
// mode="proxy"
if (registry.containsBeanDefinition(TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME)) {
parserContext.getReaderContext().error("Only one AsyncAnnotationBeanPostProcessor may exist within the context.", source);
} else {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition("cn.taketoday.scheduling.annotation.AsyncAnnotationBeanPostProcessor");
builder.getRawBeanDefinition().setSource(source);
String executor = element.getAttribute("executor");
if (StringUtils.hasText(executor)) {
builder.addPropertyReference("executor", executor);
}
String exceptionHandler = element.getAttribute("exception-handler");
if (StringUtils.hasText(exceptionHandler)) {
builder.addPropertyReference("exceptionHandler", exceptionHandler);
}
if (Boolean.parseBoolean(element.getAttribute(AopNamespaceUtils.PROXY_TARGET_CLASS_ATTRIBUTE))) {
builder.addPropertyValue("proxyTargetClass", true);
}
registerPostProcessor(parserContext, builder, TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);
}
}
if (registry.containsBeanDefinition(TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
parserContext.getReaderContext().error("Only one ScheduledAnnotationBeanPostProcessor may exist within the context.", source);
} else {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition("cn.taketoday.scheduling.annotation.ScheduledAnnotationBeanPostProcessor");
builder.getRawBeanDefinition().setSource(source);
String scheduler = element.getAttribute("scheduler");
if (StringUtils.hasText(scheduler)) {
builder.addPropertyReference("scheduler", scheduler);
}
registerPostProcessor(parserContext, builder, TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME);
}
// Finally register the composite component.
parserContext.popAndRegisterContainingComponent();
return null;
}
use of cn.taketoday.beans.factory.parsing.CompositeComponentDefinition in project today-infrastructure by TAKETODAY.
the class AopNamespaceHandlerEventTests method pointcutEvents.
@Test
void pointcutEvents() {
this.reader.loadBeanDefinitions(POINTCUT_EVENTS_CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertThat(componentDefinitions).as("Incorrect number of events fired").hasSize(1);
assertThat(componentDefinitions[0]).as("No holder with nested components").isInstanceOf(CompositeComponentDefinition.class);
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
assertThat(compositeDef.getName()).isEqualTo("aop:config");
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
assertThat(nestedComponentDefs).as("Incorrect number of inner components").hasSize(2);
PointcutComponentDefinition pcd = null;
for (ComponentDefinition componentDefinition : nestedComponentDefs) {
if (componentDefinition instanceof PointcutComponentDefinition) {
pcd = (PointcutComponentDefinition) componentDefinition;
break;
}
}
assertThat(pcd).as("PointcutComponentDefinition not found").isNotNull();
assertThat(pcd.getBeanDefinitions()).as("Incorrect number of BeanDefinitions").hasSize(1);
}
use of cn.taketoday.beans.factory.parsing.CompositeComponentDefinition in project today-framework by TAKETODAY.
the class AopNamespaceHandlerEventTests method advisorEventsWithDirectPointcut.
@Test
void advisorEventsWithDirectPointcut() {
this.reader.loadBeanDefinitions(DIRECT_POINTCUT_EVENTS_CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertThat(componentDefinitions).as("Incorrect number of events fired").hasSize(2);
assertThat(componentDefinitions[0]).as("No holder with nested components").isInstanceOf(CompositeComponentDefinition.class);
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
assertThat(compositeDef.getName()).isEqualTo("aop:config");
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
assertThat(nestedComponentDefs).as("Incorrect number of inner components").hasSize(2);
AdvisorComponentDefinition acd = null;
for (ComponentDefinition componentDefinition : nestedComponentDefs) {
if (componentDefinition instanceof AdvisorComponentDefinition) {
acd = (AdvisorComponentDefinition) componentDefinition;
break;
}
}
assertThat(acd).as("AdvisorComponentDefinition not found").isNotNull();
assertThat(acd.getBeanDefinitions()).hasSize(2);
assertThat(acd.getBeanReferences()).hasSize(1);
assertThat(componentDefinitions[1]).as("No advice bean found").isInstanceOf(BeanComponentDefinition.class);
BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1];
assertThat(adviceDef.getBeanName()).isEqualTo("countingAdvice");
}
use of cn.taketoday.beans.factory.parsing.CompositeComponentDefinition in project today-framework by TAKETODAY.
the class AopNamespaceHandlerEventTests method pointcutEvents.
@Test
void pointcutEvents() {
this.reader.loadBeanDefinitions(POINTCUT_EVENTS_CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertThat(componentDefinitions).as("Incorrect number of events fired").hasSize(1);
assertThat(componentDefinitions[0]).as("No holder with nested components").isInstanceOf(CompositeComponentDefinition.class);
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
assertThat(compositeDef.getName()).isEqualTo("aop:config");
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
assertThat(nestedComponentDefs).as("Incorrect number of inner components").hasSize(2);
PointcutComponentDefinition pcd = null;
for (ComponentDefinition componentDefinition : nestedComponentDefs) {
if (componentDefinition instanceof PointcutComponentDefinition) {
pcd = (PointcutComponentDefinition) componentDefinition;
break;
}
}
assertThat(pcd).as("PointcutComponentDefinition not found").isNotNull();
assertThat(pcd.getBeanDefinitions()).as("Incorrect number of BeanDefinitions").hasSize(1);
}
use of cn.taketoday.beans.factory.parsing.CompositeComponentDefinition in project today-framework by TAKETODAY.
the class AnnotationConfigBeanDefinitionParser method parse.
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
Object source = parserContext.extractSource(element);
// Obtain bean definitions for all relevant BeanPostProcessors.
AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), holder -> {
holder.setSource(source);
// Nest the concrete beans in the surrounding component.
parserContext.registerComponent(new BeanComponentDefinition(holder));
});
// Register component for the surrounding <context:annotation-config> element.
CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
parserContext.pushContainingComponent(compDefinition);
// Finally register the composite component.
parserContext.popAndRegisterContainingComponent();
return null;
}
Aggregations