Code example for AbstractBeanDefinition

Methods: setBeanClassvalidate

0
 
    private void createAndRegisterLogMessageHandlerChain(final Element element, final ParserContext parserContext, final String logChannelName) {
        BeanDefinitionBuilder loggingHandlerBuilder = BeanDefinitionBuilder.genericBeanDefinition(LoggingHandler.class);
        loggingHandlerBuilder.addConstructorArgValue(element.getAttribute("level"));
        loggingHandlerBuilder.addPropertyValue("shouldLogFullMessage", true);
        final String loggingHandlerBeanName = registerBeanDefinition(parserContext, loggingHandlerBuilder.getBeanDefinition());
 
        ManagedList<RuntimeBeanReference> handlerRefList = new ManagedList<RuntimeBeanReference>();
        handlerRefList.add(new RuntimeBeanReference(loggingHandlerBeanName));
 
        BeanDefinitionBuilder chainBuilder = BeanDefinitionBuilder.genericBeanDefinition(MessageHandlerChain.class);
        chainBuilder.addPropertyValue("handlers", handlerRefList);
        final String logMessageHandlerChainBeanName = registerBeanDefinition(parserContext, chainBuilder.getBeanDefinition());
 
        BeanDefinitionBuilder consumerEndpointbuilder = BeanDefinitionBuilder.genericBeanDefinition(ConsumerEndpointFactoryBean.class);
        consumerEndpointbuilder.addPropertyReference("handler", logMessageHandlerChainBeanName);
        consumerEndpointbuilder.addPropertyValue("inputChannelName", logChannelName);
        BeanDefinitionReaderUtils.registerWithGeneratedName(consumerEndpointbuilder.getBeanDefinition(), parserContext.getRegistry());
    } 
 
    private void createAndRegisterLogWireTap(final Element element, final ParserContext parserContext, final String logChannelName) {
        BeanDefinitionBuilder logWireTapBuilder = BeanDefinitionBuilder.genericBeanDefinition(WireTap.class);
        logWireTapBuilder.addConstructorArgReference(logChannelName);
        final String logWireTapBeanName = registerBeanDefinition(parserContext, logWireTapBuilder.getBeanDefinition());
 
        BeanDefinitionBuilder logWireTapWrapperBuilder = BeanDefinitionBuilder.genericBeanDefinition(GlobalChannelInterceptorWrapper.class);
        logWireTapWrapperBuilder.addConstructorArgReference(logWireTapBeanName);
        String patternAttribute = element.getAttribute("channel-pattern");
        String[] patterns = StringUtils.trimAllWhitespace(patternAttribute).split(",");
        logWireTapWrapperBuilder.addPropertyValue("patterns", patterns);
        final String logWireTapWrapperBeanName = registerBeanDefinition(parserContext, logWireTapWrapperBuilder.getBeanDefinition());
 
        BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(GlobalChannelInterceptorBeanPostProcessor.class);
        ManagedList<RuntimeBeanReference> globalInterceptors = new ManagedList<RuntimeBeanReference>();
        globalInterceptors.add(new RuntimeBeanReference(logWireTapWrapperBeanName));
        postProcessorBuilder.addConstructorArgValue(globalInterceptors);
        registerBeanDefinition(parserContext, postProcessorBuilder.getBeanDefinition());
    } 
 
    /** 
     * Convenience method for registering a bean with a name via the parser context. 
     * @param parserContext the parser context which is used to register the bean 
     * @param beanDef the bean definition itself 
     * @return the generated name assigned to the bean 
     */ 
    private String registerBeanDefinition(final ParserContext parserContext, final AbstractBeanDefinition beanDef) {
        return BeanDefinitionReaderUtils.registerWithGeneratedName(beanDef, parserContext.getRegistry());
    } 
 
}