Search in sources :

Example 26 with BeanDefinitionHolder

use of org.springframework.beans.factory.config.BeanDefinitionHolder in project mule by mulesoft.

the class DefaultListableBeanFactory method isAutowireCandidate.

/**
 * Determine whether the specified bean definition qualifies as an autowire candidate, to be injected into other beans which
 * declare a dependency of matching type.
 *
 * @param beanName the name of the bean definition to check
 * @param mbd the merged bean definition to check
 * @param descriptor the descriptor of the dependency to resolve
 * @param resolver the AutowireCandidateResolver to use for the actual resolution algorithm
 * @return whether the bean should be considered as autowire candidate
 */
protected boolean isAutowireCandidate(String beanName, RootBeanDefinition mbd, DependencyDescriptor descriptor, AutowireCandidateResolver resolver) {
    String beanDefinitionName = BeanFactoryUtils.transformedBeanName(beanName);
    resolveBeanClass(mbd, beanDefinitionName);
    if (mbd.isFactoryMethodUnique) {
        boolean resolve;
        synchronized (mbd.constructorArgumentLock) {
            resolve = (mbd.resolvedConstructorOrFactoryMethod == null);
        }
        if (resolve) {
            new ConstructorResolver(this).resolveFactoryMethodIfPossible(mbd);
        }
    }
    return resolver.isAutowireCandidate(new BeanDefinitionHolder(mbd, beanName, getAliases(beanDefinitionName)), descriptor);
}
Also used : BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder)

Example 27 with BeanDefinitionHolder

use of org.springframework.beans.factory.config.BeanDefinitionHolder in project camunda-bpm-platform by camunda.

the class StateHandlerAnnotationBeanFactoryPostProcessor method configureDefaultActivitiRegistry.

private void configureDefaultActivitiRegistry(String registryBeanName, BeanDefinitionRegistry registry) {
    if (!beanAlreadyConfigured(registry, registryBeanName, ActivitiStateHandlerRegistry.class)) {
        String registryName = ActivitiStateHandlerRegistry.class.getName();
        log.info("registering a " + registryName + " instance under bean name " + ActivitiContextUtils.ACTIVITI_REGISTRY_BEAN_NAME + ".");
        RootBeanDefinition rootBeanDefinition = new RootBeanDefinition();
        rootBeanDefinition.setBeanClassName(registryName);
        rootBeanDefinition.getPropertyValues().addPropertyValue("processEngine", this.processEngine);
        BeanDefinitionHolder holder = new BeanDefinitionHolder(rootBeanDefinition, registryBeanName);
        BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
    }
}
Also used : BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ActivitiStateHandlerRegistry(org.camunda.bpm.engine.spring.components.registry.ActivitiStateHandlerRegistry)

Example 28 with BeanDefinitionHolder

use of org.springframework.beans.factory.config.BeanDefinitionHolder in project service-proxy by membrane.

the class AbstractParser method handleChildElement.

protected void handleChildElement(Element ele, ParserContext parserContext, BeanDefinitionBuilder builder) {
    BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
    try {
        Object o = delegate.parsePropertySubElement(ele, builder.getBeanDefinition());
        String clazz = null;
        if (o instanceof BeanDefinitionHolder) {
            clazz = ((BeanDefinitionHolder) o).getBeanDefinition().getBeanClassName();
        } else if (o instanceof RuntimeBeanReference) {
            clazz = parserContext.getRegistry().getBeanDefinition(((RuntimeBeanReference) o).getBeanName()).getBeanClassName();
        } else if (o instanceof RuntimeBeanNameReference) {
            clazz = parserContext.getRegistry().getBeanDefinition(((RuntimeBeanNameReference) o).getBeanName()).getBeanClassName();
        } else {
            parserContext.getReaderContext().error("Don't know how to get bean class from " + o.getClass(), ele);
        }
        handleChildObject(ele, parserContext, builder, Class.forName(clazz), o);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : BeanDefinitionParserDelegate(org.springframework.beans.factory.xml.BeanDefinitionParserDelegate) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) RuntimeBeanNameReference(org.springframework.beans.factory.config.RuntimeBeanNameReference)

Example 29 with BeanDefinitionHolder

use of org.springframework.beans.factory.config.BeanDefinitionHolder in project sandbox by irof.

the class AhogeScanner method doScan.

@Override
protected Set<BeanDefinitionHolder> doScan(String... basePackages) {
    Set<BeanDefinitionHolder> beanDefinitionHolders = super.doScan(basePackages);
    for (BeanDefinitionHolder holder : beanDefinitionHolders) {
        // インタフェースのままだとBean生成できないので定義を上書きする
        // コンストラクタ引数にインタフェース(ex.Fuga)を与えるようにして、
        // BeanClassを FactoryBean の AhogeFactory にすげ替える。
        // これで Spring が AhogeFactory を使ってインスタンスを作ってくれるようになる。
        GenericBeanDefinition definition = (GenericBeanDefinition) holder.getBeanDefinition();
        definition.getConstructorArgumentValues().addGenericArgumentValue(definition.getBeanClassName());
        definition.setBeanClass(AhogeFactory.class);
    }
    return beanDefinitionHolders;
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder)

Example 30 with BeanDefinitionHolder

use of org.springframework.beans.factory.config.BeanDefinitionHolder in project pinpoint by naver.

the class ClassPathDefinitionScannerDoScanInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (result == null || throwable != null || !(result instanceof Set)) {
        return;
    }
    try {
        final Set<Object> set = (Set<Object>) result;
        for (Object o : set) {
            if (o instanceof BeanDefinitionHolder) {
                final BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) o;
                if (filter.isTarget(SpringBeansTargetScope.COMPONENT_SCAN, beanDefinitionHolder.getBeanName(), beanDefinitionHolder.getBeanDefinition())) {
                    final String className = beanDefinitionHolder.getBeanDefinition().getBeanClassName();
                    this.instrumentor.transform(this.classLoader, className, this.transformer);
                    this.filter.addTransformed(className);
                }
            }
        }
    } catch (Throwable t) {
        if (logger.isWarnEnabled()) {
            logger.warn("AFTER. Caused:{}", t.getMessage(), t);
        }
    }
}
Also used : Set(java.util.Set) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder)

Aggregations

BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)94 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)30 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)20 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)18 Element (org.w3c.dom.Element)18 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)16 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)16 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)12 ManagedList (org.springframework.beans.factory.support.ManagedList)11 Node (org.w3c.dom.Node)11 ArrayList (java.util.ArrayList)8 ManagedMap (org.springframework.beans.factory.support.ManagedMap)6 LinkedHashSet (java.util.LinkedHashSet)5 Test (org.junit.jupiter.api.Test)5 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)5 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)5 NamedNodeMap (org.w3c.dom.NamedNodeMap)5 NodeList (org.w3c.dom.NodeList)5 Method (java.lang.reflect.Method)4 HashSet (java.util.HashSet)4