Java Code Examples for org.springframework.beans.factory.support.RootBeanDefinition#setSource()

The following examples show how to use org.springframework.beans.factory.support.RootBeanDefinition#setSource() . 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: MvcNamespaceUtils.java    From lams with GNU General Public License v2.0 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(
		RuntimeBeanReference pathMatcherRef, ParserContext parserContext, 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 2
Source File: AopConfigUtils.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Nullable
private static BeanDefinition registerOrEscalateApcAsRequired(
		Class<?> cls, BeanDefinitionRegistry registry, @Nullable Object source) {

	Assert.notNull(registry, "BeanDefinitionRegistry must not be null");

	if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) {
		BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
		if (!cls.getName().equals(apcDefinition.getBeanClassName())) {
			int currentPriority = findPriorityForClass(apcDefinition.getBeanClassName());
			int requiredPriority = findPriorityForClass(cls);
			if (currentPriority < requiredPriority) {
				apcDefinition.setBeanClassName(cls.getName());
			}
		}
		return null;
	}

	RootBeanDefinition beanDefinition = new RootBeanDefinition(cls);
	beanDefinition.setSource(source);
	beanDefinition.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE);
	beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	registry.registerBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME, beanDefinition);
	return beanDefinition;
}
 
Example 3
Source File: ViewResolversBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private BeanDefinition createContentNegotiatingViewResolver(Element resolverElement, ParserContext context) {
	RootBeanDefinition beanDef = new RootBeanDefinition(ContentNegotiatingViewResolver.class);
	beanDef.setSource(context.extractSource(resolverElement));
	beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	MutablePropertyValues values = beanDef.getPropertyValues();

	List<Element> elements = DomUtils.getChildElementsByTagName(resolverElement, new String[] {"default-views"});
	if (!elements.isEmpty()) {
		ManagedList<Object> list = new ManagedList<Object>();
		for (Element element : DomUtils.getChildElementsByTagName(elements.get(0), "bean", "ref")) {
			list.add(context.getDelegate().parsePropertySubElement(element, null));
		}
		values.add("defaultViews", list);
	}
	if (resolverElement.hasAttribute("use-not-acceptable")) {
		values.add("useNotAcceptableStatusCode", resolverElement.getAttribute("use-not-acceptable"));
	}
	Object manager = MvcNamespaceUtils.getContentNegotiationManager(context);
	if (manager != null) {
		values.add("contentNegotiationManager", manager);
	}
	return beanDef;
}
 
Example 4
Source File: AopConfigUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private static BeanDefinition registerOrEscalateApcAsRequired(Class<?> cls, BeanDefinitionRegistry registry, Object source) {
	Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
	if (registry.containsBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME)) {
		BeanDefinition apcDefinition = registry.getBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME);
		if (!cls.getName().equals(apcDefinition.getBeanClassName())) {
			int currentPriority = findPriorityForClass(apcDefinition.getBeanClassName());
			int requiredPriority = findPriorityForClass(cls);
			if (currentPriority < requiredPriority) {
				apcDefinition.setBeanClassName(cls.getName());
			}
		}
		return null;
	}
	RootBeanDefinition beanDefinition = new RootBeanDefinition(cls);
	beanDefinition.setSource(source);
	beanDefinition.getPropertyValues().add("order", Ordered.HIGHEST_PRECEDENCE);
	beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	registry.registerBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME, beanDefinition);
	return beanDefinition;
}
 
Example 5
Source File: ConfigBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Create a {@link RootBeanDefinition} for the advisor described in the supplied. Does <strong>not</strong>
 * parse any associated '{@code pointcut}' or '{@code pointcut-ref}' attributes.
 */
private AbstractBeanDefinition createAdvisorBeanDefinition(Element advisorElement, ParserContext parserContext) {
	RootBeanDefinition advisorDefinition = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class);
	advisorDefinition.setSource(parserContext.extractSource(advisorElement));

	String adviceRef = advisorElement.getAttribute(ADVICE_REF);
	if (!StringUtils.hasText(adviceRef)) {
		parserContext.getReaderContext().error(
				"'advice-ref' attribute contains empty value.", advisorElement, this.parseState.snapshot());
	}
	else {
		advisorDefinition.getPropertyValues().add(
				ADVICE_BEAN_NAME, new RuntimeBeanNameReference(adviceRef));
	}

	if (advisorElement.hasAttribute(ORDER_PROPERTY)) {
		advisorDefinition.getPropertyValues().add(
				ORDER_PROPERTY, advisorElement.getAttribute(ORDER_PROPERTY));
	}

	return advisorDefinition;
}
 
Example 6
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 7
Source File: DefaultServletHandlerBeanDefinitionParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	String defaultServletName = element.getAttribute("default-servlet-name");
	RootBeanDefinition defaultServletHandlerDef = new RootBeanDefinition(DefaultServletHttpRequestHandler.class);
	defaultServletHandlerDef.setSource(source);
	defaultServletHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	if (StringUtils.hasText(defaultServletName)) {
		defaultServletHandlerDef.getPropertyValues().add("defaultServletName", defaultServletName);
	}
	String defaultServletHandlerName = parserContext.getReaderContext().generateBeanName(defaultServletHandlerDef);
	parserContext.getRegistry().registerBeanDefinition(defaultServletHandlerName, defaultServletHandlerDef);
	parserContext.registerComponent(new BeanComponentDefinition(defaultServletHandlerDef, defaultServletHandlerName));

	Map<String, String> urlMap = new ManagedMap<String, String>();
	urlMap.put("/**", defaultServletHandlerName);

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
	handlerMappingDef.setSource(source);
	handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	String handlerMappingBeanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef);
	parserContext.getRegistry().registerBeanDefinition(handlerMappingBeanName, handlerMappingDef);
	parserContext.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingBeanName));

	// Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off"
	MvcNamespaceUtils.registerDefaultComponents(parserContext, source);

	return null;
}
 
Example 8
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
public static void configureAutoProxyCreator(Element element, ParserContext parserContext) {
	AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element);

	String txAdvisorBeanName = TransactionManagementConfigUtils.TRANSACTION_ADVISOR_BEAN_NAME;
	if (!parserContext.getRegistry().containsBeanDefinition(txAdvisorBeanName)) {
		Object eleSource = parserContext.extractSource(element);

		// Create the TransactionAttributeSource definition.
		RootBeanDefinition sourceDef = new RootBeanDefinition(
				"org.springframework.transaction.annotation.AnnotationTransactionAttributeSource");
		sourceDef.setSource(eleSource);
		sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

		// Create the TransactionInterceptor definition.
		RootBeanDefinition interceptorDef = new RootBeanDefinition(TransactionInterceptor.class);
		interceptorDef.setSource(eleSource);
		interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		registerTransactionManager(element, interceptorDef);
		interceptorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName));
		String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

		// Create the TransactionAttributeSourceAdvisor definition.
		RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryTransactionAttributeSourceAdvisor.class);
		advisorDef.setSource(eleSource);
		advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		advisorDef.getPropertyValues().add("transactionAttributeSource", new RuntimeBeanReference(sourceName));
		advisorDef.getPropertyValues().add("adviceBeanName", interceptorName);
		if (element.hasAttribute("order")) {
			advisorDef.getPropertyValues().add("order", element.getAttribute("order"));
		}
		parserContext.getRegistry().registerBeanDefinition(txAdvisorBeanName, advisorDef);

		CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
		compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, txAdvisorBeanName));
		parserContext.registerComponent(compositeDef);
	}
}
 
Example 9
Source File: MvcNamespaceUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Registers  an {@link HttpRequestHandlerAdapter} under a well-known
 * name unless already registered.
 */
private static void registerBeanNameUrlHandlerMapping(ParserContext parserContext, Object source) {
	if (!parserContext.getRegistry().containsBeanDefinition(BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME)){
		RootBeanDefinition beanNameMappingDef = new RootBeanDefinition(BeanNameUrlHandlerMapping.class);
		beanNameMappingDef.setSource(source);
		beanNameMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		beanNameMappingDef.getPropertyValues().add("order", 2);	// consistent with WebMvcConfigurationSupport
		RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, parserContext, source);
		beanNameMappingDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef);
		parserContext.getRegistry().registerBeanDefinition(BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME, beanNameMappingDef);
		parserContext.registerComponent(new BeanComponentDefinition(beanNameMappingDef, BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME));
	}
}
 
Example 10
Source File: MvcNamespaceUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Registers  an {@link HttpRequestHandlerAdapter} under a well-known
 * name unless already registered.
 */
private static void registerHttpRequestHandlerAdapter(ParserContext parserContext, Object source) {
	if (!parserContext.getRegistry().containsBeanDefinition(HTTP_REQUEST_HANDLER_ADAPTER_BEAN_NAME)) {
		RootBeanDefinition handlerAdapterDef = new RootBeanDefinition(HttpRequestHandlerAdapter.class);
		handlerAdapterDef.setSource(source);
		handlerAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parserContext.getRegistry().registerBeanDefinition(HTTP_REQUEST_HANDLER_ADAPTER_BEAN_NAME, handlerAdapterDef);
		parserContext.registerComponent(new BeanComponentDefinition(handlerAdapterDef, HTTP_REQUEST_HANDLER_ADAPTER_BEAN_NAME));
	}
}
 
Example 11
Source File: SolrRepositoryConfigExtension.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private void registerSolrMappingContextIfNotPresent(BeanDefinitionRegistry registry,
		RepositoryConfigurationSource configurationSource) {

	RootBeanDefinition definition = new RootBeanDefinition(SimpleSolrMappingContext.class);
	definition.setRole(AbstractBeanDefinition.ROLE_INFRASTRUCTURE);
	definition.setSource(configurationSource.getSource());

	registerIfNotAlreadyRegistered(definition, registry, BeanDefinition.SOLR_MAPPTING_CONTEXT.getBeanName(),
			definition);
}
 
Example 12
Source File: AbstractStoreBeanDefinitionRegistrar.java    From spring-content with Apache License 2.0 5 votes vote down vote up
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
	Assert.notNull(importingClassMetadata, "AnnotationMetadata must not be null!");
	Assert.notNull(registry, "BeanDefinitionRegistry must not be null!");
	Assert.isTrue(registry instanceof ConfigurableListableBeanFactory, "BeanDefinitionRegistry must be instance of ConfigurableListableBeanFactory");

	// Guard against calls for sub-classes
	// if (importingClassMetadata.getAnnotationAttributes(getAnnotation().getName())
	// == null) {
	// return;
	// }

	RootBeanDefinition repositoryInterfacePostProcessor = new RootBeanDefinition(REPOSITORY_INTERFACE_POST_PROCESSOR);
	repositoryInterfacePostProcessor.setSource(importingClassMetadata);
	if (registry.containsBeanDefinition(REPOSITORY_INTERFACE_POST_PROCESSOR) == false) {
		registry.registerBeanDefinition(REPOSITORY_INTERFACE_POST_PROCESSOR,repositoryInterfacePostProcessor);
	}

	BeanDefinition storeServiceBeanDef = createBeanDefinition(ContentStoreServiceImpl.class);
	if (registry.containsBeanDefinition("contentStoreService") == false) {
		registry.registerBeanDefinition("contentStoreService", storeServiceBeanDef);
	}

	BeanDefinition annotatedStoreEventHandlerDef = createBeanDefinition(AnnotatedStoreEventInvoker.class);
	if (registry.containsBeanDefinition("annotatedStoreEventHandler") == false) {
		registry.registerBeanDefinition("annotatedStoreEventHandler", annotatedStoreEventHandlerDef);
	}

	if (registry.containsBeanDefinition("renditionService") == false) {
		BeanDefinition renditionServiceBeanDef = createBeanDefinition(RenditionServiceImpl.class);
		registry.registerBeanDefinition("renditionService", renditionServiceBeanDef);
	}

	createOperationsBean(registry);

	registerContentStoreBeanDefinitions(importingClassMetadata, registry);
}
 
Example 13
Source File: AnnotationDrivenCacheBeanDefinitionParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static void registerCacheAdvisor(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)) {
		Object eleSource = parserContext.extractSource(element);

		// Create the CacheOperationSource definition.
		RootBeanDefinition sourceDef = new RootBeanDefinition("org.springframework.cache.annotation.AnnotationCacheOperationSource");
		sourceDef.setSource(eleSource);
		sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

		// Create the CacheInterceptor definition.
		RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class);
		interceptorDef.setSource(eleSource);
		interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parseCacheResolution(element, interceptorDef, false);
		parseErrorHandler(element, interceptorDef);
		CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef);
		interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName));
		String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

		// Create the CacheAdvisor definition.
		RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class);
		advisorDef.setSource(eleSource);
		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.CACHE_ADVISOR_BEAN_NAME, advisorDef);

		CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
		compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME));
		parserContext.registerComponent(compositeDef);
	}
}
 
Example 14
Source File: JmsListenerContainerParser.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
protected RootBeanDefinition createContainer(Element containerEle, Element listenerEle, ParserContext parserContext,
		PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {

	RootBeanDefinition containerDef = new RootBeanDefinition();
	containerDef.setSource(parserContext.extractSource(containerEle));
	containerDef.getPropertyValues().addPropertyValues(commonContainerProperties);
	containerDef.getPropertyValues().addPropertyValues(specificContainerProperties);

	String containerType = containerEle.getAttribute(CONTAINER_TYPE_ATTRIBUTE);
	String containerClass = containerEle.getAttribute(CONTAINER_CLASS_ATTRIBUTE);
	if (!"".equals(containerClass)) {
		containerDef.setBeanClassName(containerClass);
	}
	else if ("".equals(containerType) || containerType.startsWith("default")) {
		containerDef.setBeanClassName("org.springframework.jms.listener.DefaultMessageListenerContainer");
	}
	else if (containerType.startsWith("simple")) {
		containerDef.setBeanClassName("org.springframework.jms.listener.SimpleMessageListenerContainer");
	}
	else {
		parserContext.getReaderContext().error(
				"Invalid 'container-type' attribute: only \"default\" and \"simple\" supported.", containerEle);
	}

	// Parse listener specific settings
	parseListenerConfiguration(listenerEle, parserContext, containerDef.getPropertyValues());

	return containerDef;
}
 
Example 15
Source File: AbstractListenerContainerParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	CompositeComponentDefinition compositeDef =
			new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
	parserContext.pushContainingComponent(compositeDef);

	PropertyValues commonProperties = parseCommonContainerProperties(element, parserContext);
	PropertyValues 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 16
Source File: AnnotationDrivenCacheBeanDefinitionParser.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static void registerCacheAdvisor(Element element, ParserContext parserContext) {
	if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME)) {
		Object eleSource = parserContext.extractSource(element);

		// Create the CacheOperationSource definition.
		RootBeanDefinition sourceDef = new RootBeanDefinition("org.springframework.cache.annotation.AnnotationCacheOperationSource");
		sourceDef.setSource(eleSource);
		sourceDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef);

		// Create the CacheInterceptor definition.
		RootBeanDefinition interceptorDef = new RootBeanDefinition(CacheInterceptor.class);
		interceptorDef.setSource(eleSource);
		interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parseCacheResolution(element, interceptorDef, false);
		parseErrorHandler(element, interceptorDef);
		CacheNamespaceHandler.parseKeyGenerator(element, interceptorDef);
		interceptorDef.getPropertyValues().add("cacheOperationSources", new RuntimeBeanReference(sourceName));
		String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef);

		// Create the CacheAdvisor definition.
		RootBeanDefinition advisorDef = new RootBeanDefinition(BeanFactoryCacheOperationSourceAdvisor.class);
		advisorDef.setSource(eleSource);
		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.CACHE_ADVISOR_BEAN_NAME, advisorDef);

		CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), eleSource);
		compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
		compositeDef.addNestedComponent(new BeanComponentDefinition(advisorDef, CacheManagementConfigUtils.CACHE_ADVISOR_BEAN_NAME));
		parserContext.registerComponent(compositeDef);
	}
}
 
Example 17
Source File: MvcNamespaceUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Registers  an {@link HttpRequestHandlerAdapter} under a well-known
 * name unless already registered.
 */
private static void registerHttpRequestHandlerAdapter(ParserContext parserContext, Object source) {
	if (!parserContext.getRegistry().containsBeanDefinition(HTTP_REQUEST_HANDLER_ADAPTER_BEAN_NAME)) {
		RootBeanDefinition handlerAdapterDef = new RootBeanDefinition(HttpRequestHandlerAdapter.class);
		handlerAdapterDef.setSource(source);
		handlerAdapterDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
		parserContext.getRegistry().registerBeanDefinition(HTTP_REQUEST_HANDLER_ADAPTER_BEAN_NAME, handlerAdapterDef);
		parserContext.registerComponent(new BeanComponentDefinition(handlerAdapterDef, HTTP_REQUEST_HANDLER_ADAPTER_BEAN_NAME));
	}
}
 
Example 18
Source File: TxAdviceBeanDefinitionParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext parserContext) {
	List<Element> methods = DomUtils.getChildElementsByTagName(attrEle, METHOD_ELEMENT);
	ManagedMap<TypedStringValue, RuleBasedTransactionAttribute> transactionAttributeMap =
			new ManagedMap<>(methods.size());
	transactionAttributeMap.setSource(parserContext.extractSource(attrEle));

	for (Element methodEle : methods) {
		String name = methodEle.getAttribute(METHOD_NAME_ATTRIBUTE);
		TypedStringValue nameHolder = new TypedStringValue(name);
		nameHolder.setSource(parserContext.extractSource(methodEle));

		RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute();
		String propagation = methodEle.getAttribute(PROPAGATION_ATTRIBUTE);
		String isolation = methodEle.getAttribute(ISOLATION_ATTRIBUTE);
		String timeout = methodEle.getAttribute(TIMEOUT_ATTRIBUTE);
		String readOnly = methodEle.getAttribute(READ_ONLY_ATTRIBUTE);
		if (StringUtils.hasText(propagation)) {
			attribute.setPropagationBehaviorName(RuleBasedTransactionAttribute.PREFIX_PROPAGATION + propagation);
		}
		if (StringUtils.hasText(isolation)) {
			attribute.setIsolationLevelName(RuleBasedTransactionAttribute.PREFIX_ISOLATION + isolation);
		}
		if (StringUtils.hasText(timeout)) {
			try {
				attribute.setTimeout(Integer.parseInt(timeout));
			}
			catch (NumberFormatException ex) {
				parserContext.getReaderContext().error("Timeout must be an integer value: [" + timeout + "]", methodEle);
			}
		}
		if (StringUtils.hasText(readOnly)) {
			attribute.setReadOnly(Boolean.valueOf(methodEle.getAttribute(READ_ONLY_ATTRIBUTE)));
		}

		List<RollbackRuleAttribute> rollbackRules = new LinkedList<>();
		if (methodEle.hasAttribute(ROLLBACK_FOR_ATTRIBUTE)) {
			String rollbackForValue = methodEle.getAttribute(ROLLBACK_FOR_ATTRIBUTE);
			addRollbackRuleAttributesTo(rollbackRules,rollbackForValue);
		}
		if (methodEle.hasAttribute(NO_ROLLBACK_FOR_ATTRIBUTE)) {
			String noRollbackForValue = methodEle.getAttribute(NO_ROLLBACK_FOR_ATTRIBUTE);
			addNoRollbackRuleAttributesTo(rollbackRules,noRollbackForValue);
		}
		attribute.setRollbackRules(rollbackRules);

		transactionAttributeMap.put(nameHolder, attribute);
	}

	RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(NameMatchTransactionAttributeSource.class);
	attributeSourceDefinition.setSource(parserContext.extractSource(attrEle));
	attributeSourceDefinition.getPropertyValues().add("nameMap", transactionAttributeMap);
	return attributeSourceDefinition;
}
 
Example 19
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private RootBeanDefinition createConverterDefinition(Class<?> converterClass, @Nullable Object source) {
	RootBeanDefinition beanDefinition = new RootBeanDefinition(converterClass);
	beanDefinition.setSource(source);
	beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	return beanDefinition;
}
 
Example 20
Source File: ViewControllerBeanDefinitionParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public BeanDefinition parse(Element element, ParserContext parserContext) {
	Object source = parserContext.extractSource(element);

	// Register SimpleUrlHandlerMapping for view controllers
	BeanDefinition hm = registerHandlerMapping(parserContext, source);

	// Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off"
	MvcNamespaceUtils.registerDefaultComponents(parserContext, source);

	// Create view controller bean definition
	RootBeanDefinition controller = new RootBeanDefinition(ParameterizableViewController.class);
	controller.setSource(source);

	HttpStatus statusCode = null;
	if (element.hasAttribute("status-code")) {
		int statusValue = Integer.parseInt(element.getAttribute("status-code"));
		statusCode = HttpStatus.valueOf(statusValue);
	}

	String name = element.getLocalName();
	if (name.equals("view-controller")) {
		if (element.hasAttribute("view-name")) {
			controller.getPropertyValues().add("viewName", element.getAttribute("view-name"));
		}
		if (statusCode != null) {
			controller.getPropertyValues().add("statusCode", statusCode);
		}
	}
	else if (name.equals("redirect-view-controller")) {
		controller.getPropertyValues().add("view", getRedirectView(element, statusCode, source));
	}
	else if (name.equals("status-controller")) {
		controller.getPropertyValues().add("statusCode", statusCode);
		controller.getPropertyValues().add("statusOnly", true);
	}
	else {
		// Should never happen...
		throw new IllegalStateException("Unexpected tag name: " + name);
	}

	Map<String, BeanDefinition> urlMap = (Map<String, BeanDefinition>) hm.getPropertyValues().get("urlMap");
	if (urlMap == null) {
		urlMap = new ManagedMap<>();
		hm.getPropertyValues().add("urlMap", urlMap);
	}
	urlMap.put(element.getAttribute("path"), controller);

	return null;
}