Search in sources :

Example 6 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project dubbo by alibaba.

the class DubboBeanDefinitionParser method parseParameters.

@SuppressWarnings("unchecked")
private static ManagedMap parseParameters(NodeList nodeList, RootBeanDefinition beanDefinition) {
    if (nodeList != null && nodeList.getLength() > 0) {
        ManagedMap parameters = null;
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node instanceof Element) {
                if ("parameter".equals(node.getNodeName()) || "parameter".equals(node.getLocalName())) {
                    if (parameters == null) {
                        parameters = new ManagedMap();
                    }
                    String key = ((Element) node).getAttribute("key");
                    String value = ((Element) node).getAttribute("value");
                    boolean hide = "true".equals(((Element) node).getAttribute("hide"));
                    if (hide) {
                        key = Constants.HIDE_KEY_PREFIX + key;
                    }
                    parameters.put(key, new TypedStringValue(value, String.class));
                }
            }
        }
        return parameters;
    }
    return null;
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) TypedStringValue(org.springframework.beans.factory.config.TypedStringValue) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 7 with ManagedMap

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

the class MongoParsingUtils method getWriteConcernPropertyEditorBuilder.

/**
 * Returns the {@link BeanDefinitionBuilder} to build a {@link BeanDefinition} for a
 * {@link WriteConcernPropertyEditor}.
 *
 * @return
 */
static BeanDefinitionBuilder getWriteConcernPropertyEditorBuilder() {
    Map<String, Class<?>> customEditors = new ManagedMap<String, Class<?>>();
    customEditors.put("com.mongodb.WriteConcern", WriteConcernPropertyEditor.class);
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
    builder.addPropertyValue("customEditors", customEditors);
    return builder;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 8 with ManagedMap

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

the class MongoParsingUtils method getServerAddressPropertyEditorBuilder.

/**
 * One should only register one bean definition but want to have the convenience of using
 * AbstractSingleBeanDefinitionParser but have the side effect of registering a 'default' property editor with the
 * container.
 */
static BeanDefinitionBuilder getServerAddressPropertyEditorBuilder() {
    Map<String, String> customEditors = new ManagedMap<String, String>();
    customEditors.put("com.mongodb.ServerAddress[]", "org.springframework.data.mongodb.config.ServerAddressPropertyEditor");
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CustomEditorConfigurer.class);
    builder.addPropertyValue("customEditors", customEditors);
    return builder;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 9 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project geronimo-xbean by apache.

the class XBeanNamespaceHandler method parseCustomMapElement.

protected Object parseCustomMapElement(MappingMetaData metadata, Element element, String name) {
    Map map = new ManagedMap();
    Element parent = (Element) element.getParentNode();
    String entryName = metadata.getMapEntryName(getLocalName(parent), name);
    String keyName = metadata.getMapKeyName(getLocalName(parent), name);
    String dups = metadata.getMapDupsMode(getLocalName(parent), name);
    boolean flat = metadata.isFlatMap(getLocalName(parent), name);
    String defaultKey = metadata.getMapDefaultKey(getLocalName(parent), name);
    if (entryName == null)
        entryName = "property";
    if (keyName == null)
        keyName = "key";
    if (dups == null)
        dups = "replace";
    // TODO : support further customizations
    // String valueName = "value";
    // boolean keyIsAttr = true;
    // boolean valueIsAttr = false;
    NodeList nl = element.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (node instanceof Element) {
            Element childElement = (Element) node;
            String localName = childElement.getLocalName();
            String uri = childElement.getNamespaceURI();
            if (localName == null || localName.equals("xmlns") || localName.startsWith("xmlns:")) {
                continue;
            }
            // attributes from namespace-specific attributes
            if (!flat && !isEmpty(uri) && localName.equals(entryName)) {
                String key = childElement.getAttribute(keyName);
                if (key == null || key.length() == 0) {
                    key = defaultKey;
                }
                if (key == null) {
                    throw new RuntimeException("No key defined for map " + entryName);
                }
                Object keyValue = getValue(key, null);
                Element valueElement = getFirstChildElement(childElement);
                Object value;
                if (valueElement != null) {
                    String valueElUri = valueElement.getNamespaceURI();
                    String valueElLocalName = valueElement.getLocalName();
                    if (valueElUri == null || valueElUri.equals(SPRING_SCHEMA) || valueElUri.equals(SPRING_SCHEMA_COMPAT) || valueElUri.equals(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI)) {
                        if (BeanDefinitionParserDelegate.BEAN_ELEMENT.equals(valueElLocalName)) {
                            value = parserContext.getDelegate().parseBeanDefinitionElement(valueElement, null);
                        } else {
                            value = parserContext.getDelegate().parsePropertySubElement(valueElement, null);
                        }
                    } else {
                        value = parserContext.getDelegate().parseCustomElement(valueElement);
                    }
                } else {
                    value = getElementText(childElement);
                }
                addValueToMap(map, keyValue, value, dups);
            } else if (flat && !isEmpty(uri)) {
                String key = childElement.getAttribute(keyName);
                if (key == null || key.length() == 0) {
                    key = defaultKey;
                }
                if (key == null) {
                    throw new RuntimeException("No key defined for map entry " + entryName);
                }
                Object keyValue = getValue(key, null);
                childElement.removeAttribute(keyName);
                BeanDefinitionHolder bdh = parseBeanFromExtensionElement(childElement);
                addValueToMap(map, keyValue, bdh, dups);
            }
        }
    }
    return map;
}
Also used : Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap) ManagedMap(org.springframework.beans.factory.support.ManagedMap) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 10 with ManagedMap

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

the class ConfigUtils method createSecurityMetadataSource.

public static BeanDefinition createSecurityMetadataSource(Element element, ParserContext pc) {
    List<Element> filterPatterns = DomUtils.getChildElementsByTagName(element, "url");
    if (filterPatterns.isEmpty()) {
        return null;
    }
    String patternType = element.getAttribute("path-type");
    if (!StringUtils.hasText(patternType)) {
        patternType = "ant";
    }
    MatcherType matcherType = MatcherType.valueOf(patternType);
    ManagedMap<BeanDefinition, BeanDefinition> invocationDefinitionMap = new ManagedMap<BeanDefinition, BeanDefinition>();
    for (Element filterPattern : filterPatterns) {
        String path = filterPattern.getAttribute("pattern");
        if (!StringUtils.hasText(path)) {
            pc.getReaderContext().error("pattern attribute cannot be empty or null", filterPattern);
        }
        String method = filterPattern.getAttribute("httpMethod");
        if (!StringUtils.hasText(method)) {
            method = null;
        }
        String access = filterPattern.getAttribute("resources");
        if (StringUtils.hasText(access)) {
            BeanDefinition matcher;
            if (createMatcherMethod4x != null) {
                matcher = (BeanDefinition) ReflectionUtils.invokeMethod(createMatcherMethod4x, matcherType, pc, path, method);
            } else {
                matcher = (BeanDefinition) ReflectionUtils.invokeMethod(createMatcherMethod3x, matcherType, path, method);
            }
            if (access.equals("none")) {
                invocationDefinitionMap.put(matcher, BeanDefinitionBuilder.rootBeanDefinition(Collections.class).setFactoryMethod("emptyList").getBeanDefinition());
            } else {
                BeanDefinitionBuilder attributeBuilder = BeanDefinitionBuilder.rootBeanDefinition(SecurityConfig.class);
                attributeBuilder.addConstructorArgValue(access);
                attributeBuilder.setFactoryMethod("createListFromCommaDelimitedString");
                if (invocationDefinitionMap.containsKey(matcher)) {
                    pc.getReaderContext().warning("Duplicate URL defined: " + path + ". The original attribute values will be overwritten", pc.extractSource(filterPattern));
                }
                invocationDefinitionMap.put(matcher, attributeBuilder.getBeanDefinition());
            }
        }
    }
    BeanDefinitionBuilder fidsBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultFilterInvocationSecurityMetadataSource.class);
    fidsBuilder.addConstructorArgValue(invocationDefinitionMap);
    fidsBuilder.getRawBeanDefinition().setSource(pc.extractSource(element));
    return fidsBuilder.getBeanDefinition();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanMetadataElement(org.springframework.beans.BeanMetadataElement) Element(org.w3c.dom.Element) MatcherType(org.springframework.security.config.http.MatcherType) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Collections(java.util.Collections) 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