Java Code Examples for org.springframework.beans.factory.config.BeanDefinition#setFactoryMethodName()

The following examples show how to use org.springframework.beans.factory.config.BeanDefinition#setFactoryMethodName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonGenericObjectDefinitionParser.java    From redisson with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    bd.setFactoryBeanName(element.getAttribute(
            RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
    String typeName
            = Conventions.attributeNameToPropertyName(element.getLocalName());
    bd.setFactoryMethodName("get" + StringUtils.capitalize(typeName));
    
    helper.addConstructorArgs(element, KEY_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, TOPIC_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, PATTERN_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, SERVICE_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, CODEC_REF_ATTRIBUTE,
            Codec.class, builder);
    if (RDestroyable.class.isAssignableFrom(getBeanClass(element))) {
        ((AbstractBeanDefinition) bd).setDestroyMethodName("destroy");
    }
}
 
Example 2
Source File: DasTransactionalEnabler.java    From das with Apache License 2.0 5 votes vote down vote up
private void replaceBeanDefinition() {
    for(String beanName: getBeanDefinitionNames()) {
        BeanDefinition beanDef = getBeanDefinition(beanName);
        String beanClassName = beanDef.getBeanClassName();

        if(beanClassName == null || beanClassName.equals(BEAN_FACTORY_NAME) || isSpringSmartClassLoader(beanDef)) {
            continue;
        }

        Class beanClass;
        try {
            beanClass = Class.forName(beanDef.getBeanClassName());
        } catch (ClassNotFoundException e) {
            throw new BeanDefinitionValidationException("Cannot validate bean: " + beanName, e);
        }

        boolean annotated = false;
        for (Method method : beanClass.getMethods()) {
            if(isTransactionAnnotated(method)) {
                annotated = true;
                break;
            }
        }

        if(!annotated) {
            continue;
        }

        beanDef.setBeanClassName(BEAN_FACTORY_NAME);
        beanDef.setFactoryMethodName(FACTORY_METHOD_NAME);

        ConstructorArgumentValues cav = beanDef.getConstructorArgumentValues();

        if(cav.getArgumentCount() != 0) {
            throw new BeanDefinitionValidationException("The transactional bean can only be instantiated with default constructor.");
        }

        cav.addGenericArgumentValue(beanClass.getName());
    }
}
 
Example 3
Source File: ScheduledAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void severalFixedRatesAgainstNestedCglibProxy() {
	BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
	BeanDefinition targetDefinition = new RootBeanDefinition(SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean.class);
	targetDefinition.setFactoryMethodName("nestedProxy");
	severalFixedRates(context, processorDefinition, targetDefinition);
}
 
Example 4
Source File: ScheduledAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void severalFixedRatesAgainstNestedCglibProxy() {
	BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
	BeanDefinition targetDefinition = new RootBeanDefinition(SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean.class);
	targetDefinition.setFactoryMethodName("nestedProxy");
	severalFixedRates(context, processorDefinition, targetDefinition);
}
 
Example 5
Source File: RedissonReadAndWriteLockDefinitionParser.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    bd.setFactoryBeanName(element.getAttribute(
            RedissonNamespaceParserSupport.READ_WRITE_LOCK_REF_ATTRIBUTE));
    String typeName
            = Conventions.attributeNameToPropertyName(element.getLocalName());
    bd.setFactoryMethodName(typeName);
}
 
Example 6
Source File: DomainTransactionInterceptorInjector.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
    for (String name : beanFactory.getBeanNamesForType(TransactionInterceptor.class, false, false)) {
        BeanDefinition bd = beanFactory.getBeanDefinition(name);
        bd.setBeanClassName(DomainTransactionInterceptor.class.getName());
        bd.setFactoryBeanName(null);
        bd.setFactoryMethodName(null);
    }
}
 
Example 7
Source File: DalTransactionalEnabler.java    From dal with Apache License 2.0 4 votes vote down vote up
private void replaceBeanDefinition() {
    for (String beanName : getBeanDefinitionNames()) {
        BeanDefinition beanDef = getBeanDefinition(beanName);
        String beanClassName = beanDef.getBeanClassName();

        if (beanClassName == null || beanClassName.equals(BEAN_FACTORY_NAME))
            continue;

        Class beanClass;
        try {
            beanClass = Class.forName(beanDef.getBeanClassName());
        } catch (ClassNotFoundException e) {
            throw new BeanDefinitionValidationException("Cannot validate bean: " + beanName, e);
        }

        boolean annotated = false;

        List<Method> methods = new ArrayList<>();
        ReflectUtils.addAllMethods(beanClass, methods);
        List<Method> unsupportedMethods = new ArrayList<>();

        for (int i = 0; i < methods.size(); i++) {
            Method currentMethod = methods.get(i);

            if (isTransactionAnnotated(currentMethod)) {
                if (Modifier.isFinal(currentMethod.getModifiers()) || Modifier.isStatic(currentMethod.getModifiers()) || Modifier.isPrivate(currentMethod.getModifiers()))
                    unsupportedMethods.add(currentMethod);
                annotated = true;
            }
        }

        if (!unsupportedMethods.isEmpty()){
            StringBuilder errMsg=new StringBuilder();
            errMsg.append(String.format("The Methods below are not supported in dal transaction due to private, final or static modifier, please use public,protected or default modifier instead:"));
            errMsg.append("\n");
            int index=1;
            for (Method method : unsupportedMethods) {
                errMsg.append(String.format("%d. %s", index, method.toString()));
                errMsg.append("\n");
                index++;
            }
            throw new DalRuntimeException(errMsg.toString());
        }

        if (!annotated)
            continue;

        beanDef.setBeanClassName(BEAN_FACTORY_NAME);
        beanDef.setFactoryMethodName(FACTORY_METHOD_NAME);

        ConstructorArgumentValues cav = beanDef.getConstructorArgumentValues();

        if (cav.getArgumentCount() != 0)
            throw new BeanDefinitionValidationException("The transactional bean can only be instantiated with default constructor.");

        cav.addGenericArgumentValue(beanClass.getName());
    }
}