Example usage for org.springframework.beans.factory.support AutowireCandidateQualifier setAttribute

List of usage examples for org.springframework.beans.factory.support AutowireCandidateQualifier setAttribute

Introduction

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

Prototype

@Override
    public void setAttribute(String name, @Nullable Object value) 

Source Link

Usage

From source file:org.os890.ds.addon.spring.impl.CdiAwareBeanFactoryPostProcessor.java

private BeanDefinition createSpringBeanDefinition(Bean<?> cdiBean) throws Exception {
    AbstractBeanDefinition beanDefinition = new GenericBeanDefinition();
    Set<Type> beanTypes = new HashSet<Type>(cdiBean.getTypes());
    beanTypes.remove(Object.class);
    beanTypes.remove(Serializable.class);

    Type beanType = beanTypes.size() == 1 ? beanTypes.iterator().next() : null;

    if (beanType instanceof Class) { //to support producers
        beanDefinition.setBeanClass((Class) beanType);
    } else { //fallback since spring doesn't support multiple types
        beanDefinition.setBeanClass(cdiBean.getBeanClass());
    }/*from ww w  . j a v  a2s  .com*/

    beanDefinition.setScope(CdiSpringScope.class.getName());

    for (Annotation qualifier : cdiBean.getQualifiers()) {
        if (Any.class.equals(qualifier.annotationType()) || Default.class.equals(qualifier.annotationType())) {
            continue;
        }
        //currently only simple qualifiers are supported
        AutowireCandidateQualifier springQualifier = new AutowireCandidateQualifier(qualifier.annotationType());

        for (Method annotationMethod : qualifier.annotationType().getDeclaredMethods()) {
            if (!annotationMethod.isAnnotationPresent(Nonbinding.class)) {
                springQualifier.setAttribute(annotationMethod.getName(), annotationMethod.invoke(qualifier));
            }
        }
        beanDefinition.addQualifier(springQualifier);
    }
    beanDefinition.setLazyInit(true);
    return beanDefinition;
}

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

/**
 * Parse a qualifier element.//from  ww  w .  j av a  2  s. c om
 */
public void parseQualifierElement(Element ele, AbstractBeanDefinition bd) {
    String typeName = ele.getAttribute(TYPE_ATTRIBUTE);
    if (!StringUtils.hasLength(typeName)) {
        error("Tag 'qualifier' must have a 'type' attribute", ele);
        return;
    }
    this.parseState.push(new QualifierEntry(typeName));
    try {
        AutowireCandidateQualifier qualifier = new AutowireCandidateQualifier(typeName);
        qualifier.setSource(extractSource(ele));
        String value = ele.getAttribute(VALUE_ATTRIBUTE);
        if (StringUtils.hasLength(value)) {
            qualifier.setAttribute(AutowireCandidateQualifier.VALUE_KEY, value);
        }
        NodeList nl = ele.getChildNodes();
        for (int i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            if (isCandidateElement(node) && nodeNameEquals(node, QUALIFIER_ATTRIBUTE_ELEMENT)) {
                Element attributeEle = (Element) node;
                String attributeName = attributeEle.getAttribute(KEY_ATTRIBUTE);
                String attributeValue = attributeEle.getAttribute(VALUE_ATTRIBUTE);
                if (StringUtils.hasLength(attributeName) && StringUtils.hasLength(attributeValue)) {
                    BeanMetadataAttribute attribute = new BeanMetadataAttribute(attributeName, attributeValue);
                    attribute.setSource(extractSource(attributeEle));
                    qualifier.addMetadataAttribute(attribute);
                } else {
                    error("Qualifier 'attribute' tag must have a 'name' and 'value'", attributeEle);
                    return;
                }
            }
        }
        bd.addQualifier(qualifier);
    } finally {
        this.parseState.pop();
    }
}