Search in sources :

Example 1 with ManagedSet

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

the class BeanDefinitionParserDelegate method parseSetElement.

/**
	 * Parse a set element.
	 */
public Set<Object> parseSetElement(Element collectionEle, BeanDefinition bd) {
    String defaultElementType = collectionEle.getAttribute(VALUE_TYPE_ATTRIBUTE);
    NodeList nl = collectionEle.getChildNodes();
    ManagedSet<Object> target = new ManagedSet<>(nl.getLength());
    target.setSource(extractSource(collectionEle));
    target.setElementTypeName(defaultElementType);
    target.setMergeEnabled(parseMergeAttribute(collectionEle));
    parseCollectionElements(nl, target, bd, defaultElementType);
    return target;
}
Also used : ManagedSet(org.springframework.beans.factory.support.ManagedSet) NodeList(org.w3c.dom.NodeList)

Example 2 with ManagedSet

use of org.springframework.beans.factory.support.ManagedSet 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 3 with ManagedSet

use of org.springframework.beans.factory.support.ManagedSet in project spring-integration by spring-projects.

the class MessageHistoryRegistrar method registerBeanDefinitions.

@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
    Map<String, Object> annotationAttributes = importingClassMetadata.getAnnotationAttributes(EnableMessageHistory.class.getName());
    Object componentNamePatterns = annotationAttributes.get("value");
    if (componentNamePatterns instanceof String[]) {
        StringBuilder componentNamePatternsString = new StringBuilder();
        for (String s : (String[]) componentNamePatterns) {
            componentNamePatternsString.append(s).append(",");
        }
        componentNamePatterns = componentNamePatternsString.substring(0, componentNamePatternsString.length() - 1);
    }
    if (!registry.containsBeanDefinition(IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER_BEAN_NAME)) {
        Set<Object> componentNamePatternsSet = new ManagedSet<Object>();
        componentNamePatternsSet.add(componentNamePatterns);
        AbstractBeanDefinition messageHistoryConfigurer = BeanDefinitionBuilder.genericBeanDefinition(MessageHistoryConfigurer.class).addPropertyValue("componentNamePatternsSet", componentNamePatternsSet).getBeanDefinition();
        registry.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER_BEAN_NAME, messageHistoryConfigurer);
    } else {
        BeanDefinition beanDefinition = registry.getBeanDefinition(IntegrationContextUtils.INTEGRATION_MESSAGE_HISTORY_CONFIGURER_BEAN_NAME);
        PropertyValue propertyValue = beanDefinition.getPropertyValues().getPropertyValue("componentNamePatternsSet");
        if (propertyValue != null) {
            @SuppressWarnings("unchecked") Set<Object> currentComponentNamePatternsSet = (Set<Object>) propertyValue.getValue();
            currentComponentNamePatternsSet.add(componentNamePatterns);
        } else {
            Set<Object> componentNamePatternsSet = new ManagedSet<Object>();
            componentNamePatternsSet.add(componentNamePatterns);
            beanDefinition.getPropertyValues().addPropertyValue("componentNamePatternsSet", componentNamePatternsSet);
        }
    }
}
Also used : ManagedSet(org.springframework.beans.factory.support.ManagedSet) Set(java.util.Set) ManagedSet(org.springframework.beans.factory.support.ManagedSet) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) PropertyValue(org.springframework.beans.PropertyValue) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition)

Example 4 with ManagedSet

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

the class MappingMongoConverterParser method getInitialEntityClasses.

@Nullable
private static Set<String> getInitialEntityClasses(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<>();
    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) Nullable(org.springframework.lang.Nullable)

Example 5 with ManagedSet

use of org.springframework.beans.factory.support.ManagedSet in project spring-integration by spring-projects.

the class IntegrationConverterInitializer method registerConverter.

@SuppressWarnings("unchecked")
public void registerConverter(BeanDefinitionRegistry registry, BeanMetadataElement converterBeanDefinition) {
    Set<BeanMetadataElement> converters = new ManagedSet<BeanMetadataElement>();
    if (!registry.containsBeanDefinition(IntegrationContextUtils.CONVERTER_REGISTRAR_BEAN_NAME)) {
        BeanDefinitionBuilder converterRegistrarBuilder = BeanDefinitionBuilder.genericBeanDefinition(CONTEXT_PACKAGE + "ConverterRegistrar").addConstructorArgValue(converters);
        registry.registerBeanDefinition(IntegrationContextUtils.CONVERTER_REGISTRAR_BEAN_NAME, converterRegistrarBuilder.getBeanDefinition());
        if (!registry.containsBeanDefinition(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME)) {
            registry.registerBeanDefinition(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, new RootBeanDefinition(CONTEXT_PACKAGE + "CustomConversionServiceFactoryBean"));
        }
    } else {
        BeanDefinition converterRegistrarBeanDefinition = registry.getBeanDefinition(IntegrationContextUtils.CONVERTER_REGISTRAR_BEAN_NAME);
        converters = (Set<BeanMetadataElement>) converterRegistrarBeanDefinition.getConstructorArgumentValues().getIndexedArgumentValues().values().iterator().next().getValue();
    }
    converters.add(converterBeanDefinition);
}
Also used : BeanMetadataElement(org.springframework.beans.BeanMetadataElement) ManagedSet(org.springframework.beans.factory.support.ManagedSet) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Aggregations

ManagedSet (org.springframework.beans.factory.support.ManagedSet)6 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)3 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)2 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)2 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)2 ClassPathScanningCandidateComponentProvider (org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider)2 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)2 Persistent (org.springframework.data.annotation.Persistent)2 Document (org.springframework.data.mongodb.core.mapping.Document)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)1 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)1 PropertyValue (org.springframework.beans.PropertyValue)1 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)1 ManagedMap (org.springframework.beans.factory.support.ManagedMap)1 MethodMetadata (org.springframework.core.type.MethodMetadata)1