Search in sources :

Example 46 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method registerAnnotationMethodMessageHandler.

private void registerAnnotationMethodMessageHandler(Element messageBrokerElement, RuntimeBeanReference inChannel, RuntimeBeanReference outChannel, RuntimeBeanReference converter, RuntimeBeanReference messagingTemplate, ParserContext context, Object source) {
    ConstructorArgumentValues cavs = new ConstructorArgumentValues();
    cavs.addIndexedArgumentValue(0, inChannel);
    cavs.addIndexedArgumentValue(1, outChannel);
    cavs.addIndexedArgumentValue(2, messagingTemplate);
    MutablePropertyValues values = new MutablePropertyValues();
    String prefixAttribute = messageBrokerElement.getAttribute("application-destination-prefix");
    values.add("destinationPrefixes", Arrays.asList(StringUtils.tokenizeToStringArray(prefixAttribute, ",")));
    values.add("messageConverter", converter);
    RootBeanDefinition beanDef = new RootBeanDefinition(WebSocketAnnotationMethodMessageHandler.class, cavs, values);
    if (messageBrokerElement.hasAttribute("path-matcher")) {
        String pathMatcherRef = messageBrokerElement.getAttribute("path-matcher");
        beanDef.getPropertyValues().add("pathMatcher", new RuntimeBeanReference(pathMatcherRef));
    }
    RuntimeBeanReference validatorRef = getValidator(messageBrokerElement, source, context);
    if (validatorRef != null) {
        beanDef.getPropertyValues().add("validator", validatorRef);
    }
    Element resolversElement = DomUtils.getChildElementByTagName(messageBrokerElement, "argument-resolvers");
    if (resolversElement != null) {
        values.add("customArgumentResolvers", extractBeanSubElements(resolversElement, context));
    }
    Element handlersElement = DomUtils.getChildElementByTagName(messageBrokerElement, "return-value-handlers");
    if (handlersElement != null) {
        values.add("customReturnValueHandlers", extractBeanSubElements(handlersElement, context));
    }
    registerBeanDef(beanDef, context, source);
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 47 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method registerUserDestResolver.

private RuntimeBeanReference registerUserDestResolver(Element brokerElem, RuntimeBeanReference userRegistry, ParserContext context, Object source) {
    RootBeanDefinition beanDef = new RootBeanDefinition(DefaultUserDestinationResolver.class);
    beanDef.getConstructorArgumentValues().addIndexedArgumentValue(0, userRegistry);
    if (brokerElem.hasAttribute("user-destination-prefix")) {
        beanDef.getPropertyValues().add("userDestinationPrefix", brokerElem.getAttribute("user-destination-prefix"));
    }
    if (brokerElem.hasAttribute("path-matcher")) {
        String pathMatcherRef = brokerElem.getAttribute("path-matcher");
        beanDef.getPropertyValues().add("pathMatcher", new RuntimeBeanReference(pathMatcherRef));
    }
    return new RuntimeBeanReference(registerBeanDef(beanDef, context, source));
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 48 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method registerUserDestHandler.

private RuntimeBeanReference registerUserDestHandler(Element brokerElem, RuntimeBeanReference userRegistry, RuntimeBeanReference inChannel, RuntimeBeanReference brokerChannel, ParserContext context, Object source) {
    Object userDestResolver = registerUserDestResolver(brokerElem, userRegistry, context, source);
    RootBeanDefinition beanDef = new RootBeanDefinition(UserDestinationMessageHandler.class);
    beanDef.getConstructorArgumentValues().addIndexedArgumentValue(0, inChannel);
    beanDef.getConstructorArgumentValues().addIndexedArgumentValue(1, brokerChannel);
    beanDef.getConstructorArgumentValues().addIndexedArgumentValue(2, userDestResolver);
    Element relayElement = DomUtils.getChildElementByTagName(brokerElem, "stomp-broker-relay");
    if (relayElement != null && relayElement.hasAttribute("user-destination-broadcast")) {
        String destination = relayElement.getAttribute("user-destination-broadcast");
        beanDef.getPropertyValues().add("broadcastDestination", destination);
    }
    String beanName = registerBeanDef(beanDef, context, source);
    return new RuntimeBeanReference(beanName);
}
Also used : Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 49 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method registerRequestHandler.

private RuntimeBeanReference registerRequestHandler(Element element, RuntimeBeanReference subProtoHandler, ParserContext context, Object source) {
    RootBeanDefinition beanDef;
    RuntimeBeanReference sockJsService = WebSocketNamespaceUtils.registerSockJsService(element, SCHEDULER_BEAN_NAME, context, source);
    if (sockJsService != null) {
        ConstructorArgumentValues cavs = new ConstructorArgumentValues();
        cavs.addIndexedArgumentValue(0, sockJsService);
        cavs.addIndexedArgumentValue(1, subProtoHandler);
        beanDef = new RootBeanDefinition(SockJsHttpRequestHandler.class, cavs, null);
        // Register alias for backwards compatibility with 4.1
        context.getRegistry().registerAlias(SCHEDULER_BEAN_NAME, SOCKJS_SCHEDULER_BEAN_NAME);
    } 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));
        ConstructorArgumentValues cavs = new ConstructorArgumentValues();
        cavs.addIndexedArgumentValue(0, subProtoHandler);
        if (handshakeHandler != null) {
            cavs.addIndexedArgumentValue(1, handshakeHandler);
        }
        beanDef = new RootBeanDefinition(WebSocketHttpRequestHandler.class, cavs, null);
        beanDef.getPropertyValues().add("handshakeInterceptors", interceptors);
    }
    return new RuntimeBeanReference(registerBeanDef(beanDef, context, source));
}
Also used : SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) OriginHandshakeInterceptor(org.springframework.web.socket.server.support.OriginHandshakeInterceptor) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler)

Example 50 with RuntimeBeanReference

use of org.springframework.beans.factory.config.RuntimeBeanReference in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method registerWebSocketMessageBrokerStats.

private void registerWebSocketMessageBrokerStats(RootBeanDefinition broker, RuntimeBeanReference inChannel, RuntimeBeanReference outChannel, ParserContext context, Object source) {
    RootBeanDefinition beanDef = new RootBeanDefinition(WebSocketMessageBrokerStats.class);
    RuntimeBeanReference webSocketHandler = new RuntimeBeanReference(WEB_SOCKET_HANDLER_BEAN_NAME);
    beanDef.getPropertyValues().add("subProtocolWebSocketHandler", webSocketHandler);
    if (StompBrokerRelayMessageHandler.class == broker.getBeanClass()) {
        beanDef.getPropertyValues().add("stompBrokerRelay", broker);
    }
    String name = inChannel.getBeanName() + "Executor";
    if (context.getRegistry().containsBeanDefinition(name)) {
        beanDef.getPropertyValues().add("inboundChannelExecutor", context.getRegistry().getBeanDefinition(name));
    }
    name = outChannel.getBeanName() + "Executor";
    if (context.getRegistry().containsBeanDefinition(name)) {
        beanDef.getPropertyValues().add("outboundChannelExecutor", context.getRegistry().getBeanDefinition(name));
    }
    Object scheduler = WebSocketNamespaceUtils.registerScheduler(SCHEDULER_BEAN_NAME, context, source);
    beanDef.getPropertyValues().add("sockJsTaskScheduler", scheduler);
    registerBeanDefByName("webSocketMessageBrokerStats", beanDef, context, source);
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Aggregations

RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)156 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)86 Element (org.w3c.dom.Element)47 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)39 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)33 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)32 ManagedList (org.springframework.beans.factory.support.ManagedList)27 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)24 Test (org.junit.Test)21 ManagedMap (org.springframework.beans.factory.support.ManagedMap)20 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)16 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)15 GroovyObject (groovy.lang.GroovyObject)12 TestBean (org.springframework.tests.sample.beans.TestBean)12 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)11 Map (java.util.Map)10 Node (org.w3c.dom.Node)10 HashMap (java.util.HashMap)9 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)9 ITestBean (org.springframework.tests.sample.beans.ITestBean)8