Search in sources :

Example 1 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project sharding-jdbc by dangdangdotcom.

the class ShardingJdbcDataSourceBeanDefinitionParser method parseTableRulesConfig.

private Map<String, BeanDefinition> parseTableRulesConfig(final Element element) {
    Element tableRulesElement = DomUtils.getChildElementByTagName(element, ShardingJdbcDataSourceBeanDefinitionParserTag.TABLE_RULES_TAG);
    List<Element> tableRuleElements = DomUtils.getChildElementsByTagName(tableRulesElement, ShardingJdbcDataSourceBeanDefinitionParserTag.TABLE_RULE_TAG);
    Map<String, BeanDefinition> result = new ManagedMap<>(tableRuleElements.size());
    for (Element each : tableRuleElements) {
        result.put(each.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.LOGIC_TABLE_ATTRIBUTE), parseTableRuleConfig(each));
    }
    return result;
}
Also used : Element(org.w3c.dom.Element) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 2 with ManagedMap

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

the class BeanDefinitionParserDelegate method parseMapElement.

/**
	 * Parse a map element.
	 */
public Map<Object, Object> parseMapElement(Element mapEle, BeanDefinition bd) {
    String defaultKeyType = mapEle.getAttribute(KEY_TYPE_ATTRIBUTE);
    String defaultValueType = mapEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
    List<Element> entryEles = DomUtils.getChildElementsByTagName(mapEle, ENTRY_ELEMENT);
    ManagedMap<Object, Object> map = new ManagedMap<>(entryEles.size());
    map.setSource(extractSource(mapEle));
    map.setKeyTypeName(defaultKeyType);
    map.setValueTypeName(defaultValueType);
    map.setMergeEnabled(parseMergeAttribute(mapEle));
    for (Element entryEle : entryEles) {
        // Should only have one value child element: ref, value, list, etc.
        // Optionally, there might be a key child element.
        NodeList entrySubNodes = entryEle.getChildNodes();
        Element keyEle = null;
        Element valueEle = null;
        for (int j = 0; j < entrySubNodes.getLength(); j++) {
            Node node = entrySubNodes.item(j);
            if (node instanceof Element) {
                Element candidateEle = (Element) node;
                if (nodeNameEquals(candidateEle, KEY_ELEMENT)) {
                    if (keyEle != null) {
                        error("<entry> element is only allowed to contain one <key> sub-element", entryEle);
                    } else {
                        keyEle = candidateEle;
                    }
                } else {
                    // Child element is what we're looking for.
                    if (nodeNameEquals(candidateEle, DESCRIPTION_ELEMENT)) {
                    // the element is a <description> -> ignore it
                    } else if (valueEle != null) {
                        error("<entry> element must not contain more than one value sub-element", entryEle);
                    } else {
                        valueEle = candidateEle;
                    }
                }
            }
        }
        // Extract key from attribute or sub-element.
        Object key = null;
        boolean hasKeyAttribute = entryEle.hasAttribute(KEY_ATTRIBUTE);
        boolean hasKeyRefAttribute = entryEle.hasAttribute(KEY_REF_ATTRIBUTE);
        if ((hasKeyAttribute && hasKeyRefAttribute) || ((hasKeyAttribute || hasKeyRefAttribute)) && keyEle != null) {
            error("<entry> element is only allowed to contain either " + "a 'key' attribute OR a 'key-ref' attribute OR a <key> sub-element", entryEle);
        }
        if (hasKeyAttribute) {
            key = buildTypedStringValueForMap(entryEle.getAttribute(KEY_ATTRIBUTE), defaultKeyType, entryEle);
        } else if (hasKeyRefAttribute) {
            String refName = entryEle.getAttribute(KEY_REF_ATTRIBUTE);
            if (!StringUtils.hasText(refName)) {
                error("<entry> element contains empty 'key-ref' attribute", entryEle);
            }
            RuntimeBeanReference ref = new RuntimeBeanReference(refName);
            ref.setSource(extractSource(entryEle));
            key = ref;
        } else if (keyEle != null) {
            key = parseKeyElement(keyEle, bd, defaultKeyType);
        } else {
            error("<entry> element must specify a key", entryEle);
        }
        // Extract value from attribute or sub-element.
        Object value = null;
        boolean hasValueAttribute = entryEle.hasAttribute(VALUE_ATTRIBUTE);
        boolean hasValueRefAttribute = entryEle.hasAttribute(VALUE_REF_ATTRIBUTE);
        boolean hasValueTypeAttribute = entryEle.hasAttribute(VALUE_TYPE_ATTRIBUTE);
        if ((hasValueAttribute && hasValueRefAttribute) || ((hasValueAttribute || hasValueRefAttribute)) && valueEle != null) {
            error("<entry> element is only allowed to contain either " + "'value' attribute OR 'value-ref' attribute OR <value> sub-element", entryEle);
        }
        if ((hasValueTypeAttribute && hasValueRefAttribute) || (hasValueTypeAttribute && !hasValueAttribute) || (hasValueTypeAttribute && valueEle != null)) {
            error("<entry> element is only allowed to contain a 'value-type' " + "attribute when it has a 'value' attribute", entryEle);
        }
        if (hasValueAttribute) {
            String valueType = entryEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
            if (!StringUtils.hasText(valueType)) {
                valueType = defaultValueType;
            }
            value = buildTypedStringValueForMap(entryEle.getAttribute(VALUE_ATTRIBUTE), valueType, entryEle);
        } else if (hasValueRefAttribute) {
            String refName = entryEle.getAttribute(VALUE_REF_ATTRIBUTE);
            if (!StringUtils.hasText(refName)) {
                error("<entry> element contains empty 'value-ref' attribute", entryEle);
            }
            RuntimeBeanReference ref = new RuntimeBeanReference(refName);
            ref.setSource(extractSource(entryEle));
            value = ref;
        } else if (valueEle != null) {
            value = parsePropertySubElement(valueEle, bd, defaultValueType);
        } else {
            error("<entry> element must specify a value", entryEle);
        }
        // Add final key and value to the Map.
        map.put(key, value);
    }
    return map;
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 3 with ManagedMap

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

the class ConsumerServiceBeanDefinitionParser method doParse.

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    List<Element> consumerElements = DomUtils.getChildElementsByTagName(element, "consumer");
    ManagedMap<String, BeanMetadataElement> consumers = new ManagedMap<String, BeanMetadataElement>();
    for (Object item : consumerElements) {
        BeanDefinitionBuilder consumer = BeanDefinitionBuilder.genericBeanDefinition(ConsumerDetailsFactoryBean.class);
        Element consumerElement = (Element) item;
        String key = consumerElement.getAttribute("key");
        if (StringUtils.hasText(key)) {
            consumer.addPropertyValue("consumerKey", key);
        } else {
            parserContext.getReaderContext().error("A consumer key must be supplied with the definition of a consumer.", consumerElement);
        }
        String secret = consumerElement.getAttribute("secret");
        if (StringUtils.hasText(secret)) {
            consumer.addPropertyValue("secret", secret);
            String typeOfSecret = consumerElement.getAttribute("typeOfSecret");
            consumer.addPropertyValue("typeOfSecret", typeOfSecret);
        } else {
            parserContext.getReaderContext().error("A consumer secret must be supplied with the definition of a consumer.", consumerElement);
        }
        String name = consumerElement.getAttribute("name");
        if (StringUtils.hasText(name)) {
            consumer.addPropertyValue("consumerName", name);
        }
        String authorities = consumerElement.getAttribute("authorities");
        if (StringUtils.hasText(authorities)) {
            consumer.addPropertyValue("authorities", authorities);
        }
        String resourceName = consumerElement.getAttribute("resourceName");
        if (StringUtils.hasText(resourceName)) {
            consumer.addPropertyValue("resourceName", resourceName);
        }
        String resourceDescription = consumerElement.getAttribute("resourceDescription");
        if (StringUtils.hasText(resourceDescription)) {
            consumer.addPropertyValue("resourceDescription", resourceDescription);
        }
        String requiredToObtainAuthenticatedToken = consumerElement.getAttribute("requiredToObtainAuthenticatedToken");
        if (StringUtils.hasText(requiredToObtainAuthenticatedToken)) {
            consumer.addPropertyValue("requiredToObtainAuthenticatedToken", requiredToObtainAuthenticatedToken);
        }
        consumers.put(key, consumer.getBeanDefinition());
    }
    builder.addPropertyValue("consumerDetailsStore", consumers);
}
Also used : BeanMetadataElement(org.springframework.beans.BeanMetadataElement) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanMetadataElement(org.springframework.beans.BeanMetadataElement) Element(org.w3c.dom.Element) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 4 with ManagedMap

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

the class AuthorizationServerBeanDefinitionParser method parseEndpointAndReturnFilter.

@Override
protected AbstractBeanDefinition parseEndpointAndReturnFilter(Element element, ParserContext parserContext, String tokenServicesRef, String serializerRef) {
    String clientDetailsRef = element.getAttribute("client-details-service-ref");
    String oAuth2RequestFactoryRef = element.getAttribute("authorization-request-manager-ref");
    String tokenEndpointUrl = element.getAttribute("token-endpoint-url");
    String checkTokenUrl = element.getAttribute("check-token-endpoint-url");
    String enableCheckToken = element.getAttribute("check-token-enabled");
    String authorizationEndpointUrl = element.getAttribute("authorization-endpoint-url");
    String tokenGranterRef = element.getAttribute("token-granter-ref");
    String redirectStrategyRef = element.getAttribute("redirect-strategy-ref");
    String userApprovalHandlerRef = element.getAttribute("user-approval-handler-ref");
    String approvalPage = element.getAttribute("user-approval-page");
    String errorPage = element.getAttribute("error-page");
    String approvalParameter = element.getAttribute("approval-parameter-name");
    String redirectResolverRef = element.getAttribute("redirect-resolver-ref");
    String oAuth2RequestValidatorRef = element.getAttribute("request-validator-ref");
    // Create a bean definition speculatively for the auth endpoint
    BeanDefinitionBuilder authorizationEndpointBean = BeanDefinitionBuilder.rootBeanDefinition(AuthorizationEndpoint.class);
    if (!StringUtils.hasText(clientDetailsRef)) {
        parserContext.getReaderContext().error("ClientDetailsService must be provided", element);
        return null;
    }
    if (!StringUtils.hasText(oAuth2RequestValidatorRef)) {
        oAuth2RequestValidatorRef = "defaultOAuth2RequestValidator";
        BeanDefinitionBuilder oAuth2RequestValidator = BeanDefinitionBuilder.rootBeanDefinition(DefaultOAuth2RequestValidator.class);
        parserContext.getRegistry().registerBeanDefinition(oAuth2RequestValidatorRef, oAuth2RequestValidator.getBeanDefinition());
    }
    authorizationEndpointBean.addPropertyReference("oAuth2RequestValidator", oAuth2RequestValidatorRef);
    if (!StringUtils.hasText(oAuth2RequestFactoryRef)) {
        oAuth2RequestFactoryRef = "oAuth2AuthorizationRequestManager";
        BeanDefinitionBuilder oAuth2RequestManager = BeanDefinitionBuilder.rootBeanDefinition(DefaultOAuth2RequestFactory.class);
        oAuth2RequestManager.addConstructorArgReference(clientDetailsRef);
        parserContext.getRegistry().registerBeanDefinition(oAuth2RequestFactoryRef, oAuth2RequestManager.getBeanDefinition());
    }
    ManagedList<BeanMetadataElement> tokenGranters = null;
    if (!StringUtils.hasText(tokenGranterRef)) {
        tokenGranterRef = "oauth2TokenGranter";
        BeanDefinitionBuilder tokenGranterBean = BeanDefinitionBuilder.rootBeanDefinition(CompositeTokenGranter.class);
        parserContext.getRegistry().registerBeanDefinition(tokenGranterRef, tokenGranterBean.getBeanDefinition());
        tokenGranters = new ManagedList<BeanMetadataElement>();
        tokenGranterBean.addConstructorArgValue(tokenGranters);
    }
    authorizationEndpointBean.addPropertyReference("tokenGranter", tokenGranterRef);
    boolean registerAuthorizationEndpoint = false;
    Element authorizationCodeElement = DomUtils.getChildElementByTagName(element, "authorization-code");
    if (authorizationCodeElement != null && !"true".equalsIgnoreCase(authorizationCodeElement.getAttribute("disabled"))) {
        // authorization code grant configuration.
        String authorizationCodeServices = authorizationCodeElement.getAttribute("authorization-code-services-ref");
        String clientTokenCacheRef = authorizationCodeElement.getAttribute("client-token-cache-ref");
        BeanDefinitionBuilder authorizationCodeTokenGranterBean = BeanDefinitionBuilder.rootBeanDefinition(AuthorizationCodeTokenGranter.class);
        if (StringUtils.hasText(tokenServicesRef)) {
            authorizationCodeTokenGranterBean.addConstructorArgReference(tokenServicesRef);
        }
        if (!StringUtils.hasText(authorizationCodeServices)) {
            authorizationCodeServices = "oauth2AuthorizationCodeServices";
            BeanDefinitionBuilder authorizationCodeServicesBean = BeanDefinitionBuilder.rootBeanDefinition(InMemoryAuthorizationCodeServices.class);
            parserContext.getRegistry().registerBeanDefinition(authorizationCodeServices, authorizationCodeServicesBean.getBeanDefinition());
        }
        authorizationEndpointBean.addPropertyReference("authorizationCodeServices", authorizationCodeServices);
        authorizationCodeTokenGranterBean.addConstructorArgReference(authorizationCodeServices);
        authorizationCodeTokenGranterBean.addConstructorArgReference(clientDetailsRef);
        authorizationCodeTokenGranterBean.addConstructorArgReference(oAuth2RequestFactoryRef);
        if (StringUtils.hasText(clientTokenCacheRef)) {
            authorizationEndpointBean.addPropertyReference("clientTokenCache", clientTokenCacheRef);
        }
        if (StringUtils.hasText(oAuth2RequestFactoryRef)) {
            authorizationEndpointBean.addPropertyReference("oAuth2RequestFactory", oAuth2RequestFactoryRef);
        }
        if (tokenGranters != null) {
            tokenGranters.add(authorizationCodeTokenGranterBean.getBeanDefinition());
        }
        // end authorization code provider configuration.
        registerAuthorizationEndpoint = true;
    }
    if (tokenGranters != null) {
        Element refreshTokenElement = DomUtils.getChildElementByTagName(element, "refresh-token");
        if (refreshTokenElement != null && !"true".equalsIgnoreCase(refreshTokenElement.getAttribute("disabled"))) {
            BeanDefinitionBuilder refreshTokenGranterBean = BeanDefinitionBuilder.rootBeanDefinition(RefreshTokenGranter.class);
            refreshTokenGranterBean.addConstructorArgReference(tokenServicesRef);
            refreshTokenGranterBean.addConstructorArgReference(clientDetailsRef);
            refreshTokenGranterBean.addConstructorArgReference(oAuth2RequestFactoryRef);
            tokenGranters.add(refreshTokenGranterBean.getBeanDefinition());
        }
        Element implicitElement = DomUtils.getChildElementByTagName(element, "implicit");
        if (implicitElement != null && !"true".equalsIgnoreCase(implicitElement.getAttribute("disabled"))) {
            BeanDefinitionBuilder implicitGranterBean = BeanDefinitionBuilder.rootBeanDefinition(ImplicitTokenGranter.class);
            implicitGranterBean.addConstructorArgReference(tokenServicesRef);
            implicitGranterBean.addConstructorArgReference(clientDetailsRef);
            implicitGranterBean.addConstructorArgReference(oAuth2RequestFactoryRef);
            tokenGranters.add(implicitGranterBean.getBeanDefinition());
            registerAuthorizationEndpoint = true;
        }
        Element clientCredentialsElement = DomUtils.getChildElementByTagName(element, "client-credentials");
        if (clientCredentialsElement != null && !"true".equalsIgnoreCase(clientCredentialsElement.getAttribute("disabled"))) {
            BeanDefinitionBuilder clientCredentialsGranterBean = BeanDefinitionBuilder.rootBeanDefinition(ClientCredentialsTokenGranter.class);
            clientCredentialsGranterBean.addConstructorArgReference(tokenServicesRef);
            clientCredentialsGranterBean.addConstructorArgReference(clientDetailsRef);
            clientCredentialsGranterBean.addConstructorArgReference(oAuth2RequestFactoryRef);
            tokenGranters.add(clientCredentialsGranterBean.getBeanDefinition());
        }
        Element clientPasswordElement = DomUtils.getChildElementByTagName(element, "password");
        if (clientPasswordElement != null && !"true".equalsIgnoreCase(clientPasswordElement.getAttribute("disabled"))) {
            BeanDefinitionBuilder clientPasswordTokenGranter = BeanDefinitionBuilder.rootBeanDefinition(ResourceOwnerPasswordTokenGranter.class);
            String authenticationManagerRef = clientPasswordElement.getAttribute("authentication-manager-ref");
            if (!StringUtils.hasText(authenticationManagerRef)) {
                authenticationManagerRef = BeanIds.AUTHENTICATION_MANAGER;
            }
            clientPasswordTokenGranter.addConstructorArgReference(authenticationManagerRef);
            clientPasswordTokenGranter.addConstructorArgReference(tokenServicesRef);
            clientPasswordTokenGranter.addConstructorArgReference(clientDetailsRef);
            clientPasswordTokenGranter.addConstructorArgReference(oAuth2RequestFactoryRef);
            tokenGranters.add(clientPasswordTokenGranter.getBeanDefinition());
        }
        List<Element> customGrantElements = DomUtils.getChildElementsByTagName(element, "custom-grant");
        for (Element customGrantElement : customGrantElements) {
            if (!"true".equalsIgnoreCase(customGrantElement.getAttribute("disabled"))) {
                String customGranterRef = customGrantElement.getAttribute("token-granter-ref");
                tokenGranters.add(new RuntimeBeanReference(customGranterRef));
            }
        }
    }
    if (registerAuthorizationEndpoint) {
        BeanDefinitionBuilder approvalEndpointBean = BeanDefinitionBuilder.rootBeanDefinition(WhitelabelApprovalEndpoint.class);
        parserContext.getRegistry().registerBeanDefinition("oauth2ApprovalEndpoint", approvalEndpointBean.getBeanDefinition());
        if (!StringUtils.hasText(clientDetailsRef)) {
            parserContext.getReaderContext().error("A client details service is mandatory", element);
        }
        if (StringUtils.hasText(redirectStrategyRef)) {
            authorizationEndpointBean.addPropertyReference("redirectStrategy", redirectStrategyRef);
        }
        if (StringUtils.hasText(userApprovalHandlerRef)) {
            authorizationEndpointBean.addPropertyReference("userApprovalHandler", userApprovalHandlerRef);
        }
        authorizationEndpointBean.addPropertyReference("clientDetailsService", clientDetailsRef);
        if (StringUtils.hasText(redirectResolverRef)) {
            authorizationEndpointBean.addPropertyReference("redirectResolver", redirectResolverRef);
        }
        if (StringUtils.hasText(approvalPage)) {
            authorizationEndpointBean.addPropertyValue("userApprovalPage", approvalPage);
        }
        if (StringUtils.hasText(errorPage)) {
            authorizationEndpointBean.addPropertyValue("errorPage", errorPage);
        }
        parserContext.getRegistry().registerBeanDefinition("oauth2AuthorizationEndpoint", authorizationEndpointBean.getBeanDefinition());
    }
    // configure the token endpoint
    BeanDefinitionBuilder tokenEndpointBean = BeanDefinitionBuilder.rootBeanDefinition(TokenEndpoint.class);
    tokenEndpointBean.addPropertyReference("clientDetailsService", clientDetailsRef);
    tokenEndpointBean.addPropertyReference("tokenGranter", tokenGranterRef);
    authorizationEndpointBean.addPropertyReference("oAuth2RequestValidator", oAuth2RequestValidatorRef);
    parserContext.getRegistry().registerBeanDefinition("oauth2TokenEndpoint", tokenEndpointBean.getBeanDefinition());
    if (StringUtils.hasText(oAuth2RequestFactoryRef)) {
        tokenEndpointBean.addPropertyReference("oAuth2RequestFactory", oAuth2RequestFactoryRef);
    }
    if (StringUtils.hasText(oAuth2RequestValidatorRef)) {
        tokenEndpointBean.addPropertyReference("oAuth2RequestValidator", oAuth2RequestValidatorRef);
    }
    // Register a handler mapping that can detect the auth server endpoints
    BeanDefinitionBuilder handlerMappingBean = BeanDefinitionBuilder.rootBeanDefinition(FrameworkEndpointHandlerMapping.class);
    ManagedMap<String, TypedStringValue> mappings = new ManagedMap<String, TypedStringValue>();
    if (StringUtils.hasText(tokenEndpointUrl) || StringUtils.hasText(authorizationEndpointUrl)) {
        if (StringUtils.hasText(tokenEndpointUrl)) {
            mappings.put("/oauth/token", new TypedStringValue(tokenEndpointUrl, String.class));
        }
        if (StringUtils.hasText(authorizationEndpointUrl)) {
            mappings.put("/oauth/authorize", new TypedStringValue(authorizationEndpointUrl, String.class));
        }
        if (StringUtils.hasText(approvalPage)) {
            mappings.put("/oauth/confirm_access", new TypedStringValue(approvalPage, String.class));
        }
    }
    if (StringUtils.hasText(enableCheckToken) && enableCheckToken.equals("true")) {
        // configure the check token endpoint
        BeanDefinitionBuilder checkTokenEndpointBean = BeanDefinitionBuilder.rootBeanDefinition(CheckTokenEndpoint.class);
        checkTokenEndpointBean.addConstructorArgReference(tokenServicesRef);
        parserContext.getRegistry().registerBeanDefinition("oauth2CheckTokenEndpoint", checkTokenEndpointBean.getBeanDefinition());
        if (StringUtils.hasText(checkTokenUrl)) {
            mappings.put("/oauth/check_token", new TypedStringValue(checkTokenUrl, String.class));
        }
    }
    if (!mappings.isEmpty()) {
        handlerMappingBean.addPropertyValue("mappings", mappings);
    }
    if (StringUtils.hasText(approvalParameter) && registerAuthorizationEndpoint) {
        if (!StringUtils.hasText(userApprovalHandlerRef)) {
            BeanDefinitionBuilder userApprovalHandler = BeanDefinitionBuilder.rootBeanDefinition(DefaultUserApprovalHandler.class);
            userApprovalHandler.addPropertyValue("approvalParameter", new TypedStringValue(approvalParameter, String.class));
            authorizationEndpointBean.addPropertyValue("userApprovalHandler", userApprovalHandler.getBeanDefinition());
        }
        handlerMappingBean.addPropertyValue("approvalParameter", approvalParameter);
    }
    parserContext.getRegistry().registerBeanDefinition("oauth2HandlerMapping", handlerMappingBean.getBeanDefinition());
    // We aren't defining a filter...
    return null;
}
Also used : BeanMetadataElement(org.springframework.beans.BeanMetadataElement) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanMetadataElement(org.springframework.beans.BeanMetadataElement) Element(org.w3c.dom.Element) TypedStringValue(org.springframework.beans.factory.config.TypedStringValue) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 5 with ManagedMap

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

the class GroovyBeanDefinitionReader method manageMapIfNecessary.

/**
	 * Checks whether there are any {@link RuntimeBeanReference}s inside the {@link Map}
	 * and converts it to a {@link ManagedMap} if necessary.
	 * @param map the original Map
	 * @return either the original map or a managed copy of it
	 */
private Object manageMapIfNecessary(Map<?, ?> map) {
    boolean containsRuntimeRefs = false;
    for (Object element : map.values()) {
        if (element instanceof RuntimeBeanReference) {
            containsRuntimeRefs = true;
            break;
        }
    }
    if (containsRuntimeRefs) {
        Map<Object, Object> managedMap = new ManagedMap<>();
        managedMap.putAll(map);
        return managedMap;
    }
    return map;
}
Also used : GroovyObject(groovy.lang.GroovyObject) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) 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