Search in sources :

Example 51 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project dubbo by alibaba.

the class DubboBeanDefinitionParser method parseNested.

private static void parseNested(Element element, ParserContext parserContext, Class<?> beanClass, boolean required, String tag, String property, String ref, BeanDefinition beanDefinition) {
    NodeList nodeList = element.getChildNodes();
    if (nodeList != null && nodeList.getLength() > 0) {
        boolean first = true;
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if (node instanceof Element) {
                if (tag.equals(node.getNodeName()) || tag.equals(node.getLocalName())) {
                    if (first) {
                        first = false;
                        String isDefault = element.getAttribute("default");
                        if (isDefault == null || isDefault.length() == 0) {
                            beanDefinition.getPropertyValues().addPropertyValue("default", "false");
                        }
                    }
                    BeanDefinition subDefinition = parse((Element) node, parserContext, beanClass, required);
                    if (subDefinition != null && ref != null && ref.length() > 0) {
                        subDefinition.getPropertyValues().addPropertyValue(property, new RuntimeBeanReference(ref));
                    }
                }
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 52 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterParser method getInititalEntityClasses.

private static Set<String> getInititalEntityClasses(Element element) {
    String basePackage = element.getAttribute(BASE_PACKAGE);
    if (!StringUtils.hasText(basePackage)) {
        return null;
    }
    ClassPathScanningCandidateComponentProvider componentProvider = new ClassPathScanningCandidateComponentProvider(false);
    componentProvider.addIncludeFilter(new AnnotationTypeFilter(Document.class));
    componentProvider.addIncludeFilter(new AnnotationTypeFilter(Persistent.class));
    Set<String> classes = new ManagedSet<String>();
    for (BeanDefinition candidate : componentProvider.findCandidateComponents(basePackage)) {
        classes.add(candidate.getBeanClassName());
    }
    return classes;
}
Also used : ManagedSet(org.springframework.beans.factory.support.ManagedSet) AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) ClassPathScanningCandidateComponentProvider(org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider) Persistent(org.springframework.data.annotation.Persistent) Document(org.springframework.data.mongodb.core.mapping.Document) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition)

Example 53 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition 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 54 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project spring-security-oauth by spring-projects.

the class ConfigUtils method findDefaultFilterChainBeanId.

@SuppressWarnings({ "unchecked" })
protected static String findDefaultFilterChainBeanId(ParserContext parserContext) {
    BeanDefinition filterChainList = parserContext.getRegistry().getBeanDefinition(BeanIds.FILTER_CHAINS);
    // Get the list of SecurityFilterChain beans
    List<BeanReference> filterChains = (List<BeanReference>) filterChainList.getPropertyValues().getPropertyValue("sourceList").getValue();
    return filterChains.get(filterChains.size() - 1).getBeanName();
}
Also used : BeanReference(org.springframework.beans.factory.config.BeanReference) List(java.util.List) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 55 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project easy-tests by malinink.

the class EachMapperHaveOwnTestTest method checkEachMapperHaveOwnTest.

@Test
public void checkEachMapperHaveOwnTest() throws Exception {
    final Set<BeanDefinition> mappers = getMappers();
    final Set<BeanDefinition> mappersTests = getMappersTests();
    final Set<Class> mappersClasses = new HashSet<>();
    final Set<Class> mappersWithTestsClasses = new HashSet<>();
    for (BeanDefinition mapper : mappers) {
        mappersClasses.add(Class.forName(mapper.getBeanClassName()));
    }
    for (BeanDefinition mapperTest : mappersTests) {
        final Class mapperTestClass = Class.forName(mapperTest.getBeanClassName());
        final Field mapperField = MapperTestHelper.findMapperFieldInTest(mapperTestClass);
        Assert.assertNotNull(String.format("Mapper '%1$s' use unknown mapper, or mapper have no @Mapper annotation", mapperTestClass.getName()), mapperField);
        mappersWithTestsClasses.add(mapperField.getType());
    }
    for (Class mapperClass : mappersClasses) {
        Assert.assertTrue(String.format("Mapper '%1$s' have no test", mapperClass.getName()), mappersWithTestsClasses.contains(mapperClass));
    }
}
Also used : Field(java.lang.reflect.Field) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)601 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)188 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)116 Test (org.junit.jupiter.api.Test)112 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)89 Element (org.w3c.dom.Element)72 Test (org.junit.Test)66 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)60 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)53 ClassPathScanningCandidateComponentProvider (org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider)41 ManagedList (org.springframework.beans.factory.support.ManagedList)39 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)36 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)35 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)34 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)34 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)31 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)30 Method (java.lang.reflect.Method)28 ArrayList (java.util.ArrayList)28 Map (java.util.Map)27