
package org.mule.modules.salesforce.config;

import java.util.Map;
import javax.annotation.Generated;
import com.sforce.async.holders.JobInfoExpressionHolder;
import org.mule.modules.salesforce.config.AbstractDefinitionParser.ParseDelegate;
import org.mule.modules.salesforce.config.AbstractDefinitionParser.ParseDelegate;
import org.mule.modules.salesforce.processors.CreateBatchMessageProcessor;
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 CreateBatchDefinitionParser
    extends AbstractDefinitionParser
{


    public BeanDefinition parse(Element element, ParserContext parserContext) {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(CreateBatchMessageProcessor.class.getName());
        parseConfigRef(element, builder);
        if (!parseObjectRef(element, builder, "job-info", "jobInfo")) {
            BeanDefinitionBuilder jobInfoBuilder = BeanDefinitionBuilder.rootBeanDefinition(JobInfoExpressionHolder.class.getName());
            Element jobInfoChildElement = DomUtils.getChildElementByTagName(element, "job-info");
            if (jobInfoChildElement!= null) {
                parseProperty(jobInfoBuilder, jobInfoChildElement, "id");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "operation");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "object");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "createdById");
                if (hasAttribute(jobInfoChildElement, "createdDate-ref")) {
                    if (jobInfoChildElement.getAttribute("createdDate-ref").startsWith("#")) {
                        jobInfoBuilder.addPropertyValue("createdDate", jobInfoChildElement.getAttribute("createdDate-ref"));
                    } else {
                        jobInfoBuilder.addPropertyValue("createdDate", (("#[registry:"+ jobInfoChildElement.getAttribute("createdDate-ref"))+"]"));
                    }
                }
                if (hasAttribute(jobInfoChildElement, "systemModstamp-ref")) {
                    if (jobInfoChildElement.getAttribute("systemModstamp-ref").startsWith("#")) {
                        jobInfoBuilder.addPropertyValue("systemModstamp", jobInfoChildElement.getAttribute("systemModstamp-ref"));
                    } else {
                        jobInfoBuilder.addPropertyValue("systemModstamp", (("#[registry:"+ jobInfoChildElement.getAttribute("systemModstamp-ref"))+"]"));
                    }
                }
                parseProperty(jobInfoBuilder, jobInfoChildElement, "state");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "externalIdFieldName");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "concurrencyMode");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "numberBatchesQueued");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "numberBatchesInProgress");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "numberBatchesCompleted");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "numberBatchesFailed");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "numberBatchesTotal");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "numberRecordsProcessed");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "numberRetries");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "contentType");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "apiVersion");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "assignmentRuleId");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "numberRecordsFailed");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "totalProcessingTime");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "apiActiveProcessingTime");
                parseProperty(jobInfoBuilder, jobInfoChildElement, "apexProcessingTime");
                builder.addPropertyValue("jobInfo", jobInfoBuilder.getBeanDefinition());
            }
        }
        parseListAndSetProperty(element, builder, "objects", "objects", "object", new ParseDelegate<Map>() {


            public Map parse(Element element) {
                return parseMap(element, "inner-object", new ParseDelegate<String>() {


                    public String parse(Element element) {
                        return element.getTextContent();
                    }

                }
                );
            }

        }
        );
        parseProperty(builder, element, "username");
        parseProperty(builder, element, "password");
        parseProperty(builder, element, "securityToken");
        BeanDefinition definition = builder.getBeanDefinition();
        setNoRecurseOnDefinition(definition);
        attachProcessorDefinition(parserContext, definition);
        return definition;
    }

}
