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

pl.chilldev.web.spring.config.HandleTextProcessingBeanDefinitionParser Maven / Gradle / Ivy

There is a newer version: 0.1.2
Show newest version
/**
 * This file is part of the ChillDev-Web.
 *
 * @license http://mit-license.org/ The MIT license
 * @copyright 2015 © by Rafał Wrzeszcz - Wrzasq.pl.
 */

package pl.chilldev.web.spring.config;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;

import org.w3c.dom.Element;

import pl.chilldev.web.core.text.Formatter;

import pl.chilldev.web.spring.text.FormatterFactoryBean;

/**
 * `<handle-text-processing>` element parser.
 */
public class HandleTextProcessingBeanDefinitionParser
    implements
        BeanDefinitionParser
{
    /**
     * Formatter creation method name.
     */
    public static final String METHOD_CREATEPFORMATTER = "createFormatter";

    /**
     * Formatter factorz for aggregating all the info.
     */
    private BeanDefinition formatterFactoryBean;

    /**
     * Assigns formatter for aggregating all the info.
     *
     * @param formatterFactoryBean Formatter bean definition.
     */
    public HandleTextProcessingBeanDefinitionParser(
        BeanDefinition formatterFactoryBean
    )
    {
        this.formatterFactoryBean = formatterFactoryBean;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public BeanDefinition parse(Element element, ParserContext parserContext)
    {
        // page model bean prototype
        GenericBeanDefinition formatterBean = new GenericBeanDefinition();
        formatterBean.setBeanClass(Formatter.class);
        formatterBean.setFactoryBeanName(FormatterFactoryBean.class.getName());
        formatterBean.setFactoryMethodName(HandleTextProcessingBeanDefinitionParser.METHOD_CREATEPFORMATTER);
        parserContext.getRegistry().registerBeanDefinition(Formatter.class.getName(), formatterBean);

        parserContext.getRegistry().registerBeanDefinition(
            FormatterFactoryBean.class.getName(),
            this.formatterFactoryBean
        );

        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy