Coverage Report - org.mule.config.spring.factories.AbstractFlowConstructFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractFlowConstructFactoryBean
0%
0/23
0%
0/4
0
AbstractFlowConstructFactoryBean$NullFlowConstruct
0%
0/3
N/A
0
 
 1  
 /*
 2  
  * $Id: AbstractFlowConstructFactoryBean.java 20013 2010-10-27 11:24:22Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.config.spring.factories;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.MuleException;
 15  
 import org.mule.api.construct.FlowConstruct;
 16  
 import org.mule.api.context.MuleContextAware;
 17  
 import org.mule.api.endpoint.InboundEndpoint;
 18  
 import org.mule.api.exception.MessagingExceptionHandler;
 19  
 import org.mule.api.lifecycle.Initialisable;
 20  
 import org.mule.api.lifecycle.InitialisationException;
 21  
 import org.mule.api.source.MessageSource;
 22  
 import org.mule.construct.AbstractFlowConstruct;
 23  
 import org.mule.construct.builder.AbstractFlowConstructBuilder;
 24  
 import org.mule.construct.builder.AbstractFlowConstructWithSingleInboundEndpointBuilder;
 25  
 import org.mule.processor.builder.InterceptingChainMessageProcessorBuilder;
 26  
 
 27  
 import org.springframework.beans.BeansException;
 28  
 import org.springframework.beans.factory.FactoryBean;
 29  
 import org.springframework.beans.factory.InitializingBean;
 30  
 import org.springframework.context.ApplicationContext;
 31  
 import org.springframework.context.ApplicationContextAware;
 32  
 
 33  0
 public abstract class AbstractFlowConstructFactoryBean implements FactoryBean<FlowConstruct>, 
 34  
     InitializingBean, ApplicationContextAware, MuleContextAware, Initialisable
 35  
 {
 36  0
     private static final NullFlowConstruct NULL_FLOW_CONSTRUCT = new NullFlowConstruct("noop", null);
 37  
 
 38  
     /*
 39  
      * Shameful hack, read FIXME below
 40  
      */
 41  
     private static final class NullFlowConstruct extends AbstractFlowConstruct
 42  
     {
 43  
         public NullFlowConstruct(String name, MuleContext muleContext)
 44  
         {
 45  0
             super(name, muleContext);
 46  0
         }
 47  
 
 48  
         @Override
 49  
         protected void configureMessageProcessors(InterceptingChainMessageProcessorBuilder builder)
 50  
         {
 51  
             // NOOP
 52  0
         }
 53  
     }
 54  
 
 55  
     protected ApplicationContext applicationContext;
 56  
     protected MuleContext muleContext;
 57  
 
 58  
     // FIXME terrible hack to get around the first call to getObject that comes too
 59  
     // soon (nothing is injected yet)
 60  0
     protected AbstractFlowConstruct flowConstruct = NULL_FLOW_CONSTRUCT;
 61  
 
 62  
     public boolean isSingleton()
 63  
     {
 64  0
         return true;
 65  
     }
 66  
 
 67  
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
 68  
     {
 69  0
         this.applicationContext = applicationContext;
 70  0
     }
 71  
 
 72  
     public void setMuleContext(MuleContext muleContext)
 73  
     {
 74  0
         this.muleContext = muleContext;
 75  0
     }
 76  
 
 77  
     protected abstract AbstractFlowConstructBuilder<? extends AbstractFlowConstructBuilder<?, ?>, ? extends AbstractFlowConstruct> getFlowConstructBuilder();
 78  
 
 79  
     public void setName(String name)
 80  
     {
 81  0
         getFlowConstructBuilder().name(name);
 82  0
     }
 83  
 
 84  
     public void setMessageSource(MessageSource messageSource)
 85  
     {
 86  0
         final AbstractFlowConstructBuilder<?, ?> flowConstructBuilder = getFlowConstructBuilder();
 87  
 
 88  0
         if ((flowConstructBuilder instanceof AbstractFlowConstructWithSingleInboundEndpointBuilder<?, ?>)
 89  
             && (messageSource instanceof InboundEndpoint))
 90  
         {
 91  0
             ((AbstractFlowConstructWithSingleInboundEndpointBuilder<?, ?>) flowConstructBuilder).inboundEndpoint((InboundEndpoint) messageSource);
 92  
         }
 93  
         else
 94  
         {
 95  0
             flowConstructBuilder.messageSource(messageSource);
 96  
         }
 97  0
     }
 98  
 
 99  
     public void setExceptionListener(MessagingExceptionHandler exceptionListener)
 100  
     {
 101  0
         getFlowConstructBuilder().exceptionStrategy(exceptionListener);
 102  0
     }
 103  
 
 104  
     public void afterPropertiesSet() throws Exception
 105  
     {
 106  0
         flowConstruct = createFlowConstruct();
 107  0
     }
 108  
 
 109  
     public void initialise() throws InitialisationException
 110  
     {
 111  0
         flowConstruct.initialise();
 112  0
     }
 113  
 
 114  
     public FlowConstruct getObject() throws Exception
 115  
     {
 116  0
         return flowConstruct;
 117  
     }
 118  
 
 119  
     protected AbstractFlowConstruct createFlowConstruct() throws MuleException
 120  
     {
 121  0
         return getFlowConstructBuilder().build(muleContext);
 122  
     }
 123  
 }