Java Code Examples for org.springframework.beans.factory.xml.ParserContext#extractSource()
The following examples show how to use
org.springframework.beans.factory.xml.ParserContext#extractSource() .
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: AnnotationConfigBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 6 votes |
@Override 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 2
Source File: AnnotationConfigBeanDefinitionParser.java From spring-analysis-note with MIT License | 6 votes |
@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 3
Source File: RedissonDefinitionParser.java From redisson with Apache License 2.0 | 6 votes |
private void parseChildElements(Element element, String parentId, String redissonRef, BeanDefinitionBuilder redissonDef, ParserContext parserContext) { if (element.hasChildNodes()) { CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(parentId, parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); List<Element> childElts = DomUtils.getChildElements(element); for (Element elt : childElts) { if (BeanDefinitionParserDelegate.QUALIFIER_ELEMENT.equals(elt.getLocalName())) { continue; //parsed elsewhere } String localName = parserContext.getDelegate().getLocalName(elt); localName = Conventions.attributeNameToPropertyName(localName); if (ConfigType.contains(localName)) { parseConfigTypes(elt, localName, redissonDef, parserContext); } else if (AddressType.contains(localName)) { parseAddressTypes(elt, localName, redissonDef, parserContext); } else if (helper.isRedissonNS(elt)) { elt.setAttribute(REDISSON_REF, redissonRef); parserContext.getDelegate().parseCustomElement(elt); } } parserContext.popContainingComponent(); } }
Example 4
Source File: ConfigBeanDefinitionParser.java From spring-analysis-note with MIT License | 6 votes |
@Override @Nullable public BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); configureAutoProxyCreator(parserContext, element); List<Element> childElts = DomUtils.getChildElements(element); for (Element elt: childElts) { String localName = parserContext.getDelegate().getLocalName(elt); if (POINTCUT.equals(localName)) { parsePointcut(elt, parserContext); } else if (ADVISOR.equals(localName)) { parseAdvisor(elt, parserContext); } else if (ASPECT.equals(localName)) { parseAspect(elt, parserContext); } } parserContext.popAndRegisterContainingComponent(); return null; }
Example 5
Source File: AnnotationDrivenCacheBeanDefinitionParser.java From java-technology-stack with MIT License | 5 votes |
private static void registerCacheAspect(Element element, ParserContext parserContext) { if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME)) { Object eleSource = parserContext.extractSource(element); RootBeanDefinition def = new RootBeanDefinition(); def.setBeanClassName(JCACHE_ASPECT_CLASS_NAME); def.setFactoryMethodName("aspectOf"); BeanDefinition sourceDef = createJCacheOperationSourceBeanDefinition(element, eleSource); String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef); def.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName)); parserContext.registerBeanComponent(new BeanComponentDefinition(sourceDef, sourceName)); parserContext.registerBeanComponent(new BeanComponentDefinition(def, CacheManagementConfigUtils.JCACHE_ASPECT_BEAN_NAME)); } }
Example 6
Source File: AnnotationDrivenCacheBeanDefinitionParser.java From java-technology-stack with MIT License | 5 votes |
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 7
Source File: DefaultServletHandlerBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 5 votes |
@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: AbstractListenerContainerParser.java From java-technology-stack with MIT License | 5 votes |
@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 9
Source File: DefaultsBeanDefinitionParser.java From jdal with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); CompositeComponentDefinition ccd = new CompositeComponentDefinition("jdal-vaadin", source); ccd.addNestedComponent(registerPropertyEditors(element, parserContext)); ccd.addNestedComponent(registerPaginatorView(element, parserContext)); ccd.addNestedComponent(registerDefaultTableActions(element, parserContext)); ccd.addNestedComponent(registerDefaultGuiFactory(element, parserContext)); parserContext.getReaderContext().fireComponentRegistered(ccd); return null; }
Example 10
Source File: AnnotationDrivenCacheBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 5 votes |
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 11
Source File: AnnotationDrivenBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 5 votes |
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 12
Source File: DefaultServletHandlerBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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 13
Source File: ResourcesBeanDefinitionParser.java From spring-analysis-note with MIT License | 4 votes |
@Override public BeanDefinition parse(Element element, ParserContext context) { Object source = context.extractSource(element); registerUrlProvider(context, source); RuntimeBeanReference pathMatcherRef = MvcNamespaceUtils.registerPathMatcher(null, context, source); RuntimeBeanReference pathHelperRef = MvcNamespaceUtils.registerUrlPathHelper(null, context, source); String resourceHandlerName = registerResourceHandler(context, element, pathHelperRef, source); if (resourceHandlerName == null) { return null; } Map<String, String> urlMap = new ManagedMap<>(); String resourceRequestPath = element.getAttribute("mapping"); if (!StringUtils.hasText(resourceRequestPath)) { context.getReaderContext().error("The 'mapping' attribute is required.", context.extractSource(element)); return null; } urlMap.put(resourceRequestPath, resourceHandlerName); RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class); handlerMappingDef.setSource(source); handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); handlerMappingDef.getPropertyValues().add("urlMap", urlMap); handlerMappingDef.getPropertyValues().add("pathMatcher", pathMatcherRef).add("urlPathHelper", pathHelperRef); String orderValue = element.getAttribute("order"); // Use a default of near-lowest precedence, still allowing for even lower precedence in other mappings Object order = StringUtils.hasText(orderValue) ? orderValue : Ordered.LOWEST_PRECEDENCE - 1; handlerMappingDef.getPropertyValues().add("order", order); RuntimeBeanReference corsRef = MvcNamespaceUtils.registerCorsConfigurations(null, context, source); handlerMappingDef.getPropertyValues().add("corsConfigurations", corsRef); String beanName = context.getReaderContext().generateBeanName(handlerMappingDef); context.getRegistry().registerBeanDefinition(beanName, handlerMappingDef); context.registerComponent(new BeanComponentDefinition(handlerMappingDef, beanName)); // Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off" // Register HttpRequestHandlerAdapter MvcNamespaceUtils.registerDefaultComponents(context, source); return null; }
Example 14
Source File: HandlersBeanDefinitionParser.java From spring-analysis-note with MIT License | 4 votes |
@Override @Nullable public BeanDefinition parse(Element element, ParserContext context) { Object source = context.extractSource(element); CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source); context.pushContainingComponent(compDefinition); String orderAttribute = element.getAttribute("order"); int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute); RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class); handlerMappingDef.setSource(source); handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); handlerMappingDef.getPropertyValues().add("order", order); String handlerMappingName = context.getReaderContext().registerWithGeneratedName(handlerMappingDef); RuntimeBeanReference sockJsService = WebSocketNamespaceUtils.registerSockJsService( element, SOCK_JS_SCHEDULER_NAME, context, source); HandlerMappingStrategy strategy; if (sockJsService != null) { strategy = new SockJsHandlerMappingStrategy(sockJsService); } else { RuntimeBeanReference handler = WebSocketNamespaceUtils.registerHandshakeHandler(element, context, source); Element interceptElem = DomUtils.getChildElementByTagName(element, "handshake-interceptors"); ManagedList<Object> interceptors = WebSocketNamespaceUtils.parseBeanSubElements(interceptElem, context); String allowedOrigins = element.getAttribute("allowed-origins"); List<String> origins = Arrays.asList(StringUtils.tokenizeToStringArray(allowedOrigins, ",")); interceptors.add(new OriginHandshakeInterceptor(origins)); strategy = new WebSocketHandlerMappingStrategy(handler, interceptors); } ManagedMap<String, Object> urlMap = new ManagedMap<>(); urlMap.setSource(source); for (Element mappingElement : DomUtils.getChildElementsByTagName(element, "mapping")) { strategy.addMapping(mappingElement, urlMap, context); } handlerMappingDef.getPropertyValues().add("urlMap", urlMap); context.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingName)); context.popAndRegisterContainingComponent(); return null; }
Example 15
Source File: ViewControllerBeanDefinitionParser.java From spring-analysis-note with MIT License | 4 votes |
@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; }
Example 16
Source File: AnnotationDrivenJmsBeanDefinitionParser.java From spring-analysis-note with MIT License | 4 votes |
@Override @Nullable public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Register component for the surrounding <jms: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(); if (registry.containsBeanDefinition(JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)) { parserContext.getReaderContext().error( "Only one JmsListenerAnnotationBeanPostProcessor may exist within the context.", source); } else { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor"); builder.getRawBeanDefinition().setSource(source); String endpointRegistry = element.getAttribute("registry"); if (StringUtils.hasText(endpointRegistry)) { builder.addPropertyReference("endpointRegistry", endpointRegistry); } else { registerDefaultEndpointRegistry(source, parserContext); } String containerFactory = element.getAttribute("container-factory"); if (StringUtils.hasText(containerFactory)) { builder.addPropertyValue("containerFactoryBeanName", containerFactory); } String handlerMethodFactory = element.getAttribute("handler-method-factory"); if (StringUtils.hasText(handlerMethodFactory)) { builder.addPropertyReference("messageHandlerMethodFactory", handlerMethodFactory); } registerInfrastructureBean(parserContext, builder, JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME); } // Finally register the composite component. parserContext.popAndRegisterContainingComponent(); return null; }
Example 17
Source File: MessageBrokerBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public BeanDefinition parse(Element element, ParserContext context) { Object source = context.extractSource(element); CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source); context.pushContainingComponent(compDefinition); Element channelElem = DomUtils.getChildElementByTagName(element, "client-inbound-channel"); RuntimeBeanReference inChannel = getMessageChannel("clientInboundChannel", channelElem, context, source); channelElem = DomUtils.getChildElementByTagName(element, "client-outbound-channel"); RuntimeBeanReference outChannel = getMessageChannel("clientOutboundChannel", channelElem, context, source); channelElem = DomUtils.getChildElementByTagName(element, "broker-channel"); RuntimeBeanReference brokerChannel = getMessageChannel("brokerChannel", channelElem, context, source); RuntimeBeanReference userRegistry = registerUserRegistry(element, context, source); Object userDestHandler = registerUserDestHandler(element, userRegistry, inChannel, brokerChannel, context, source); RuntimeBeanReference converter = registerMessageConverter(element, context, source); RuntimeBeanReference template = registerMessagingTemplate(element, brokerChannel, converter, context, source); registerAnnotationMethodMessageHandler(element, inChannel, outChannel,converter, template, context, source); RootBeanDefinition broker = registerMessageBroker(element, inChannel, outChannel, brokerChannel, userDestHandler, template, userRegistry, context, source); // WebSocket and sub-protocol handling ManagedMap<String, Object> urlMap = registerHandlerMapping(element, context, source); RuntimeBeanReference stompHandler = registerStompHandler(element, inChannel, outChannel, context, source); for (Element endpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) { RuntimeBeanReference requestHandler = registerRequestHandler(endpointElem, stompHandler, context, source); String pathAttribute = endpointElem.getAttribute("path"); Assert.state(StringUtils.hasText(pathAttribute), "Invalid <stomp-endpoint> (no path mapping)"); List<String> paths = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ",")); for (String path : paths) { path = path.trim(); Assert.state(StringUtils.hasText(path), "Invalid <stomp-endpoint> path attribute: " + pathAttribute); if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) { path = path.endsWith("/") ? path + "**" : path + "/**"; } urlMap.put(path, requestHandler); } } Map<String, Object> scopeMap = Collections.<String, Object>singletonMap("websocket", new SimpSessionScope()); RootBeanDefinition scopeConfigurer = new RootBeanDefinition(CustomScopeConfigurer.class); scopeConfigurer.getPropertyValues().add("scopes", scopeMap); registerBeanDefByName("webSocketScopeConfigurer", scopeConfigurer, context, source); registerWebSocketMessageBrokerStats(broker, inChannel, outChannel, context, source); context.popAndRegisterContainingComponent(); return null; }
Example 18
Source File: HandlersBeanDefinitionParser.java From java-technology-stack with MIT License | 4 votes |
@Override @Nullable public BeanDefinition parse(Element element, ParserContext context) { Object source = context.extractSource(element); CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source); context.pushContainingComponent(compDefinition); String orderAttribute = element.getAttribute("order"); int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute); RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class); handlerMappingDef.setSource(source); handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); handlerMappingDef.getPropertyValues().add("order", order); String handlerMappingName = context.getReaderContext().registerWithGeneratedName(handlerMappingDef); RuntimeBeanReference sockJsService = WebSocketNamespaceUtils.registerSockJsService( element, SOCK_JS_SCHEDULER_NAME, context, source); HandlerMappingStrategy strategy; if (sockJsService != null) { strategy = new SockJsHandlerMappingStrategy(sockJsService); } else { RuntimeBeanReference handler = WebSocketNamespaceUtils.registerHandshakeHandler(element, context, source); Element interceptElem = DomUtils.getChildElementByTagName(element, "handshake-interceptors"); ManagedList<Object> interceptors = WebSocketNamespaceUtils.parseBeanSubElements(interceptElem, context); String allowedOrigins = element.getAttribute("allowed-origins"); List<String> origins = Arrays.asList(StringUtils.tokenizeToStringArray(allowedOrigins, ",")); interceptors.add(new OriginHandshakeInterceptor(origins)); strategy = new WebSocketHandlerMappingStrategy(handler, interceptors); } ManagedMap<String, Object> urlMap = new ManagedMap<>(); urlMap.setSource(source); for (Element mappingElement : DomUtils.getChildElementsByTagName(element, "mapping")) { strategy.addMapping(mappingElement, urlMap, context); } handlerMappingDef.getPropertyValues().add("urlMap", urlMap); context.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingName)); context.popAndRegisterContainingComponent(); return null; }
Example 19
Source File: ResourcesBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); registerUrlProvider(parserContext, source); String resourceHandlerName = registerResourceHandler(parserContext, element, source); if (resourceHandlerName == null) { return null; } Map<String, String> urlMap = new ManagedMap<String, String>(); String resourceRequestPath = element.getAttribute("mapping"); if (!StringUtils.hasText(resourceRequestPath)) { parserContext.getReaderContext().error("The 'mapping' attribute is required.", parserContext.extractSource(element)); return null; } urlMap.put(resourceRequestPath, resourceHandlerName); RuntimeBeanReference pathMatcherRef = MvcNamespaceUtils.registerPathMatcher(null, parserContext, source); RuntimeBeanReference pathHelperRef = MvcNamespaceUtils.registerUrlPathHelper(null, parserContext, source); RootBeanDefinition handlerMappingDef = new RootBeanDefinition(SimpleUrlHandlerMapping.class); handlerMappingDef.setSource(source); handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); handlerMappingDef.getPropertyValues().add("urlMap", urlMap); handlerMappingDef.getPropertyValues().add("pathMatcher", pathMatcherRef).add("urlPathHelper", pathHelperRef); String order = element.getAttribute("order"); // Use a default of near-lowest precedence, still allowing for even lower precedence in other mappings handlerMappingDef.getPropertyValues().add("order", StringUtils.hasText(order) ? order : Ordered.LOWEST_PRECEDENCE - 1); RuntimeBeanReference corsConfigurationsRef = MvcNamespaceUtils.registerCorsConfigurations(null, parserContext, source); handlerMappingDef.getPropertyValues().add("corsConfigurations", corsConfigurationsRef); String beanName = parserContext.getReaderContext().generateBeanName(handlerMappingDef); parserContext.getRegistry().registerBeanDefinition(beanName, handlerMappingDef); parserContext.registerComponent(new BeanComponentDefinition(handlerMappingDef, beanName)); // Ensure BeanNameUrlHandlerMapping (SPR-8289) and default HandlerAdapters are not "turned off" // Register HttpRequestHandlerAdapter MvcNamespaceUtils.registerDefaultComponents(parserContext, source); return null; }
Example 20
Source File: HandlersBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public BeanDefinition parse(Element element, ParserContext context) { Object source = context.extractSource(element); CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source); context.pushContainingComponent(compDefinition); String orderAttribute = element.getAttribute("order"); int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute); RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class); handlerMappingDef.setSource(source); handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); handlerMappingDef.getPropertyValues().add("order", order); String handlerMappingName = context.getReaderContext().registerWithGeneratedName(handlerMappingDef); RuntimeBeanReference sockJsService = WebSocketNamespaceUtils.registerSockJsService( element, SOCK_JS_SCHEDULER_NAME, context, source); HandlerMappingStrategy strategy; if (sockJsService != null) { strategy = new SockJsHandlerMappingStrategy(sockJsService); } else { RuntimeBeanReference handshakeHandler = WebSocketNamespaceUtils.registerHandshakeHandler(element, context, source); Element interceptorsElement = DomUtils.getChildElementByTagName(element, "handshake-interceptors"); ManagedList<? super Object> interceptors = WebSocketNamespaceUtils.parseBeanSubElements(interceptorsElement, context); String allowedOriginsAttribute = element.getAttribute("allowed-origins"); List<String> allowedOrigins = Arrays.asList(StringUtils.tokenizeToStringArray(allowedOriginsAttribute, ",")); interceptors.add(new OriginHandshakeInterceptor(allowedOrigins)); strategy = new WebSocketHandlerMappingStrategy(handshakeHandler, interceptors); } ManagedMap<String, Object> urlMap = new ManagedMap<String, Object>(); urlMap.setSource(source); for (Element mappingElement : DomUtils.getChildElementsByTagName(element, "mapping")) { strategy.addMapping(mappingElement, urlMap, context); } handlerMappingDef.getPropertyValues().add("urlMap", urlMap); context.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingName)); context.popAndRegisterContainingComponent(); return null; }