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

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

Introduction

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

Prototype

String TYPE_ATTRIBUTE

To view the source code for org.springframework.beans.factory.xml BeanDefinitionParserDelegate TYPE_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;// w ww .ja  v  a 2s . 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();
    }
}

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

/**
 * Return a typed String value Object for the given value element.
 * /*www  . j  a  v  a2 s. c  o  m*/
 * @param ele element
 * @param defaultTypeName type class name
 * @return typed String value Object
 */
private Object parseValueElement(Element ele, String defaultTypeName) {
    // It's a literal value.
    String value = DomUtils.getTextValue(ele);
    String specifiedTypeName = ele.getAttribute(BeanDefinitionParserDelegate.TYPE_ATTRIBUTE);
    String typeName = specifiedTypeName;
    if (!StringUtils.hasText(typeName)) {
        typeName = defaultTypeName;
    }
    try {
        TypedStringValue typedValue = buildTypedStringValue(value, typeName);
        typedValue.setSource(extractSource(ele));
        typedValue.setSpecifiedTypeName(specifiedTypeName);
        return typedValue;
    } catch (ClassNotFoundException ex) {
        error("Type class [" + typeName + "] not found for <value> element", ele, ex);
        return value;
    }
}