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

org.springframework.contributions.ordered.OrderedContributionRefBeanDefinitionParser 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.ordered;

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

import org.springframework.beans.factory.config.BeanReferenceFactoryBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

/**
 * Parses contribution-ref element in Spring XML config.
 *
 * @author Christian Köberl
 */
@SuppressWarnings("rawtypes")
public class OrderedContributionRefBeanDefinitionParser extends AbstractSingleBeanDefinitionParser
{
    @Override
    protected Class getBeanClass(Element element)
    {
        return BeanReferenceFactoryBean.class;
    }

    @Override
    protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
    {
        String contributionName = element.getAttribute("name");
        String beanName = ORDERED_CONTRIBUTION_PREFIX + contributionName;

        BeanDefinitionRegistry registry = parserContext.getRegistry();
        if (!registry.containsBeanDefinition(beanName))
        {
            BeanDefinitionBuilder contributionBeanBuilder =
                BeanDefinitionBuilder.rootBeanDefinition(OrderedConfigurationFactoryBean.class);

            contributionBeanBuilder.addPropertyValue("contributionList", new ManagedList());

            parserContext.getRegistry().registerBeanDefinition(beanName, contributionBeanBuilder.getBeanDefinition());
        }

        builder.addPropertyValue("targetBeanName", beanName);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy