Java Code Examples for org.springframework.beans.factory.xml.ParserContext#pushContainingComponent()
The following examples show how to use
org.springframework.beans.factory.xml.ParserContext#pushContainingComponent() .
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 spring4-understanding with Apache License 2.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: ConfigBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override 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 4
Source File: ConfigBeanDefinitionParser.java From java-technology-stack 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: ConfigBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 6 votes |
@Override 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 6
Source File: AnnotationConfigBeanDefinitionParser.java From java-technology-stack 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 7
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 8
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 9
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 10
Source File: AbstractListenerContainerParser.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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 11
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 12
Source File: ServiceBeanDefinitionParser.java From jdal with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public AbstractBeanDefinition parse(Element element, ParserContext parserContext) { // default dao and service classes String daoClassName = JPA_DAO_CLASS_NAME; String serviceClassName = PERSISTENT_SERVICE_CLASS_NAME; String name = null; boolean declareService = false; if (element.hasAttribute(DAO_CLASS)) daoClassName = element.getAttribute(DAO_CLASS); if (element.hasAttribute(SERVICE_CLASS)) { serviceClassName = element.getAttribute(SERVICE_CLASS); declareService = true; } if (element.hasAttribute(NAME)) name = element.getAttribute(NAME); if (element.hasAttribute(ENTITY)) { String className = element.getAttribute(ENTITY); if (name == null) { name = StringUtils.uncapitalize( StringUtils.substringAfterLast(className, PropertyUtils.PROPERTY_SEPARATOR)); } parserContext.pushContainingComponent( new CompositeComponentDefinition(name, parserContext.extractSource(element))); // Dao BeanDefinitionBuilder daoBuilder = BeanDefinitionBuilder.genericBeanDefinition(daoClassName); NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), CRITERIA); if (nl.getLength() > 0) { ManagedMap<String, BeanReference> builders = new ManagedMap<String, BeanReference>(nl.getLength()); for (int i = 0; i < nl.getLength(); i++) { Element e = (Element) nl.item(i); builders.put(e.getAttribute(NAME), new RuntimeBeanReference(e.getAttribute(BUILDER))); } daoBuilder.addPropertyValue(CRITERIA_BUILDER_MAP, builders); } daoBuilder.addConstructorArgValue(ClassUtils.resolveClassName(className, null)); daoBuilder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); String daoBeanName; if (declareService) { // use dao suffix daoBeanName = name + DAO_SUFFIX; registerBeanDefinition(parserContext, daoBuilder, daoBeanName); // register service wrapper String serviceBeanName = name + SERVICE_SUFFIX; BeanDefinitionBuilder serviceBuilder = BeanDefinitionBuilder.genericBeanDefinition(serviceClassName); serviceBuilder.addPropertyReference("dao", daoBeanName); registerBeanDefinition(parserContext, serviceBuilder, serviceBeanName); } else { // use service suffix for dao and declare an alias with dao suffix for compatibility with older api. daoBeanName = name + SERVICE_SUFFIX; String[] aliases = new String[] { name + DAO_SUFFIX }; BeanComponentDefinition bcd = new BeanComponentDefinition(daoBuilder.getBeanDefinition(), daoBeanName, aliases); parserContext.registerBeanComponent(bcd); } parserContext.popAndRegisterContainingComponent(); } return null; }
Example 13
Source File: ConfigBeanDefinitionParser.java From lams with GNU General Public License v2.0 | 4 votes |
private void parseAspect(Element aspectElement, ParserContext parserContext) { String aspectId = aspectElement.getAttribute(ID); String aspectName = aspectElement.getAttribute(REF); try { this.parseState.push(new AspectEntry(aspectId, aspectName)); List<BeanDefinition> beanDefinitions = new ArrayList<BeanDefinition>(); List<BeanReference> beanReferences = new ArrayList<BeanReference>(); List<Element> declareParents = DomUtils.getChildElementsByTagName(aspectElement, DECLARE_PARENTS); for (int i = METHOD_INDEX; i < declareParents.size(); i++) { Element declareParentsElement = declareParents.get(i); beanDefinitions.add(parseDeclareParents(declareParentsElement, parserContext)); } // We have to parse "advice" and all the advice kinds in one loop, to get the // ordering semantics right. NodeList nodeList = aspectElement.getChildNodes(); boolean adviceFoundAlready = false; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (isAdviceNode(node, parserContext)) { if (!adviceFoundAlready) { adviceFoundAlready = true; if (!StringUtils.hasText(aspectName)) { parserContext.getReaderContext().error( "<aspect> tag needs aspect bean reference via 'ref' attribute when declaring advices.", aspectElement, this.parseState.snapshot()); return; } beanReferences.add(new RuntimeBeanReference(aspectName)); } AbstractBeanDefinition advisorDefinition = parseAdvice( aspectName, i, aspectElement, (Element) node, parserContext, beanDefinitions, beanReferences); beanDefinitions.add(advisorDefinition); } } AspectComponentDefinition aspectComponentDefinition = createAspectComponentDefinition( aspectElement, aspectId, beanDefinitions, beanReferences, parserContext); parserContext.pushContainingComponent(aspectComponentDefinition); List<Element> pointcuts = DomUtils.getChildElementsByTagName(aspectElement, POINTCUT); for (Element pointcutElement : pointcuts) { parsePointcut(pointcutElement, parserContext); } parserContext.popAndRegisterContainingComponent(); } finally { this.parseState.pop(); } }
Example 14
Source File: AnnotationDrivenJmsBeanDefinitionParser.java From java-technology-stack 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 15
Source File: AnnotationDrivenJmsBeanDefinitionParser.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override 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 16
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; }
Example 17
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 18
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 19
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 20
Source File: ConfigBeanDefinitionParser.java From spring-analysis-note with MIT License | 4 votes |
private void parseAspect(Element aspectElement, ParserContext parserContext) { String aspectId = aspectElement.getAttribute(ID); String aspectName = aspectElement.getAttribute(REF); try { this.parseState.push(new AspectEntry(aspectId, aspectName)); List<BeanDefinition> beanDefinitions = new ArrayList<>(); List<BeanReference> beanReferences = new ArrayList<>(); List<Element> declareParents = DomUtils.getChildElementsByTagName(aspectElement, DECLARE_PARENTS); for (int i = METHOD_INDEX; i < declareParents.size(); i++) { Element declareParentsElement = declareParents.get(i); beanDefinitions.add(parseDeclareParents(declareParentsElement, parserContext)); } // We have to parse "advice" and all the advice kinds in one loop, to get the // ordering semantics right. NodeList nodeList = aspectElement.getChildNodes(); boolean adviceFoundAlready = false; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (isAdviceNode(node, parserContext)) { if (!adviceFoundAlready) { adviceFoundAlready = true; if (!StringUtils.hasText(aspectName)) { parserContext.getReaderContext().error( "<aspect> tag needs aspect bean reference via 'ref' attribute when declaring advices.", aspectElement, this.parseState.snapshot()); return; } beanReferences.add(new RuntimeBeanReference(aspectName)); } AbstractBeanDefinition advisorDefinition = parseAdvice( aspectName, i, aspectElement, (Element) node, parserContext, beanDefinitions, beanReferences); beanDefinitions.add(advisorDefinition); } } AspectComponentDefinition aspectComponentDefinition = createAspectComponentDefinition( aspectElement, aspectId, beanDefinitions, beanReferences, parserContext); parserContext.pushContainingComponent(aspectComponentDefinition); List<Element> pointcuts = DomUtils.getChildElementsByTagName(aspectElement, POINTCUT); for (Element pointcutElement : pointcuts) { parsePointcut(pointcutElement, parserContext); } parserContext.popAndRegisterContainingComponent(); } finally { this.parseState.pop(); } }