Example usage for org.springframework.beans.factory.config ConstructorArgumentValues addIndexedArgumentValue

List of usage examples for org.springframework.beans.factory.config ConstructorArgumentValues addIndexedArgumentValue

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config ConstructorArgumentValues addIndexedArgumentValue.

Prototype

public void addIndexedArgumentValue(int index, @Nullable Object value, String type) 

Source Link

Document

Add an argument value for the given index in the constructor argument list.

Usage

From source file:org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.java

/**
 * Parse a constructor-arg element./*from  w  ww  . j a  v a2  s .  c  o m*/
 */
protected void parseConstructorArgElement(Element ele, String beanName, ConstructorArgumentValues cargs)
        throws BeanDefinitionStoreException {

    Object val = parsePropertyValue(ele, beanName, null);
    String indexAttr = ele.getAttribute(INDEX_ATTRIBUTE);
    String typeAttr = ele.getAttribute(TYPE_ATTRIBUTE);
    if (StringUtils.hasLength(indexAttr)) {
        try {
            int index = Integer.parseInt(indexAttr);
            if (index < 0) {
                throw new BeanDefinitionStoreException(getResource(), beanName,
                        "'index' cannot be lower than 0");
            }
            if (StringUtils.hasLength(typeAttr)) {
                cargs.addIndexedArgumentValue(index, val, typeAttr);
            } else {
                cargs.addIndexedArgumentValue(index, val);
            }
        } catch (NumberFormatException ex) {
            throw new BeanDefinitionStoreException(getResource(), beanName,
                    "Attribute 'index' of tag 'constructor-arg' must be an integer");
        }
    } else {
        if (StringUtils.hasLength(typeAttr)) {
            cargs.addGenericArgumentValue(val, typeAttr);
        } else {
            cargs.addGenericArgumentValue(val);
        }
    }
}