Search in sources :

Example 26 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project spring-security by spring-projects.

the class PortMappingsBeanDefinitionParser method parse.

@Override
@SuppressWarnings("unchecked")
public BeanDefinition parse(Element element, ParserContext parserContext) {
    RootBeanDefinition portMapper = new RootBeanDefinition(PortMapperImpl.class);
    portMapper.setSource(parserContext.extractSource(element));
    if (element != null) {
        List<Element> mappingElts = DomUtils.getChildElementsByTagName(element, Elements.PORT_MAPPING);
        if (mappingElts.isEmpty()) {
            parserContext.getReaderContext().error("No port-mapping child elements specified", element);
        }
        Map mappings = new ManagedMap();
        for (Element elt : mappingElts) {
            String httpPort = elt.getAttribute(ATT_HTTP_PORT);
            String httpsPort = elt.getAttribute(ATT_HTTPS_PORT);
            if (!StringUtils.hasText(httpPort)) {
                parserContext.getReaderContext().error("No http port supplied in port mapping", elt);
            }
            if (!StringUtils.hasText(httpsPort)) {
                parserContext.getReaderContext().error("No https port supplied in port mapping", elt);
            }
            mappings.put(httpPort, httpsPort);
        }
        portMapper.getPropertyValues().addPropertyValue("portMappings", mappings);
    }
    return portMapper;
}
Also used : Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ManagedMap(org.springframework.beans.factory.support.ManagedMap) Map(java.util.Map) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 27 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project spring-framework by spring-projects.

the class ResourcesBeanDefinitionParser method parse.

@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;
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 28 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method registerHandlerMapping.

private ManagedMap<String, Object> registerHandlerMapping(Element element, ParserContext context, @Nullable Object source) {
    RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);
    String orderAttribute = element.getAttribute("order");
    int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.parseInt(orderAttribute);
    handlerMappingDef.getPropertyValues().add("order", order);
    String pathHelper = element.getAttribute("path-helper");
    if (StringUtils.hasText(pathHelper)) {
        handlerMappingDef.getPropertyValues().add("urlPathHelper", new RuntimeBeanReference(pathHelper));
    }
    ManagedMap<String, Object> urlMap = new ManagedMap<>();
    urlMap.setSource(source);
    handlerMappingDef.getPropertyValues().add("urlMap", urlMap);
    registerBeanDef(handlerMappingDef, context, source);
    return urlMap;
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 29 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project spring-framework by spring-projects.

the class MessageBrokerBeanDefinitionParser method registerMessageBroker.

private RootBeanDefinition registerMessageBroker(Element brokerElement, RuntimeBeanReference inChannel, RuntimeBeanReference outChannel, RuntimeBeanReference brokerChannel, Object userDestHandler, RuntimeBeanReference brokerTemplate, RuntimeBeanReference userRegistry, ParserContext context, @Nullable Object source) {
    Element simpleBrokerElem = DomUtils.getChildElementByTagName(brokerElement, "simple-broker");
    Element brokerRelayElem = DomUtils.getChildElementByTagName(brokerElement, "stomp-broker-relay");
    ConstructorArgumentValues cargs = new ConstructorArgumentValues();
    cargs.addIndexedArgumentValue(0, inChannel);
    cargs.addIndexedArgumentValue(1, outChannel);
    cargs.addIndexedArgumentValue(2, brokerChannel);
    RootBeanDefinition brokerDef;
    if (simpleBrokerElem != null) {
        String prefix = simpleBrokerElem.getAttribute("prefix");
        cargs.addIndexedArgumentValue(3, Arrays.asList(StringUtils.tokenizeToStringArray(prefix, ",")));
        brokerDef = new RootBeanDefinition(SimpleBrokerMessageHandler.class, cargs, null);
        if (brokerElement.hasAttribute("path-matcher")) {
            String pathMatcherRef = brokerElement.getAttribute("path-matcher");
            brokerDef.getPropertyValues().add("pathMatcher", new RuntimeBeanReference(pathMatcherRef));
        }
        if (simpleBrokerElem.hasAttribute("scheduler")) {
            String scheduler = simpleBrokerElem.getAttribute("scheduler");
            brokerDef.getPropertyValues().add("taskScheduler", new RuntimeBeanReference(scheduler));
        }
        if (simpleBrokerElem.hasAttribute("heartbeat")) {
            String heartbeatValue = simpleBrokerElem.getAttribute("heartbeat");
            brokerDef.getPropertyValues().add("heartbeatValue", heartbeatValue);
        }
        if (simpleBrokerElem.hasAttribute("selector-header")) {
            String headerName = simpleBrokerElem.getAttribute("selector-header");
            brokerDef.getPropertyValues().add("selectorHeaderName", headerName);
        }
    } else if (brokerRelayElem != null) {
        String prefix = brokerRelayElem.getAttribute("prefix");
        cargs.addIndexedArgumentValue(3, Arrays.asList(StringUtils.tokenizeToStringArray(prefix, ",")));
        MutablePropertyValues values = new MutablePropertyValues();
        if (brokerRelayElem.hasAttribute("relay-host")) {
            values.add("relayHost", brokerRelayElem.getAttribute("relay-host"));
        }
        if (brokerRelayElem.hasAttribute("relay-port")) {
            values.add("relayPort", brokerRelayElem.getAttribute("relay-port"));
        }
        if (brokerRelayElem.hasAttribute("client-login")) {
            values.add("clientLogin", brokerRelayElem.getAttribute("client-login"));
        }
        if (brokerRelayElem.hasAttribute("client-passcode")) {
            values.add("clientPasscode", brokerRelayElem.getAttribute("client-passcode"));
        }
        if (brokerRelayElem.hasAttribute("system-login")) {
            values.add("systemLogin", brokerRelayElem.getAttribute("system-login"));
        }
        if (brokerRelayElem.hasAttribute("system-passcode")) {
            values.add("systemPasscode", brokerRelayElem.getAttribute("system-passcode"));
        }
        if (brokerRelayElem.hasAttribute("heartbeat-send-interval")) {
            values.add("systemHeartbeatSendInterval", brokerRelayElem.getAttribute("heartbeat-send-interval"));
        }
        if (brokerRelayElem.hasAttribute("heartbeat-receive-interval")) {
            values.add("systemHeartbeatReceiveInterval", brokerRelayElem.getAttribute("heartbeat-receive-interval"));
        }
        if (brokerRelayElem.hasAttribute("virtual-host")) {
            values.add("virtualHost", brokerRelayElem.getAttribute("virtual-host"));
        }
        ManagedMap<String, Object> map = new ManagedMap<>();
        map.setSource(source);
        if (brokerRelayElem.hasAttribute("user-destination-broadcast")) {
            String destination = brokerRelayElem.getAttribute("user-destination-broadcast");
            map.put(destination, userDestHandler);
        }
        if (brokerRelayElem.hasAttribute("user-registry-broadcast")) {
            String destination = brokerRelayElem.getAttribute("user-registry-broadcast");
            map.put(destination, registerUserRegistryMessageHandler(userRegistry, brokerTemplate, destination, context, source));
        }
        if (!map.isEmpty()) {
            values.add("systemSubscriptions", map);
        }
        Class<?> handlerType = StompBrokerRelayMessageHandler.class;
        brokerDef = new RootBeanDefinition(handlerType, cargs, values);
    } else {
        // Should not happen
        throw new IllegalStateException("Neither <simple-broker> nor <stomp-broker-relay> elements found.");
    }
    if (brokerElement.hasAttribute("preserve-publish-order")) {
        String preservePublishOrder = brokerElement.getAttribute("preserve-publish-order");
        brokerDef.getPropertyValues().add("preservePublishOrder", preservePublishOrder);
    }
    registerBeanDef(brokerDef, context, source);
    return brokerDef;
}
Also used : Element(org.w3c.dom.Element) SimpleBrokerMessageHandler(org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues)

Example 30 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project hudson-2.x by hudson.

the class BeanBuilder method manageMapIfNecessary.

/**
 * Checks whether there are any runtime refs inside a Map and converts
 * it to a ManagedMap if necessary
 *
 * @param value The current map
 * @return A ManagedMap or a normal map
 */
private Object manageMapIfNecessary(Object value) {
    Map<Object, Object> map = (Map) value;
    boolean containsRuntimeRefs = false;
    for (Entry<Object, Object> e : map.entrySet()) {
        Object v = e.getValue();
        if (v instanceof RuntimeBeanReference) {
            containsRuntimeRefs = true;
        }
        if (v instanceof BeanConfiguration) {
            BeanConfiguration c = (BeanConfiguration) v;
            e.setValue(c.getBeanDefinition());
            containsRuntimeRefs = true;
        }
    }
    if (containsRuntimeRefs) {
        // return new ManagedMap(map);
        ManagedMap m = new ManagedMap();
        m.putAll(map);
        return m;
    }
    return value;
}
Also used : GroovyObject(groovy.lang.GroovyObject) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) HashMap(java.util.HashMap) Map(java.util.Map) ManagedMap(org.springframework.beans.factory.support.ManagedMap) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Aggregations

ManagedMap (org.springframework.beans.factory.support.ManagedMap)63 Element (org.w3c.dom.Element)37 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)25 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)25 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)24 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)23 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)11 Map (java.util.Map)10 TypedStringValue (org.springframework.beans.factory.config.TypedStringValue)9 HashMap (java.util.HashMap)6 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)6 Node (org.w3c.dom.Node)6 ManagedList (org.springframework.beans.factory.support.ManagedList)5 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 NamedNodeMap (org.w3c.dom.NamedNodeMap)4 GroovyObject (groovy.lang.GroovyObject)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)3