Package org.gwtoolbox.springrpc

Source Code of org.gwtoolbox.springrpc.GwtServiceScanParser

package org.gwtoolbox.springrpc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.*;
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;

/**
* @author Uri Boness
*/
public class GwtServiceScanParser extends AbstractBeanDefinitionParser {

    private final static Logger logger = LoggerFactory.getLogger(GwtServiceScanParser.class);


    private final static String PATH_PREFIX_ATTR = "path-prefix";
    private final static String UNEXPECTED_EXCEPTION_MAPPTINS_DEF = "unexpected-exception-mappings";
    private final static String MAPPING_DEF = "mapping";
    private final static String THROWABLE_CLASS_ATTR = "throwable-class";
    private final static String STATUS_CODE_ATTR = "status-code";
    private final static String MESSAGE_ATTR = "message";

    protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
        String pathPrefix = element.getAttribute(PATH_PREFIX_ATTR);

        GenericBeanDefinition definition = new GenericBeanDefinition();
        definition.setBeanClass(GwtServiceBeanFactoryPostProcessor.class);

        MutablePropertyValues propertyValues = new MutablePropertyValues();
        propertyValues.addPropertyValue("pathPrefix", new TypedStringValue(pathPrefix));

        Element mappingsElement = DomUtils.getChildElementByTagName(element, UNEXPECTED_EXCEPTION_MAPPTINS_DEF);

        if (mappingsElement != null) {

            ManagedList<RootBeanDefinition> mappingList = new ManagedList<RootBeanDefinition>();
            for (Element mappingElement : DomUtils.getChildElementsByTagName(mappingsElement, MAPPING_DEF)) {
                BeanDefinitionBuilder mappingBuilder = BeanDefinitionBuilder.rootBeanDefinition(UnexpectedExceptionMapping.class);
                String throwableClassName = mappingElement.getAttribute(THROWABLE_CLASS_ATTR);
                String statusCode = mappingElement.getAttribute(STATUS_CODE_ATTR);
                String message = mappingElement.getAttribute(MESSAGE_ATTR);
                mappingBuilder.addConstructorArgValue(throwableClassName);
                mappingBuilder.addConstructorArgValue(statusCode);
                mappingBuilder.addConstructorArgValue(message);
                mappingList.add((RootBeanDefinition) mappingBuilder.getBeanDefinition());
            }

            BeanDefinitionBuilder mappingsBuilder = BeanDefinitionBuilder.rootBeanDefinition(UnexpectedExceptionMappings.class);
            mappingsBuilder.addConstructorArgValue(mappingList);
            RootBeanDefinition mappingsBeanDefinition = (RootBeanDefinition) mappingsBuilder.getBeanDefinition();
            String id = parserContext.getReaderContext().registerWithGeneratedName(mappingsBeanDefinition);

            logger.info("Registered UnexpectedExceptionMappgins bean with id '" + id + "'");

            propertyValues.addPropertyValue("unexpectedExceptionMappingsBeanName", new TypedStringValue(id));

        }

        definition.setPropertyValues(propertyValues);

        return definition;
    }

    @Override
    protected boolean shouldGenerateId() {
        return true;
    }

}
TOP

Related Classes of org.gwtoolbox.springrpc.GwtServiceScanParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.