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