org.springframework.beans.factory.parsing.BeanComponentDefinition Java Examples

The following examples show how to use org.springframework.beans.factory.parsing.BeanComponentDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScopedProxyBeanDefinitionDecorator.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
	boolean proxyTargetClass = true;
	if (node instanceof Element) {
		Element ele = (Element) node;
		if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
			proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
		}
	}

	// Register the original bean definition as it will be referenced by the scoped proxy
	// and is relevant for tooling (validation, navigation).
	BeanDefinitionHolder holder =
			ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass);
	String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName());
	parserContext.getReaderContext().fireComponentRegistered(
			new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
	return holder;
}
 
Example #2
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void registerAsyncExecutionAspect(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME)) {
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ASYNC_EXECUTION_ASPECT_CLASS_NAME);
		builder.setFactoryMethod("aspectOf");
		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);
		}
		parserContext.registerBeanComponent(new BeanComponentDefinition(builder.getBeanDefinition(),
				TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME));
	}
}
 
Example #3
Source File: MvcNamespaceUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Adds an alias to an existing well-known name or registers a new instance of a {@link UrlPathHelper}
 * under that well-known name, unless already registered.
 * @return a RuntimeBeanReference to this {@link UrlPathHelper} instance
 */
public static RuntimeBeanReference registerUrlPathHelper(
		@Nullable RuntimeBeanReference urlPathHelperRef, ParserContext parserContext, @Nullable Object source) {

	if (urlPathHelperRef != null) {
		if (parserContext.getRegistry().isAlias(URL_PATH_HELPER_BEAN_NAME)) {
			parserContext.getRegistry().removeAlias(URL_PATH_HELPER_BEAN_NAME);
		}
		parserContext.getRegistry().registerAlias(urlPathHelperRef.getBeanName(), URL_PATH_HELPER_BEAN_NAME);
	}
	else if (!parserContext.getRegistry().isAlias(URL_PATH_HELPER_BEAN_NAME)
			&& !parserContext.getRegistry().containsBeanDefinition(URL_PATH_HELPER_BEAN_NAME)) {
		RootBeanDefinition urlPathHelperDef = new RootBeanDefinition(UrlPathHelper.class);
		urlPathHelperDef.setSource(source);
		urlPathHelperDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parserContext.getRegistry().registerBeanDefinition(URL_PATH_HELPER_BEAN_NAME, urlPathHelperDef);
		parserContext.registerComponent(new BeanComponentDefinition(urlPathHelperDef, URL_PATH_HELPER_BEAN_NAME));
	}
	return new RuntimeBeanReference(URL_PATH_HELPER_BEAN_NAME);
}
 
Example #4
Source File: MvcNamespaceUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Adds an alias to an existing well-known name or registers a new instance of a {@link PathMatcher}
 * under that well-known name, unless already registered.
 * @return a RuntimeBeanReference to this {@link PathMatcher} instance
 */
public static RuntimeBeanReference registerPathMatcher(@Nullable RuntimeBeanReference pathMatcherRef,
		ParserContext parserContext, @Nullable Object source) {

	if (pathMatcherRef != null) {
		if (parserContext.getRegistry().isAlias(PATH_MATCHER_BEAN_NAME)) {
			parserContext.getRegistry().removeAlias(PATH_MATCHER_BEAN_NAME);
		}
		parserContext.getRegistry().registerAlias(pathMatcherRef.getBeanName(), PATH_MATCHER_BEAN_NAME);
	}
	else if (!parserContext.getRegistry().isAlias(PATH_MATCHER_BEAN_NAME)
			&& !parserContext.getRegistry().containsBeanDefinition(PATH_MATCHER_BEAN_NAME)) {
		RootBeanDefinition pathMatcherDef = new RootBeanDefinition(AntPathMatcher.class);
		pathMatcherDef.setSource(source);
		pathMatcherDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parserContext.getRegistry().registerBeanDefinition(PATH_MATCHER_BEAN_NAME, pathMatcherDef);
		parserContext.registerComponent(new BeanComponentDefinition(pathMatcherDef, PATH_MATCHER_BEAN_NAME));
	}
	return new RuntimeBeanReference(PATH_MATCHER_BEAN_NAME);
}
 
Example #5
Source File: AnnotationConfigBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	// Obtain bean definitions for all relevant BeanPostProcessors.
	Set<BeanDefinitionHolder> processorDefinitions =
			AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);

	// Register component for the surrounding <context:annotation-config> element.
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	parserContext.pushContainingComponent(compDefinition);

	// Nest the concrete beans in the surrounding component.
	for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
		parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
	}

	// Finally register the composite component.
	parserContext.popAndRegisterContainingComponent();

	return null;
}
 
Example #6
Source File: ComponentScanBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
protected void registerComponents(
		XmlReaderContext readerContext, Set<BeanDefinitionHolder> beanDefinitions, Element element) {

	Object source = readerContext.extractSource(element);
	CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);

	for (BeanDefinitionHolder beanDefHolder : beanDefinitions) {
		compositeDef.addNestedComponent(new BeanComponentDefinition(beanDefHolder));
	}

	// Register annotation config processors, if necessary.
	boolean annotationConfig = true;
	if (element.hasAttribute(ANNOTATION_CONFIG_ATTRIBUTE)) {
		annotationConfig = Boolean.valueOf(element.getAttribute(ANNOTATION_CONFIG_ATTRIBUTE));
	}
	if (annotationConfig) {
		Set<BeanDefinitionHolder> processorDefinitions =
				AnnotationConfigUtils.registerAnnotationConfigProcessors(readerContext.getRegistry(), source);
		for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
			compositeDef.addNestedComponent(new BeanComponentDefinition(processorDefinition));
		}
	}

	readerContext.fireComponentRegistered(compositeDef);
}
 
Example #7
Source File: LoadTimeWeaverBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

	if (isAspectJWeavingEnabled(element.getAttribute(ASPECTJ_WEAVING_ATTRIBUTE), parserContext)) {
		if (!parserContext.getRegistry().containsBeanDefinition(ASPECTJ_WEAVING_ENABLER_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition(ASPECTJ_WEAVING_ENABLER_CLASS_NAME);
			parserContext.registerBeanComponent(
					new BeanComponentDefinition(def, ASPECTJ_WEAVING_ENABLER_BEAN_NAME));
		}

		if (isBeanConfigurerAspectEnabled(parserContext.getReaderContext().getBeanClassLoader())) {
			new SpringConfiguredBeanDefinitionParser().parse(element, parserContext);
		}
	}
}
 
Example #8
Source File: MessageBrokerBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Nullable
private RuntimeBeanReference getValidator(
		Element messageBrokerElement, @Nullable Object source, ParserContext context) {

	if (messageBrokerElement.hasAttribute("validator")) {
		return new RuntimeBeanReference(messageBrokerElement.getAttribute("validator"));
	}
	else if (javaxValidationPresent) {
		RootBeanDefinition validatorDef = new RootBeanDefinition(
				"org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean");
		validatorDef.setSource(source);
		validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String validatorName = context.getReaderContext().registerWithGeneratedName(validatorDef);
		context.registerComponent(new BeanComponentDefinition(validatorDef, validatorName));
		return new RuntimeBeanReference(validatorName);
	}
	else {
		return null;
	}
}
 
Example #9
Source File: ViewControllerBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
private BeanDefinition registerHandlerMapping(ParserContext context, @Nullable Object source) {
	if (context.getRegistry().containsBeanDefinition(HANDLER_MAPPING_BEAN_NAME)) {
		return context.getRegistry().getBeanDefinition(HANDLER_MAPPING_BEAN_NAME);
	}
	RootBeanDefinition beanDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
	beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	context.getRegistry().registerBeanDefinition(HANDLER_MAPPING_BEAN_NAME, beanDef);
	context.registerComponent(new BeanComponentDefinition(beanDef, HANDLER_MAPPING_BEAN_NAME));

	beanDef.setSource(source);
	beanDef.getPropertyValues().add("order", "1");
	beanDef.getPropertyValues().add("pathMatcher", MvcNamespaceUtils.registerPathMatcher(null, context, source));
	beanDef.getPropertyValues().add("urlPathHelper", MvcNamespaceUtils.registerUrlPathHelper(null, context, source));
	RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, context, source);
	beanDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef);

	return beanDef;
}
 
Example #10
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Nullable
private RuntimeBeanReference getValidator(Element element, @Nullable Object source, ParserContext context) {
	if (element.hasAttribute("validator")) {
		return new RuntimeBeanReference(element.getAttribute("validator"));
	}
	else if (javaxValidationPresent) {
		RootBeanDefinition validatorDef = new RootBeanDefinition(
				"org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean");
		validatorDef.setSource(source);
		validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String validatorName = context.getReaderContext().registerWithGeneratedName(validatorDef);
		context.registerComponent(new BeanComponentDefinition(validatorDef, validatorName));
		return new RuntimeBeanReference(validatorName);
	}
	else {
		return null;
	}
}
 
Example #11
Source File: AnnotationConfigBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	// Obtain bean definitions for all relevant BeanPostProcessors.
	Set<BeanDefinitionHolder> processorDefinitions =
			AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);

	// Register component for the surrounding <context:annotation-config> element.
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	parserContext.pushContainingComponent(compDefinition);

	// Nest the concrete beans in the surrounding component.
	for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
		parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
	}

	// Finally register the composite component.
	parserContext.popAndRegisterContainingComponent();

	return null;
}
 
Example #12
Source File: MvcNamespaceUtils.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Adds an alias to an existing well-known name or registers a new instance of a {@link UrlPathHelper}
 * under that well-known name, unless already registered.
 * @return a RuntimeBeanReference to this {@link UrlPathHelper} instance
 */
public static RuntimeBeanReference registerUrlPathHelper(
		@Nullable RuntimeBeanReference urlPathHelperRef, ParserContext parserContext, @Nullable Object source) {

	if (urlPathHelperRef != null) {
		if (parserContext.getRegistry().isAlias(URL_PATH_HELPER_BEAN_NAME)) {
			parserContext.getRegistry().removeAlias(URL_PATH_HELPER_BEAN_NAME);
		}
		parserContext.getRegistry().registerAlias(urlPathHelperRef.getBeanName(), URL_PATH_HELPER_BEAN_NAME);
	}
	else if (!parserContext.getRegistry().isAlias(URL_PATH_HELPER_BEAN_NAME) &&
			!parserContext.getRegistry().containsBeanDefinition(URL_PATH_HELPER_BEAN_NAME)) {
		RootBeanDefinition urlPathHelperDef = new RootBeanDefinition(UrlPathHelper.class);
		urlPathHelperDef.setSource(source);
		urlPathHelperDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parserContext.getRegistry().registerBeanDefinition(URL_PATH_HELPER_BEAN_NAME, urlPathHelperDef);
		parserContext.registerComponent(new BeanComponentDefinition(urlPathHelperDef, URL_PATH_HELPER_BEAN_NAME));
	}
	return new RuntimeBeanReference(URL_PATH_HELPER_BEAN_NAME);
}
 
Example #13
Source File: ComponentScanBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
protected void registerComponents(
		XmlReaderContext readerContext, Set<BeanDefinitionHolder> beanDefinitions, Element element) {

	Object source = readerContext.extractSource(element);
	CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);

	for (BeanDefinitionHolder beanDefHolder : beanDefinitions) {
		compositeDef.addNestedComponent(new BeanComponentDefinition(beanDefHolder));
	}

	// Register annotation config processors, if necessary.
	boolean annotationConfig = true;
	if (element.hasAttribute(ANNOTATION_CONFIG_ATTRIBUTE)) {
		annotationConfig = Boolean.valueOf(element.getAttribute(ANNOTATION_CONFIG_ATTRIBUTE));
	}
	if (annotationConfig) {
		Set<BeanDefinitionHolder> processorDefinitions =
				AnnotationConfigUtils.registerAnnotationConfigProcessors(readerContext.getRegistry(), source);
		for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
			compositeDef.addNestedComponent(new BeanComponentDefinition(processorDefinition));
		}
	}

	readerContext.fireComponentRegistered(compositeDef);
}
 
Example #14
Source File: MvcNamespaceUtils.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Adds an alias to an existing well-known name or registers a new instance of a {@link PathMatcher}
 * under that well-known name, unless already registered.
 * @return a RuntimeBeanReference to this {@link PathMatcher} instance
 */
public static RuntimeBeanReference registerPathMatcher(@Nullable RuntimeBeanReference pathMatcherRef,
		ParserContext parserContext, @Nullable Object source) {

	if (pathMatcherRef != null) {
		if (parserContext.getRegistry().isAlias(PATH_MATCHER_BEAN_NAME)) {
			parserContext.getRegistry().removeAlias(PATH_MATCHER_BEAN_NAME);
		}
		parserContext.getRegistry().registerAlias(pathMatcherRef.getBeanName(), PATH_MATCHER_BEAN_NAME);
	}
	else if (!parserContext.getRegistry().isAlias(PATH_MATCHER_BEAN_NAME) &&
			!parserContext.getRegistry().containsBeanDefinition(PATH_MATCHER_BEAN_NAME)) {
		RootBeanDefinition pathMatcherDef = new RootBeanDefinition(AntPathMatcher.class);
		pathMatcherDef.setSource(source);
		pathMatcherDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parserContext.getRegistry().registerBeanDefinition(PATH_MATCHER_BEAN_NAME, pathMatcherDef);
		parserContext.registerComponent(new BeanComponentDefinition(pathMatcherDef, PATH_MATCHER_BEAN_NAME));
	}
	return new RuntimeBeanReference(PATH_MATCHER_BEAN_NAME);
}
 
Example #15
Source File: ScopedProxyBeanDefinitionDecorator.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
	boolean proxyTargetClass = true;
	if (node instanceof Element) {
		Element ele = (Element) node;
		if (ele.hasAttribute(PROXY_TARGET_CLASS)) {
			proxyTargetClass = Boolean.valueOf(ele.getAttribute(PROXY_TARGET_CLASS));
		}
	}

	// Register the original bean definition as it will be referenced by the scoped proxy
	// and is relevant for tooling (validation, navigation).
	BeanDefinitionHolder holder =
			ScopedProxyUtils.createScopedProxy(definition, parserContext.getRegistry(), proxyTargetClass);
	String targetBeanName = ScopedProxyUtils.getTargetBeanName(definition.getBeanName());
	parserContext.getReaderContext().fireComponentRegistered(
			new BeanComponentDefinition(definition.getBeanDefinition(), targetBeanName));
	return holder;
}
 
Example #16
Source File: LoadTimeWeaverBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

	if (isAspectJWeavingEnabled(element.getAttribute(ASPECTJ_WEAVING_ATTRIBUTE), parserContext)) {
		if (!parserContext.getRegistry().containsBeanDefinition(ASPECTJ_WEAVING_ENABLER_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition(ASPECTJ_WEAVING_ENABLER_CLASS_NAME);
			parserContext.registerBeanComponent(
					new BeanComponentDefinition(def, ASPECTJ_WEAVING_ENABLER_BEAN_NAME));
		}

		if (isBeanConfigurerAspectEnabled(parserContext.getReaderContext().getBeanClassLoader())) {
			new SpringConfiguredBeanDefinitionParser().parse(element, parserContext);
		}
	}
}
 
Example #17
Source File: MessageBrokerBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Nullable
private RuntimeBeanReference getValidator(
		Element messageBrokerElement, @Nullable Object source, ParserContext context) {

	if (messageBrokerElement.hasAttribute("validator")) {
		return new RuntimeBeanReference(messageBrokerElement.getAttribute("validator"));
	}
	else if (javaxValidationPresent) {
		RootBeanDefinition validatorDef = new RootBeanDefinition(
				"org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean");
		validatorDef.setSource(source);
		validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String validatorName = context.getReaderContext().registerWithGeneratedName(validatorDef);
		context.registerComponent(new BeanComponentDefinition(validatorDef, validatorName));
		return new RuntimeBeanReference(validatorName);
	}
	else {
		return null;
	}
}
 
Example #18
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Nullable
private RuntimeBeanReference getValidator(Element element, @Nullable Object source, ParserContext context) {
	if (element.hasAttribute("validator")) {
		return new RuntimeBeanReference(element.getAttribute("validator"));
	}
	else if (javaxValidationPresent) {
		RootBeanDefinition validatorDef = new RootBeanDefinition(
				"org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean");
		validatorDef.setSource(source);
		validatorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String validatorName = context.getReaderContext().registerWithGeneratedName(validatorDef);
		context.registerComponent(new BeanComponentDefinition(validatorDef, validatorName));
		return new RuntimeBeanReference(validatorName);
	}
	else {
		return null;
	}
}
 
Example #19
Source File: ViewControllerBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private BeanDefinition registerHandlerMapping(ParserContext context, @Nullable Object source) {
	if (context.getRegistry().containsBeanDefinition(HANDLER_MAPPING_BEAN_NAME)) {
		return context.getRegistry().getBeanDefinition(HANDLER_MAPPING_BEAN_NAME);
	}
	RootBeanDefinition beanDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
	beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	context.getRegistry().registerBeanDefinition(HANDLER_MAPPING_BEAN_NAME, beanDef);
	context.registerComponent(new BeanComponentDefinition(beanDef, HANDLER_MAPPING_BEAN_NAME));

	beanDef.setSource(source);
	beanDef.getPropertyValues().add("order", "1");
	beanDef.getPropertyValues().add("pathMatcher", MvcNamespaceUtils.registerPathMatcher(null, context, source));
	beanDef.getPropertyValues().add("urlPathHelper", MvcNamespaceUtils.registerUrlPathHelper(null, context, source));
	RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, context, source);
	beanDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef);

	return beanDef;
}
 
Example #20
Source File: ResourcesBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void registerUrlProvider(ParserContext context, @Nullable Object source) {
	if (!context.getRegistry().containsBeanDefinition(RESOURCE_URL_PROVIDER)) {
		RootBeanDefinition urlProvider = new RootBeanDefinition(ResourceUrlProvider.class);
		urlProvider.setSource(source);
		urlProvider.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		context.getRegistry().registerBeanDefinition(RESOURCE_URL_PROVIDER, urlProvider);
		context.registerComponent(new BeanComponentDefinition(urlProvider, RESOURCE_URL_PROVIDER));

		RootBeanDefinition interceptor = new RootBeanDefinition(ResourceUrlProviderExposingInterceptor.class);
		interceptor.setSource(source);
		interceptor.getConstructorArgumentValues().addIndexedArgumentValue(0, urlProvider);

		RootBeanDefinition mappedInterceptor = new RootBeanDefinition(MappedInterceptor.class);
		mappedInterceptor.setSource(source);
		mappedInterceptor.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		mappedInterceptor.getConstructorArgumentValues().addIndexedArgumentValue(0, (Object) null);
		mappedInterceptor.getConstructorArgumentValues().addIndexedArgumentValue(1, interceptor);
		String mappedInterceptorName = context.getReaderContext().registerWithGeneratedName(mappedInterceptor);
		context.registerComponent(new BeanComponentDefinition(mappedInterceptor, mappedInterceptorName));
	}
}
 
Example #21
Source File: AnnotationDrivenCacheBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static void registerCacheAdvisor(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME)) {
		Object source = parserContext.extractSource(element);

		// Create the CacheOperationSource definition.
		BeanDefinition sourceDef = createJCacheOperationSourceBeanDefinition(element, source);
		String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

		// Create the CacheInterceptor definition.
		RootBeanDefinition interceptorDef =
				new RootBeanDefinition("org.springframework.cache.jcache.interceptor.JCacheInterceptor");
		interceptorDef.setSource(source);
		interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		interceptorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
		parseErrorHandler(element, interceptorDef);
		String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

		// Create the CacheAdvisor definition.
		RootBeanDefinition advisorDef = new RootBeanDefinition(
				"org.springframework.cache.jcache.interceptor.BeanFactoryJCacheOperationSourceAdvisor");
		advisorDef.setSource(source);
		advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName));
		advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
		if (element.hasAttribute("order")) {
			advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
		}
		parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME, advisorDef);

		CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source);
		compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME));
		parserContext.registerComponent(compositeDef);
	}
}
 
Example #22
Source File: SpringConfiguredBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(BEAN_CONFIGURER_ASPECT_BEAN_NAME)) {
		RootBeanDefinition def = new RootBeanDefinition();
		def.setBeanClassName(BEAN_CONFIGURER_ASPECT_CLASS_NAME);
		def.setFactoryMethodName("aspectOf");
		def.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		def.setSource(parserContext.extractSource(element));
		parserContext.registerBeanComponent(new BeanComponentDefinition(def, BEAN_CONFIGURER_ASPECT_BEAN_NAME));
	}
	return null;
}
 
Example #23
Source File: EventPublicationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void beanEventReceived() throws Exception {
	ComponentDefinition componentDefinition1 = this.eventListener.getComponentDefinition("testBean");
	assertTrue(componentDefinition1 instanceof BeanComponentDefinition);
	assertEquals(1, componentDefinition1.getBeanDefinitions().length);
	BeanDefinition beanDefinition1 = componentDefinition1.getBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Rob Harrop"),
			beanDefinition1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
	assertEquals(1, componentDefinition1.getBeanReferences().length);
	assertEquals("testBean2", componentDefinition1.getBeanReferences()[0].getBeanName());
	assertEquals(1, componentDefinition1.getInnerBeanDefinitions().length);
	BeanDefinition innerBd1 = componentDefinition1.getInnerBeanDefinitions()[0];
	assertEquals(new TypedStringValue("ACME"),
			innerBd1.getConstructorArgumentValues().getGenericArgumentValue(String.class).getValue());
	assertTrue(componentDefinition1.getSource() instanceof Element);

	ComponentDefinition componentDefinition2 = this.eventListener.getComponentDefinition("testBean2");
	assertTrue(componentDefinition2 instanceof BeanComponentDefinition);
	assertEquals(1, componentDefinition1.getBeanDefinitions().length);
	BeanDefinition beanDefinition2 = componentDefinition2.getBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Juergen Hoeller"),
			beanDefinition2.getPropertyValues().getPropertyValue("name").getValue());
	assertEquals(0, componentDefinition2.getBeanReferences().length);
	assertEquals(1, componentDefinition2.getInnerBeanDefinitions().length);
	BeanDefinition innerBd2 = componentDefinition2.getInnerBeanDefinitions()[0];
	assertEquals(new TypedStringValue("Eva Schallmeiner"),
			innerBd2.getPropertyValues().getPropertyValue("name").getValue());
	assertTrue(componentDefinition2.getSource() instanceof Element);
}
 
Example #24
Source File: AnnotationDrivenJmsBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static void registerInfrastructureBean(
		ParserContext parserContext, BeanDefinitionBuilder builder, String beanName) {

	builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	parserContext.getRegistry().registerBeanDefinition(beanName, builder.getBeanDefinition());
	BeanDefinitionHolder holder = new BeanDefinitionHolder(builder.getBeanDefinition(), beanName);
	parserContext.registerComponent(new BeanComponentDefinition(holder));
}
 
Example #25
Source File: MvcNamespaceUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Registers  an {@link HttpRequestHandlerAdapter} under a well-known
 * name unless already registered.
 */
private static void registerBeanNameUrlHandlerMapping(ParserContext context, @Nullable Object source) {
	if (!context.getRegistry().containsBeanDefinition(BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME)){
		RootBeanDefinition mappingDef = new RootBeanDefinition(BeanNameUrlHandlerMapping.class);
		mappingDef.setSource(source);
		mappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		mappingDef.getPropertyValues().add("order", 2);	// consistent with WebMvcConfigurationSupport
		RuntimeBeanReference corsRef = MvcNamespaceUtils.registerCorsConfigurations(null, context, source);
		mappingDef.getPropertyValues().add("corsConfigurations", corsRef);
		context.getRegistry().registerBeanDefinition(BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME, mappingDef);
		context.registerComponent(new BeanComponentDefinition(mappingDef, BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME));
	}
}
 
Example #26
Source File: AnnotationDrivenJmsBeanDefinitionParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static void registerInfrastructureBean(
		ParserContext parserContext, BeanDefinitionBuilder builder, String beanName) {

	builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	parserContext.getRegistry().registerBeanDefinition(beanName, builder.getBeanDefinition());
	BeanDefinitionHolder holder = new BeanDefinitionHolder(builder.getBeanDefinition(), beanName);
	parserContext.registerComponent(new BeanComponentDefinition(holder));
}
 
Example #27
Source File: MvcNamespaceUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Registers  an {@link HttpRequestHandlerAdapter} under a well-known
 * name unless already registered.
 */
private static void registerHttpRequestHandlerAdapter(ParserContext context, @Nullable Object source) {
	if (!context.getRegistry().containsBeanDefinition(HTTP_REQUEST_HANDLER_ADAPTER_BEAN_NAME)) {
		RootBeanDefinition adapterDef = new RootBeanDefinition(HttpRequestHandlerAdapter.class);
		adapterDef.setSource(source);
		adapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		context.getRegistry().registerBeanDefinition(HTTP_REQUEST_HANDLER_ADAPTER_BEAN_NAME, adapterDef);
		context.registerComponent(new BeanComponentDefinition(adapterDef, HTTP_REQUEST_HANDLER_ADAPTER_BEAN_NAME));
	}
}
 
Example #28
Source File: AbstractListenerContainerParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	CompositeComponentDefinition compositeDef =
			new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
	parserContext.pushContainingComponent(compositeDef);

	MutablePropertyValues commonProperties = parseCommonContainerProperties(element, parserContext);
	MutablePropertyValues specificProperties = parseSpecificContainerProperties(element, parserContext);

	String factoryId = element.getAttribute(FACTORY_ID_ATTRIBUTE);
	if (StringUtils.hasText(factoryId)) {
		RootBeanDefinition beanDefinition = createContainerFactory(
				factoryId, element, parserContext, commonProperties, specificProperties);
		if (beanDefinition != null) {
			beanDefinition.setSource(parserContext.extractSource(element));
			parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, factoryId));
		}
	}

	NodeList childNodes = element.getChildNodes();
	for (int i = 0; i < childNodes.getLength(); i++) {
		Node child = childNodes.item(i);
		if (child.getNodeType() == Node.ELEMENT_NODE) {
			String localName = parserContext.getDelegate().getLocalName(child);
			if (LISTENER_ELEMENT.equals(localName)) {
				parseListener(element, (Element) child, parserContext, commonProperties, specificProperties);
			}
		}
	}

	parserContext.popAndRegisterContainingComponent();
	return null;
}
 
Example #29
Source File: MvcNamespaceUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Registers a {@link SimpleControllerHandlerAdapter} under a well-known
 * name unless already registered.
 */
private static void registerSimpleControllerHandlerAdapter(ParserContext context, @Nullable Object source) {
	if (!context.getRegistry().containsBeanDefinition(SIMPLE_CONTROLLER_HANDLER_ADAPTER_BEAN_NAME)) {
		RootBeanDefinition beanDef = new RootBeanDefinition(SimpleControllerHandlerAdapter.class);
		beanDef.setSource(source);
		beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		context.getRegistry().registerBeanDefinition(SIMPLE_CONTROLLER_HANDLER_ADAPTER_BEAN_NAME, beanDef);
		context.registerComponent(new BeanComponentDefinition(beanDef, SIMPLE_CONTROLLER_HANDLER_ADAPTER_BEAN_NAME));
	}
}
 
Example #30
Source File: MvcNamespaceUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Registers  an {@link HandlerMappingIntrospector} under a well-known name
 * unless already registered.
 */
private static void registerHandlerMappingIntrospector(ParserContext parserContext, @Nullable Object source) {
	if (!parserContext.getRegistry().containsBeanDefinition(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME)){
		RootBeanDefinition beanDef = new RootBeanDefinition(HandlerMappingIntrospector.class);
		beanDef.setSource(source);
		beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		beanDef.setLazyInit(true);
		parserContext.getRegistry().registerBeanDefinition(HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME, beanDef);
		parserContext.registerComponent(new BeanComponentDefinition(beanDef, HANDLER_MAPPING_INTROSPECTOR_BEAN_NAME));
	}
}