Search in sources :

Example 56 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project cxf by apache.

the class JettyHTTPServerEngineFactoryBeanDefinitionParser method doParse.

@Override
public void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
    // bean.setAbstract(true);
    String bus = element.getAttribute("bus");
    BeanDefinitionBuilder factbean = BeanDefinitionBuilder.rootBeanDefinition(JettySpringTypesFactory.class);
    ctx.getRegistry().registerBeanDefinition(JettySpringTypesFactory.class.getName(), factbean.getBeanDefinition());
    try {
        if (StringUtils.isEmpty(bus)) {
            addBusWiringAttribute(bean, BusWiringType.CONSTRUCTOR);
        } else {
            bean.addConstructorArgReference(bus);
        }
        bean.addConstructorArgValue(mapElementToJaxbBean(element, TLSServerParametersIdentifiedType.class, JettySpringTypesFactory.class, "createTLSServerParametersMap"));
        bean.addConstructorArgValue(mapElementToJaxbBean(element, ThreadingParametersIdentifiedType.class, JettySpringTypesFactory.class, "createThreadingParametersMap"));
        // parser the engine list
        List<Object> list = getRequiredElementsList(element, ctx, new QName(HTTP_JETTY_NS, "engine"), bean);
        if (!list.isEmpty()) {
            bean.addPropertyValue("enginesList", list);
        }
    } catch (Exception e) {
        throw new RuntimeException("Could not process configuration.", e);
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ThreadingParametersIdentifiedType(org.apache.cxf.transports.http_jetty.configuration.ThreadingParametersIdentifiedType) QName(javax.xml.namespace.QName) BeansException(org.springframework.beans.BeansException) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) TLSServerParametersIdentifiedType(org.apache.cxf.transports.http_jetty.configuration.TLSServerParametersIdentifiedType)

Example 57 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project cxf by apache.

the class UndertowHTTPServerEngineBeanDefinitionParser method mapTLSServerParameters.

private void mapTLSServerParameters(Element e, BeanDefinitionBuilder bean) {
    BeanDefinitionBuilder paramsbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.TLSServerParametersTypeInternal.class);
    // read the attributes
    NamedNodeMap as = e.getAttributes();
    for (int i = 0; i < as.getLength(); i++) {
        Attr a = (Attr) as.item(i);
        if (a.getNamespaceURI() == null) {
            String aname = a.getLocalName();
            if ("jsseProvider".equals(aname) || "secureSocketProtocol".equals(aname)) {
                paramsbean.addPropertyValue(aname, a.getValue());
            }
        }
    }
    // read the child elements
    Node n = e.getFirstChild();
    while (n != null) {
        if (Node.ELEMENT_NODE != n.getNodeType() || !SECURITY_NS.equals(n.getNamespaceURI())) {
            n = n.getNextSibling();
            continue;
        }
        String ename = n.getLocalName();
        // Schema should require that no more than one each of these exist.
        String ref = ((Element) n).getAttribute("ref");
        if ("keyManagers".equals(ename)) {
            if (ref != null && ref.length() > 0) {
                paramsbean.addPropertyReference("keyManagersRef", ref);
            } else {
                mapElementToJaxbProperty((Element) n, paramsbean, ename, KeyManagersType.class);
            }
        } else if ("trustManagers".equals(ename)) {
            if (ref != null && ref.length() > 0) {
                paramsbean.addPropertyReference("trustManagersRef", ref);
            } else {
                mapElementToJaxbProperty((Element) n, paramsbean, ename, TrustManagersType.class);
            }
        } else if ("cipherSuites".equals(ename)) {
            mapElementToJaxbProperty((Element) n, paramsbean, ename, CipherSuites.class);
        } else if ("cipherSuitesFilter".equals(ename)) {
            mapElementToJaxbProperty((Element) n, paramsbean, ename, FiltersType.class);
        } else if ("excludeProtocols".equals(ename)) {
            mapElementToJaxbProperty((Element) n, paramsbean, ename, ExcludeProtocols.class);
        } else if ("includeProtocols".equals(ename)) {
            mapElementToJaxbProperty((Element) n, paramsbean, ename, IncludeProtocols.class);
        } else if ("secureRandomParameters".equals(ename)) {
            mapElementToJaxbProperty((Element) n, paramsbean, ename, SecureRandomParameters.class);
        } else if ("clientAuthentication".equals(ename)) {
            mapElementToJaxbProperty((Element) n, paramsbean, ename, ClientAuthentication.class);
        } else if ("certConstraints".equals(ename)) {
            mapElementToJaxbProperty((Element) n, paramsbean, ename, CertificateConstraintsType.class);
        } else if ("certAlias".equals(ename)) {
            paramsbean.addPropertyValue(ename, n.getTextContent());
        }
        n = n.getNextSibling();
    }
    BeanDefinitionBuilder jaxbbean = BeanDefinitionBuilder.rootBeanDefinition(TLSServerParametersConfig.class);
    jaxbbean.addConstructorArgValue(paramsbean.getBeanDefinition());
    bean.addPropertyValue("tlsServerParameters", jaxbbean.getBeanDefinition());
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) NamedNodeMap(org.w3c.dom.NamedNodeMap) IncludeProtocols(org.apache.cxf.configuration.security.IncludeProtocols) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) TrustManagersType(org.apache.cxf.configuration.security.TrustManagersType) FiltersType(org.apache.cxf.configuration.security.FiltersType) ClientAuthentication(org.apache.cxf.configuration.security.ClientAuthentication) TLSServerParametersConfig(org.apache.cxf.configuration.jsse.TLSServerParametersConfig) Attr(org.w3c.dom.Attr)

Example 58 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project pentaho-platform by pentaho.

the class BeanListParser method parseInternal.

@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(BeanListBuilder.class.getName());
    builder.addPropertyValue("type", element.getAttribute("class"));
    Map<String, String> propMap = new HashMap<String, String>();
    Element objectproperties = DomUtils.getChildElementByTagName(element, Const.ATTRIBUTES);
    if (objectproperties != null) {
        List props = DomUtils.getChildElementsByTagName(objectproperties, Const.ATTR);
        if (props != null) {
            for (Object o : props) {
                Element prop = (Element) o;
                String key = prop.getAttribute(Const.KEY);
                String value = prop.getAttribute(Const.VALUE);
                propMap.put(key, value);
            }
        }
    }
    builder.addPropertyValue(Const.ATTRIBUTES, propMap);
    AbstractBeanDefinition definition = builder.getRawBeanDefinition();
    definition.setSource(parserContext.extractSource(element));
    return definition;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) List(java.util.List)

Example 59 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder 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)

Example 60 with BeanDefinitionBuilder

use of org.springframework.beans.factory.support.BeanDefinitionBuilder in project loc-framework by lord-of-code.

the class LocElasticJobAutoConfiguration method createSpringJobScheduler.

private void createSpringJobScheduler(String name, List<Object> argList) {
    ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext;
    BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) configurableApplicationContext.getBeanFactory();
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SpringJobScheduler.class);
    builder.setInitMethodName("init");
    for (Object arg : argList) {
        builder.addConstructorArgValue(arg);
    }
    beanDefinitionRegistry.registerBeanDefinition(name, builder.getBeanDefinition());
    log.info("spring bean name {} register success ", name);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)

Aggregations

BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)524 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)116 Element (org.w3c.dom.Element)96 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)61 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)60 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)58 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)53 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)47 ManagedList (org.springframework.beans.factory.support.ManagedList)33 ManagedMap (org.springframework.beans.factory.support.ManagedMap)26 HashMap (java.util.HashMap)19 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)19 Test (org.junit.jupiter.api.Test)16 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)16 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)12 Node (org.w3c.dom.Node)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 TypedStringValue (org.springframework.beans.factory.config.TypedStringValue)10 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)10