Example usage for org.springframework.beans.factory.support BeanDefinitionBuilder getBeanDefinition

List of usage examples for org.springframework.beans.factory.support BeanDefinitionBuilder getBeanDefinition

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support BeanDefinitionBuilder getBeanDefinition.

Prototype

public AbstractBeanDefinition getBeanDefinition() 

Source Link

Document

Validate and return the created BeanDefinition object.

Usage

From source file:com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceExporter.java

/**
 * Registers the new beans with the bean factory.
 *//* w  ww. jav a  2 s .  c om*/
private void registerServiceProxy(DefaultListableBeanFactory dlbf, String servicePath, String serviceBeanName) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(JsonServiceExporter.class)
            .addPropertyReference("service", serviceBeanName);
    BeanDefinition serviceBeanDefinition = findBeanDefintion(dlbf, serviceBeanName);
    for (Class<?> iface : getBeanInterfaces(serviceBeanDefinition, dlbf.getBeanClassLoader())) {
        if (iface.isAnnotationPresent(JsonRpcService.class)) {
            String serviceInterface = iface.getName();
            LOG.fine(format("Registering interface '%s' for JSON-RPC bean [%s].", serviceInterface,
                    serviceBeanName));
            builder.addPropertyValue("serviceInterface", serviceInterface);
            break;
        }
    }
    if (objectMapper != null) {
        builder.addPropertyValue("objectMapper", objectMapper);
    }

    if (errorResolver != null) {
        builder.addPropertyValue("errorResolver", errorResolver);
    }

    if (invocationListener != null) {
        builder.addPropertyValue("invocationListener", invocationListener);
    }

    if (registerTraceInterceptor != null) {
        builder.addPropertyValue("registerTraceInterceptor", registerTraceInterceptor);
    }

    builder.addPropertyValue("backwardsComaptible", Boolean.valueOf(backwardsComaptible));
    builder.addPropertyValue("rethrowExceptions", Boolean.valueOf(rethrowExceptions));
    builder.addPropertyValue("allowExtraParams", Boolean.valueOf(allowExtraParams));
    builder.addPropertyValue("allowLessParams", Boolean.valueOf(allowLessParams));
    builder.addPropertyValue("exceptionLogLevel", exceptionLogLevel);
    dlbf.registerBeanDefinition(servicePath, builder.getBeanDefinition());
}

From source file:it.pronetics.madstore.common.configuration.spring.MadStoreConfigurationBeanDefinitionParser.java

@SuppressWarnings("unchecked")
private void parseTasksConfiguration(Element tasksElement, BeanDefinitionBuilder beanDefinitionBuilder)
        throws NumberFormatException, MadStoreConfigurationException, DOMException {
    List<Element> taskElements = DomUtils.getChildElementsByTagName(tasksElement, TASK_TAG);
    Map<String, SimpleTriggerConfiguration> triggerTasks = new ManagedMap();
    for (Element task : taskElements) {
        String key = task.getAttribute(TASK_NAME);
        Element simpleTriggerConfigurationElement = DomUtils.getChildElementByTagName(task,
                SIMPLE_TRIGGER_CONFIGURATION_TAG);
        String startDelaySt = DomUtils.getChildElementByTagName(simpleTriggerConfigurationElement, START_DELAY)
                .getTextContent();/*  w  ww . j av a 2 s . c  om*/
        String repeatIntervalSt = DomUtils
                .getChildElementByTagName(simpleTriggerConfigurationElement, REPEAT_INTERVAL).getTextContent();
        if ("".equals(startDelaySt) || "".equals(repeatIntervalSt)) {
            throw new MadStoreConfigurationException("Parameters startDelay and repeatInterval in "
                    + SIMPLE_TRIGGER_CONFIGURATION_TAG + " tag cannot be empty.");
        }
        SimpleTriggerConfiguration simpleTriggerConfiguration = new SimpleTriggerConfiguration();
        simpleTriggerConfiguration.setStartDelay(new Integer(startDelaySt).intValue());
        simpleTriggerConfiguration.setRepeatInterval(new Integer(repeatIntervalSt).intValue());
        triggerTasks.put(key, simpleTriggerConfiguration);
    }
    beanDefinitionBuilder.addPropertyValue(TASKS_CONFIGURATION_BEAN_PROPERTY, triggerTasks);

    List<CrawlerConfiguration> crawlerConfigurations = (List<CrawlerConfiguration>) beanDefinitionBuilder
            .getBeanDefinition().getPropertyValues().getPropertyValue(CRAWLER_CONFIGURATIONS_BEAN_PROPERTY)
            .getValue();

    if (triggerTasks.keySet().contains(CRAWLER_TASK) && crawlerConfigurations.size() == 0) {
        throw new MadStoreConfigurationException("Crawler task cannot exist without crawler tag definition!");
    }
}

From source file:org.apache.ftpserver.config.spring.UserManagerBeanDefinitionParser.java

@Override
protected void doParse(final Element element, final ParserContext parserContext,
        final BeanDefinitionBuilder builder) {

    Class<?> factoryClass;// w  ww  . jav  a 2 s .c o  m
    if (element.getLocalName().equals("file-user-manager")) {
        factoryClass = PropertiesUserManagerFactory.class;
    } else {
        factoryClass = DbUserManagerFactory.class;
    }
    BeanDefinitionBuilder factoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(factoryClass);

    // common for both user managers
    if (StringUtils.hasText(element.getAttribute("encrypt-passwords"))) {
        String encryptionStrategy = element.getAttribute("encrypt-passwords");

        if (encryptionStrategy.equals("true") || encryptionStrategy.equals("md5")) {
            factoryBuilder.addPropertyValue("passwordEncryptor", new Md5PasswordEncryptor());
        } else if (encryptionStrategy.equals("salted")) {
            factoryBuilder.addPropertyValue("passwordEncryptor", new SaltedPasswordEncryptor());
        } else {
            factoryBuilder.addPropertyValue("passwordEncryptor", new ClearTextPasswordEncryptor());
        }
    }

    if (factoryClass == PropertiesUserManagerFactory.class) {
        if (StringUtils.hasText(element.getAttribute("file"))) {
            factoryBuilder.addPropertyValue("file", element.getAttribute("file"));
        }
        if (StringUtils.hasText(element.getAttribute("url"))) {
            factoryBuilder.addPropertyValue("url", element.getAttribute("url"));
        }
    } else {
        Element dsElm = SpringUtil.getChildElement(element, FtpServerNamespaceHandler.FTPSERVER_NS,
                "data-source");

        // schema ensure we get the right type of element
        Element springElm = SpringUtil.getChildElement(dsElm, null, null);
        Object o;
        if ("bean".equals(springElm.getLocalName())) {
            o = parserContext.getDelegate().parseBeanDefinitionElement(springElm, builder.getBeanDefinition());
        } else {
            // ref
            o = parserContext.getDelegate().parsePropertySubElement(springElm, builder.getBeanDefinition());

        }
        factoryBuilder.addPropertyValue("dataSource", o);

        factoryBuilder.addPropertyValue("sqlUserInsert", getSql(element, "insert-user"));
        factoryBuilder.addPropertyValue("sqlUserUpdate", getSql(element, "update-user"));
        factoryBuilder.addPropertyValue("sqlUserDelete", getSql(element, "delete-user"));
        factoryBuilder.addPropertyValue("sqlUserSelect", getSql(element, "select-user"));
        factoryBuilder.addPropertyValue("sqlUserSelectAll", getSql(element, "select-all-users"));
        factoryBuilder.addPropertyValue("sqlUserAdmin", getSql(element, "is-admin"));
        factoryBuilder.addPropertyValue("sqlUserAuthenticate", getSql(element, "authenticate"));
    }

    BeanDefinition factoryDefinition = factoryBuilder.getBeanDefinition();
    String factoryId = parserContext.getReaderContext().generateBeanName(factoryDefinition);

    BeanDefinitionHolder factoryHolder = new BeanDefinitionHolder(factoryDefinition, factoryId);
    registerBeanDefinition(factoryHolder, parserContext.getRegistry());

    // set the factory on the listener bean
    builder.getRawBeanDefinition().setFactoryBeanName(factoryId);
    builder.getRawBeanDefinition().setFactoryMethodName("createUserManager");

}

From source file:org.apache.smscserver.config.spring.UserManagerBeanDefinitionParser.java

@Override
protected void doParse(final Element element, final ParserContext parserContext,
        final BeanDefinitionBuilder builder) {

    Class<?> factoryClass;/*from w w  w .  ja va  2  s . c o m*/
    if (element.getLocalName().equals("file-user-manager")) {
        factoryClass = PropertiesUserManagerFactory.class;
    } else {
        factoryClass = DbUserManagerFactory.class;
    }

    BeanDefinitionBuilder factoryBuilder = BeanDefinitionBuilder.genericBeanDefinition(factoryClass);

    // common for both user managers
    if (StringUtils.hasText(element.getAttribute("encrypt-passwords"))) {
        String encryptionStrategy = element.getAttribute("encrypt-passwords");

        if (encryptionStrategy.equals("true") || encryptionStrategy.equals("md5")) {
            factoryBuilder.addPropertyValue("passwordEncryptor", new Md5PasswordEncryptor());
        } else if (encryptionStrategy.equals("salted")) {
            factoryBuilder.addPropertyValue("passwordEncryptor", new SaltedPasswordEncryptor());
        } else {
            factoryBuilder.addPropertyValue("passwordEncryptor", new ClearTextPasswordEncryptor());
        }
    }

    if (factoryClass == PropertiesUserManagerFactory.class) {
        if (StringUtils.hasText(element.getAttribute("file"))) {
            factoryBuilder.addPropertyValue("file", element.getAttribute("file"));
        }
        if (StringUtils.hasText(element.getAttribute("url"))) {
            factoryBuilder.addPropertyValue("url", element.getAttribute("url"));
        }
    } else {
        Element dsElm = SpringUtil.getChildElement(element, SmscServerNamespaceHandler.SMSCSERVER_NS,
                "data-source");

        // schema ensure we get the right type of element
        Element springElm = SpringUtil.getChildElement(dsElm, null, null);
        Object o;
        if ("bean".equals(springElm.getLocalName())) {
            o = parserContext.getDelegate().parseBeanDefinitionElement(springElm, builder.getBeanDefinition());
        } else {
            // ref
            o = parserContext.getDelegate().parsePropertySubElement(springElm, builder.getBeanDefinition());

        }
        factoryBuilder.addPropertyValue("dataSource", o);

        factoryBuilder.addPropertyValue("sqlUserInsert", this.getSql(element, "insert-user"));
        factoryBuilder.addPropertyValue("sqlUserUpdate", this.getSql(element, "update-user"));
        factoryBuilder.addPropertyValue("sqlUserDelete", this.getSql(element, "delete-user"));
        factoryBuilder.addPropertyValue("sqlUserSelect", this.getSql(element, "select-user"));
        factoryBuilder.addPropertyValue("sqlUserSelectAll", this.getSql(element, "select-all-users"));
        factoryBuilder.addPropertyValue("sqlUserAdmin", this.getSql(element, "is-admin"));
        factoryBuilder.addPropertyValue("sqlUserAuthenticate", this.getSql(element, "authenticate"));
    }

    BeanDefinition factoryDefinition = factoryBuilder.getBeanDefinition();
    String factoryId = parserContext.getReaderContext().generateBeanName(factoryDefinition);

    BeanDefinitionHolder factoryHolder = new BeanDefinitionHolder(factoryDefinition, factoryId);
    this.registerBeanDefinition(factoryHolder, parserContext.getRegistry());

    // set the factory on the listener bean
    builder.getRawBeanDefinition().setFactoryBeanName(factoryId);
    builder.getRawBeanDefinition().setFactoryMethodName("createUserManager");

}

From source file:com.mtgi.analytics.aop.config.v11.BtPersisterChainBeanDefinitionParser.java

@Override
@SuppressWarnings("unchecked")
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    //propagate shared template factory into sub-components if necessary.  this would not be
    //necessary if parserContext gave us access to the entire component stack instead of just the
    //top.  In that case, deeply nested children could search up the stack until they found
    //the template.  perhaps a future version of the Spring API will support this.
    DefaultListableBeanFactory template = findEnclosingTemplateFactory(parserContext);
    if (template != null)
        parserContext.pushContainingComponent(new TemplateComponentDefinition(element.getNodeName(),
                parserContext.extractSource(element), template));

    try {/*from  w w  w. ja v  a 2 s  . c o m*/
        //parse delegate persister definitions
        ManagedList persisters = new ManagedList();
        persisters.setSource(element);

        NodeList nodes = element.getChildNodes();
        for (int i = 0; i < nodes.getLength(); ++i) {
            Node node = nodes.item(i);
            if (node.getNodeType() == Node.ELEMENT_NODE) {
                String namespaceUri = node.getNamespaceURI();
                NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver()
                        .resolve(namespaceUri);
                Object def = handler == null
                        ? parserContext.getDelegate().parsePropertySubElement((Element) node,
                                builder.getRawBeanDefinition())
                        : handler.parse((Element) node, parserContext);
                persisters.add(def);
            }
        }
        builder.addPropertyValue("delegates", persisters);
    } finally {
        if (template != null)
            parserContext.popContainingComponent();
    }

    //register persister implementation with parent.
    if (parserContext.isNested()) {
        AbstractBeanDefinition def = builder.getBeanDefinition();
        String id = element.hasAttribute("id") ? element.getAttribute("id")
                : parserContext.getReaderContext().generateBeanName(def);
        BeanDefinitionHolder holder = new BeanDefinitionHolder(def, id);
        BtManagerBeanDefinitionParser.registerNestedBean(holder, "persister", parserContext);
    }
}

From source file:com.dangdang.ddframe.job.spring.namespace.parser.common.AbstractJobBeanDefinitionParser.java

private String createJobConfiguration(final Element element, final ParserContext parserContext) {
    BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(getJobConfigurationDTO());
    factory.addConstructorArgValue(element.getAttribute(ID_ATTRIBUTE));
    if (!getJobConfigurationDTO().isAssignableFrom(ScriptJobConfigurationDto.class)) {
        factory.addConstructorArgValue(element.getAttribute(CLASS_ATTRIBUTE));
    }/*from  ww w.  j  a v  a  2s.  com*/
    factory.addConstructorArgValue(element.getAttribute(SHARDING_TOTAL_COUNT_ATTRIBUTE));
    factory.addConstructorArgValue(element.getAttribute(CRON_ATTRIBUTE));
    if (getJobConfigurationDTO().isAssignableFrom(ScriptJobConfigurationDto.class)) {
        factory.addConstructorArgValue(element.getAttribute(SCRIPT_COMMAND_LINE_ATTRIBUTE));
    }
    addPropertyValueIfNotEmpty(SHARDING_ITEM_PARAMETERS_ATTRIBUTE, "shardingItemParameters", element, factory);
    addPropertyValueIfNotEmpty(JOB_PARAMETER_ATTRIBUTE, "jobParameter", element, factory);
    addPropertyValueIfNotEmpty(MONITOR_EXECUTION_ATTRIBUTE, "monitorExecution", element, factory);
    addPropertyValueIfNotEmpty(MONITOR_PORT_ATTRIBUTE, "monitorPort", element, factory);
    addPropertyValueIfNotEmpty(MAX_TIME_DIFF_SECONDS_ATTRIBUTE, "maxTimeDiffSeconds", element, factory);
    addPropertyValueIfNotEmpty(FAILOVER_ATTRIBUTE, "failover", element, factory);
    addPropertyValueIfNotEmpty(MISFIRE_ATTRIBUTE, "misfire", element, factory);
    addPropertyValueIfNotEmpty(JOB_SHARDING_STRATEGY_CLASS_ATTRIBUTE, "jobShardingStrategyClass", element,
            factory);
    addPropertyValueIfNotEmpty(DESCRIPTION_ATTRIBUTE, "description", element, factory);
    addPropertyValueIfNotEmpty(DISABLED_ATTRIBUTE, "disabled", element, factory);
    addPropertyValueIfNotEmpty(OVERWRITE_ATTRIBUTE, "overwrite", element, factory);
    setPropertiesValue(element, factory);
    String result = element.getAttribute(ID_ATTRIBUTE) + "Conf";
    parserContext.getRegistry().registerBeanDefinition(result, factory.getBeanDefinition());
    return result;
}

From source file:com.dangdang.ddframe.job.spring.namespace.JobBeanDefinitionParser.java

private String createJobConfiguration(final Element element, final ParserContext parserContext) {
    BeanDefinitionBuilder factory = BeanDefinitionBuilder
            .rootBeanDefinition("com.dangdang.ddframe.job.api.JobConfiguration");
    String className = element.getAttribute("class");
    //TODO ,job:dataflow,job:simple,job:script,job:sequence
    if (Strings.isNullOrEmpty(className)) {
        Preconditions.checkNotNull(element.getAttribute("scriptCommandLine"),
                "Cannot find script command line.");
        className = "com.dangdang.ddframe.job.plugin.job.type.integrated.ScriptElasticJob";
    }/*w w w  . j a va  2 s .com*/
    factory.addConstructorArgValue(element.getAttribute("id"));
    factory.addConstructorArgValue(className);
    factory.addConstructorArgValue(element.getAttribute("shardingTotalCount"));
    factory.addConstructorArgValue(element.getAttribute("cron"));
    addPropertyValueIfNotEmpty("shardingItemParameters", element, factory);
    addPropertyValueIfNotEmpty("jobParameter", element, factory);
    addPropertyValueIfNotEmpty("monitorExecution", element, factory);
    addPropertyValueIfNotEmpty("monitorPort", element, factory);
    addPropertyValueIfNotEmpty("processCountIntervalSeconds", element, factory);
    addPropertyValueIfNotEmpty("concurrentDataProcessThreadCount", element, factory);
    addPropertyValueIfNotEmpty("fetchDataCount", element, factory);
    addPropertyValueIfNotEmpty("maxTimeDiffSeconds", element, factory);
    addPropertyValueIfNotEmpty("failover", element, factory);
    addPropertyValueIfNotEmpty("misfire", element, factory);
    addPropertyValueIfNotEmpty("jobShardingStrategyClass", element, factory);
    addPropertyValueIfNotEmpty("description", element, factory);
    addPropertyValueIfNotEmpty("disabled", element, factory);
    addPropertyValueIfNotEmpty("overwrite", element, factory);
    addPropertyValueIfNotEmpty("scriptCommandLine", element, factory);
    String result = element.getAttribute("id") + "Conf";
    parserContext.getRegistry().registerBeanDefinition(result, factory.getBeanDefinition());
    return result;
}

From source file:org.opencredo.couchdb.config.CouchDbInboundChannelAdapterParser.java

@Override
protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = null;
    String databaseUrl = element.getAttribute(COUCHDB_DATABASE_URL_ATTRIBUTE);
    String changesOperations = element.getAttribute(COUCHDB_CHANGES_OPERATIONS_ATTRIBUTE);
    String allDocuments = element.getAttribute(COUCHDB_ALL_DOCUMENTS_ATTRIBUTE);
    String allDocumentsLimit = element.getAttribute(COUCHDB_ALL_DOCUMENTS_LIMIT_ATTRIBUTE);

    if (StringUtils.hasText(databaseUrl)) {
        if (StringUtils.hasText(changesOperations)) {
            parserContext.getReaderContext().error("At most one of '" + COUCHDB_DATABASE_URL_ATTRIBUTE
                    + "' and '" + COUCHDB_CHANGES_OPERATIONS_ATTRIBUTE + "' may be provided.", element);
        } else {//from  ww  w.j  a  v  a 2 s . c  om
            if ("true".equals(allDocuments)) {
                builder = BeanDefinitionBuilder.genericBeanDefinition(CouchDbAllDocumentsMessageSource.class);
            } else {
                builder = BeanDefinitionBuilder.genericBeanDefinition(CouchDbChangesPollingMessageSource.class);
            }
            builder.addConstructorArgValue(databaseUrl);
        }
    } else if (StringUtils.hasText(changesOperations)) {
        // changesOperations and allDocuments are XOR
        if ("true".equals(allDocuments)) {
            parserContext.getReaderContext().error("At most one of '" + COUCHDB_ALL_DOCUMENTS_ATTRIBUTE
                    + "' and '" + COUCHDB_CHANGES_OPERATIONS_ATTRIBUTE + "' may be provided.", element);
        } else {
            builder = BeanDefinitionBuilder.genericBeanDefinition(CouchDbChangesPollingMessageSource.class);
            builder.addConstructorArgReference(changesOperations);
        }
    } else {
        parserContext.getReaderContext().error("Either '" + COUCHDB_DATABASE_URL_ATTRIBUTE + "' or '"
                + COUCHDB_CHANGES_OPERATIONS_ATTRIBUTE + "' must be provided.", element);
    }

    if ("true".equals(allDocuments)) {
        builder.addConstructorArgValue(Integer.valueOf(allDocumentsLimit));
    }

    String beanName = BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(),
            parserContext.getRegistry());
    return new RuntimeBeanReference(beanName);
}

From source file:org.mule.transport.zmq.config.OutboundEndpointDefinitionParser.java

public BeanDefinition parse(Element element, ParserContext parserContent) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder
            .rootBeanDefinition(OutboundEndpointMessageProcessor.class.getName());
    String configRef = element.getAttribute("config-ref");
    if ((configRef != null) && (!StringUtils.isBlank(configRef))) {
        builder.addPropertyValue("moduleObject", configRef);
    }/*from   ww  w  . ja v  a 2 s.  co m*/
    if ((element.getAttribute("payload-ref") != null)
            && (!StringUtils.isBlank(element.getAttribute("payload-ref")))) {
        if (element.getAttribute("payload-ref").startsWith("#")) {
            builder.addPropertyValue("payload", element.getAttribute("payload-ref"));
        } else {
            builder.addPropertyValue("payload", (("#[registry:" + element.getAttribute("payload-ref")) + "]"));
        }
    }
    if ((element.getAttribute("retryMax") != null)
            && (!StringUtils.isBlank(element.getAttribute("retryMax")))) {
        builder.addPropertyValue("retryMax", element.getAttribute("retryMax"));
    }
    if (element.hasAttribute("exchange-pattern")) {
        builder.addPropertyValue("exchangePattern", element.getAttribute("exchange-pattern"));
    }
    if (element.hasAttribute("socket-operation")) {
        builder.addPropertyValue("socketOperation", element.getAttribute("socket-operation"));
    }
    if ((element.getAttribute("address") != null) && (!StringUtils.isBlank(element.getAttribute("address")))) {
        builder.addPropertyValue("address", element.getAttribute("address"));
    }
    if ((element.getAttribute("filter") != null) && (!StringUtils.isBlank(element.getAttribute("filter")))) {
        builder.addPropertyValue("filter", element.getAttribute("filter"));
    }
    if ((element.getAttribute("identity") != null)
            && (!StringUtils.isBlank(element.getAttribute("identity")))) {
        builder.addPropertyValue("identity", element.getAttribute("identity"));
    }
    if ((element.getAttribute("multipart") != null)
            && (!StringUtils.isBlank(element.getAttribute("multipart")))) {
        builder.addPropertyValue("multipart", element.getAttribute("multipart"));
    }
    BeanDefinition definition = builder.getBeanDefinition();
    definition.setAttribute(MuleHierarchicalBeanDefinitionParserDelegate.MULE_NO_RECURSE, Boolean.TRUE);
    MutablePropertyValues propertyValues = parserContent.getContainingBeanDefinition().getPropertyValues();
    if (parserContent.getContainingBeanDefinition().getBeanClassName()
            .equals("org.mule.config.spring.factories.PollingMessageSourceFactoryBean")) {
        propertyValues.addPropertyValue("messageProcessor", definition);
    } else {
        if (parserContent.getContainingBeanDefinition().getBeanClassName()
                .equals("org.mule.enricher.MessageEnricher")) {
            propertyValues.addPropertyValue("enrichmentMessageProcessor", definition);
        } else {
            PropertyValue messageProcessors = propertyValues.getPropertyValue("messageProcessors");
            if ((messageProcessors == null) || (messageProcessors.getValue() == null)) {
                propertyValues.addPropertyValue("messageProcessors", new ManagedList());
            }
            List listMessageProcessors = ((List) propertyValues.getPropertyValue("messageProcessors")
                    .getValue());
            listMessageProcessors.add(definition);
        }
    }
    return definition;
}

From source file:biz.c24.io.spring.batch.config.ItemReaderParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) {

    // Optional/*from w ww  .j  av  a2  s.c  om*/
    String scope = element.getAttribute("scope");
    if (StringUtils.hasText(scope)) {
        bean.setScope(scope);
    } else {
        // Default to step scope
        bean.setScope("step");
    }

    int numSourceDefns = 0;

    // Optional
    String sourceRef = element.getAttribute("source-ref");
    if (StringUtils.hasText(sourceRef)) {
        bean.addPropertyReference("source", sourceRef);
        numSourceDefns++;
    }

    // Mandatory
    String modelRef = element.getAttribute("model-ref");
    bean.addPropertyReference("model", modelRef);

    // Optional
    String elementStartPattern = element.getAttribute("elementStartPattern");
    if (StringUtils.hasText(elementStartPattern)) {
        bean.addPropertyValue("elementStartPattern", elementStartPattern);
    }

    // Optional
    String elementStopPattern = element.getAttribute("elementStopPattern");
    if (StringUtils.hasText(elementStopPattern)) {
        bean.addPropertyValue("elementStopPattern", elementStopPattern);
    }

    // Optional
    String validate = element.getAttribute("validate");
    if (StringUtils.hasText(validate)) {
        bean.addPropertyValue("validate", validate); //don't evaluate as a boolean until Bean creation time to allow for SpEL
    }

    // Optional
    String failfast = element.getAttribute("failfast");
    if (StringUtils.hasText(failfast)) {
        boolean val = Boolean.parseBoolean(failfast);
        bean.addPropertyValue("failfast", val);
    }

    // Optional
    String sourceFactoryRef = element.getAttribute("source-factory-ref");
    if (StringUtils.hasText(sourceFactoryRef)) {
        bean.addPropertyReference("sourceFactory", sourceFactoryRef);
    }

    // Optional
    String parseListenerRef = element.getAttribute("parse-listener-ref");
    if (StringUtils.hasText(parseListenerRef)) {
        bean.addPropertyReference("parseListener", parseListenerRef);
    }

    Element fileSourceElement = DomUtils.getChildElementByTagName(element, "file-source");
    if (fileSourceElement != null) {
        BeanDefinition beanDefinition = parserContext.getDelegate().parseCustomElement(fileSourceElement,
                bean.getBeanDefinition());
        beanDefinition.setBeanClassName(FileSource.class.getName());
        bean.addPropertyValue("source", beanDefinition);
        numSourceDefns++;
    }

    Element zipFileSourceElement = DomUtils.getChildElementByTagName(element, "zip-file-source");
    if (zipFileSourceElement != null) {
        BeanDefinition beanDefinition = parserContext.getDelegate().parseCustomElement(zipFileSourceElement,
                bean.getBeanDefinition());
        beanDefinition.setBeanClassName(ZipFileSource.class.getName());
        bean.addPropertyValue("source", beanDefinition);
        numSourceDefns++;
    }

    if (numSourceDefns > 1) {
        parserContext.getReaderContext()
                .error("Only one of source-ref, file-source and zip-file-source can be used", element);
    } else if (numSourceDefns == 0) {
        parserContext.getReaderContext()
                .error("One of source-ref, file-source and zip-file-source must be specified", element);
    }

}