
package org.mule.modules.salesforce.config;

import javax.annotation.Generated;
import com.sforce.async.holders.BatchInfoExpressionHolder;
import org.mule.modules.salesforce.processors.BatchResultMessageProcessor;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;

@Generated(value = "Mule DevKit Version 3.4-SNAPSHOT", date = "2012-07-18T11:29:04-05:00", comments = "Build UNKNOWN_BUILDNUMBER")
public class BatchResultDefinitionParser
    extends AbstractDefinitionParser
{


    public BeanDefinition parse(Element element, ParserContext parserContext) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(BatchResultMessageProcessor.class.getName());
        parseConfigRef(element, builder);
        if (!parseObjectRef(element, builder, "batch-info", "batchInfo")) {
            BeanDefinitionBuilder batchInfoBuilder = BeanDefinitionBuilder.rootBeanDefinition(BatchInfoExpressionHolder.class.getName());
            Element batchInfoChildElement = DomUtils.getChildElementByTagName(element, "batch-info");
            if (batchInfoChildElement!= null) {
                parseProperty(batchInfoBuilder, batchInfoChildElement, "id");
                parseProperty(batchInfoBuilder, batchInfoChildElement, "jobId");
                parseProperty(batchInfoBuilder, batchInfoChildElement, "state");
                parseProperty(batchInfoBuilder, batchInfoChildElement, "stateMessage");
                if (hasAttribute(batchInfoChildElement, "createdDate-ref")) {
                    if (batchInfoChildElement.getAttribute("createdDate-ref").startsWith("#")) {
                        batchInfoBuilder.addPropertyValue("createdDate", batchInfoChildElement.getAttribute("createdDate-ref"));
                    } else {
                        batchInfoBuilder.addPropertyValue("createdDate", (("#[registry:"+ batchInfoChildElement.getAttribute("createdDate-ref"))+"]"));
                    }
                }
                if (hasAttribute(batchInfoChildElement, "systemModstamp-ref")) {
                    if (batchInfoChildElement.getAttribute("systemModstamp-ref").startsWith("#")) {
                        batchInfoBuilder.addPropertyValue("systemModstamp", batchInfoChildElement.getAttribute("systemModstamp-ref"));
                    } else {
                        batchInfoBuilder.addPropertyValue("systemModstamp", (("#[registry:"+ batchInfoChildElement.getAttribute("systemModstamp-ref"))+"]"));
                    }
                }
                parseProperty(batchInfoBuilder, batchInfoChildElement, "numberRecordsProcessed");
                parseProperty(batchInfoBuilder, batchInfoChildElement, "numberRecordsFailed");
                parseProperty(batchInfoBuilder, batchInfoChildElement, "totalProcessingTime");
                parseProperty(batchInfoBuilder, batchInfoChildElement, "apiActiveProcessingTime");
                parseProperty(batchInfoBuilder, batchInfoChildElement, "apexProcessingTime");
                builder.addPropertyValue("batchInfo", batchInfoBuilder.getBeanDefinition());
            }
        }
        parseProperty(builder, element, "username");
        parseProperty(builder, element, "password");
        parseProperty(builder, element, "securityToken");
        BeanDefinition definition = builder.getBeanDefinition();
        setNoRecurseOnDefinition(definition);
        attachProcessorDefinition(parserContext, definition);
        return definition;
    }

}
