Java 类org.springframework.beans.factory.parsing.ConstructorArgumentEntry 实例源码

项目:gemini.blueprint    文件: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;
            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();
        }
    }