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/4
N/A
0
 
 1  
 /*
 2  
  * $Id: AbstractFlowConstructFactoryBean.java 20203 2010-11-17 01:54:38Z mike.schilling $
 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.processor.MessageProcessorChainBuilder;
 22  
 import org.mule.api.source.MessageSource;
 23  
 import org.mule.construct.AbstractFlowConstruct;
 24  
 import org.mule.construct.builder.AbstractFlowConstructBuilder;
 25  
 import org.mule.construct.builder.AbstractFlowConstructWithSingleInboundEndpointBuilder;
 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(MessageProcessorChainBuilder builder)
 50  
         {
 51  
             // NOOP
 52  0
         }
 53  
 
 54  
         @Override
 55  
         public String getConstructType()
 56  
         {
 57  0
             return "NULL";
 58  
         }
 59  
     }
 60  
 
 61  
     protected ApplicationContext applicationContext;
 62  
     protected MuleContext muleContext;
 63  
 
 64  
     // FIXME terrible hack to get around the first call to getObject that comes too
 65  
     // soon (nothing is injected yet)
 66  0
     protected AbstractFlowConstruct flowConstruct = NULL_FLOW_CONSTRUCT;
 67  
 
 68  
     public boolean isSingleton()
 69  
     {
 70  0
         return true;
 71  
     }
 72  
 
 73  
     public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
 74  
     {
 75  0
         this.applicationContext = applicationContext;
 76  0
     }
 77  
 
 78  
     public void setMuleContext(MuleContext muleContext)
 79  
     {
 80  0
         this.muleContext = muleContext;
 81  0
     }
 82  
 
 83  
     protected abstract AbstractFlowConstructBuilder<? extends AbstractFlowConstructBuilder<?, ?>, ? extends AbstractFlowConstruct> getFlowConstructBuilder();
 84  
 
 85  
     public void setName(String name)
 86  
     {
 87  0
         getFlowConstructBuilder().name(name);
 88  0
     }
 89  
 
 90  
     public void setMessageSource(MessageSource messageSource)
 91  
     {
 92  0
         final AbstractFlowConstructBuilder<?, ?> flowConstructBuilder = getFlowConstructBuilder();
 93  
 
 94  0
         if ((flowConstructBuilder instanceof AbstractFlowConstructWithSingleInboundEndpointBuilder<?, ?>)
 95  
             && (messageSource instanceof InboundEndpoint))
 96  
         {
 97  0
             ((AbstractFlowConstructWithSingleInboundEndpointBuilder<?, ?>) flowConstructBuilder).inboundEndpoint((InboundEndpoint) messageSource);
 98  
         }
 99  
         else
 100  
         {
 101  0
             flowConstructBuilder.messageSource(messageSource);
 102  
         }
 103  0
     }
 104  
 
 105  
     public void setExceptionListener(MessagingExceptionHandler exceptionListener)
 106  
     {
 107  0
         getFlowConstructBuilder().exceptionStrategy(exceptionListener);
 108  0
     }
 109  
 
 110  
     public void afterPropertiesSet() throws Exception
 111  
     {
 112  0
         flowConstruct = createFlowConstruct();
 113  0
     }
 114  
 
 115  
     public void initialise() throws InitialisationException
 116  
     {
 117  0
         flowConstruct.initialise();
 118  0
     }
 119  
 
 120  
     public FlowConstruct getObject() throws Exception
 121  
     {
 122  0
         return flowConstruct;
 123  
     }
 124  
 
 125  
     protected AbstractFlowConstruct createFlowConstruct() throws MuleException
 126  
     {
 127  0
         return getFlowConstructBuilder().build(muleContext);
 128  
     }
 129  
 }