Example usage for org.springframework.beans.factory.xml BeanDefinitionParserDelegate INDEX_ATTRIBUTE

List of usage examples for org.springframework.beans.factory.xml BeanDefinitionParserDelegate INDEX_ATTRIBUTE

Introduction

In this page you can find the example usage for org.springframework.beans.factory.xml BeanDefinitionParserDelegate INDEX_ATTRIBUTE.

Prototype

String INDEX_ATTRIBUTE

To view the source code for org.springframework.beans.factory.xml BeanDefinitionParserDelegate INDEX_ATTRIBUTE.

Click Source Link

Usage

From source file:org.eclipse.gemini.blueprint.blueprint.config.internal.BlueprintParser.java

private void parseConstructorArgElement(Element ele, AbstractBeanDefinition beanDefinition) {

    String indexAttr = ele.getAttribute(BeanDefinitionParserDelegate.INDEX_ATTRIBUTE);
    String typeAttr = ele.getAttribute(BeanDefinitionParserDelegate.TYPE_ATTRIBUTE);

    boolean hasIndex = false;
    int index = -1;

    if (StringUtils.hasLength(indexAttr)) {
        hasIndex = true;/*from w  ww  .j  av a2  s  . com*/
        try {
            index = Integer.parseInt(indexAttr);
        } catch (NumberFormatException ex) {
            error("Attribute 'index' of tag 'constructor-arg' must be an integer", ele);
        }

        if (index < 0) {
            error("'index' cannot be lower than 0", ele);
        }
    }

    try {
        this.parseState.push(hasIndex ? new ConstructorArgumentEntry(index) : new ConstructorArgumentEntry());

        ConstructorArgumentValues values = beanDefinition.getConstructorArgumentValues();
        // Blueprint failure (index duplication)
        Integer indexInt = Integer.valueOf(index);
        if (values.getIndexedArgumentValues().containsKey(indexInt)) {
            error("duplicate 'index' with value=[" + index + "] specified", ele);
        }

        Object value = parsePropertyValue(ele, beanDefinition, null);
        ConstructorArgumentValues.ValueHolder valueHolder = new ConstructorArgumentValues.ValueHolder(value);
        if (StringUtils.hasLength(typeAttr)) {
            valueHolder.setType(typeAttr);
        }
        valueHolder.setSource(extractSource(ele));

        if (hasIndex) {
            values.addIndexedArgumentValue(index, valueHolder);
        } else {
            values.addGenericArgumentValue(valueHolder);
        }
        // Blueprint failure (mixed index/non-indexed arguments)
        if (!values.getGenericArgumentValues().isEmpty() && !values.getIndexedArgumentValues().isEmpty()) {
            error("indexed and non-indexed constructor arguments are not supported by Blueprint; "
                    + "consider using the Spring namespace instead", ele);
        }
    } finally {
        this.parseState.pop();
    }
}