All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.springframework.contributions.mapped.MappedContributionUtils Maven / Gradle / Ivy

Go to download

This project adds a so called contribution mechanism (like known from Tapestry IOC or Eclipse Plugins) for configuration and extension of services to the Spring project.

There is a newer version: 2.0.0
Show newest version
package org.springframework.contributions.mapped;

import static org.springframework.contributions.ContributionsNamespaceHandler.MAPPED_CONTRIBUTION_PREFIX;

import java.util.Map;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.MapFactoryBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;

public class MappedContributionUtils
{
    public static BeanDefinition addContribution(String contributionName, Map map, BeanDefinitionRegistry registry)
    {
        final String beanName = MAPPED_CONTRIBUTION_PREFIX + contributionName;
        BeanDefinition beanDefinition;
        if (registry.containsBeanDefinition(beanName))
        {
            beanDefinition = registry.getBeanDefinition(beanName);
            beanDefinition.getPropertyValues().addPropertyValue("sourceMap", map);
        }
        else
        {
            BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(MapFactoryBean.class);
            builder.addPropertyValue("sourceMap", map);
            beanDefinition = builder.getBeanDefinition();
            registry.registerBeanDefinition(beanName, beanDefinition);
        }

        return beanDefinition;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy