Coverage Report - org.mule.api.processor.MessageProcessors
 
Classes in this File Line Coverage Branch Coverage Complexity
MessageProcessors
0%
0/4
N/A
1.545
MessageProcessors$LifecyleAwareMessageProcessorWrapper
0%
0/22
0%
0/12
1.545
 
 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.api.processor;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.MuleEvent;
 11  
 import org.mule.api.MuleException;
 12  
 import org.mule.api.construct.FlowConstruct;
 13  
 import org.mule.api.construct.FlowConstructAware;
 14  
 import org.mule.api.context.MuleContextAware;
 15  
 import org.mule.api.lifecycle.Disposable;
 16  
 import org.mule.api.lifecycle.Initialisable;
 17  
 import org.mule.api.lifecycle.InitialisationException;
 18  
 import org.mule.api.lifecycle.Lifecycle;
 19  
 import org.mule.api.lifecycle.Startable;
 20  
 import org.mule.api.lifecycle.Stoppable;
 21  
 import org.mule.processor.chain.DefaultMessageProcessorChain;
 22  
 
 23  
 /**
 24  
  * Some convenience methods for message processors.
 25  
  */
 26  
 public class MessageProcessors
 27  
 {
 28  
 
 29  
     private MessageProcessors()
 30  0
     {
 31  
         // do not instantiate
 32  0
     }
 33  
 
 34  
     public static MessageProcessorChain singletonChain(MessageProcessor mp)
 35  
     {
 36  0
         return DefaultMessageProcessorChain.from(mp);
 37  
     }
 38  
 
 39  
     public static MessageProcessor lifecyleAwareMessageProcessorWrapper(final MessageProcessor mp)
 40  
     {
 41  0
         return new LifecyleAwareMessageProcessorWrapper(mp);
 42  
     }
 43  
 
 44  
     private static class LifecyleAwareMessageProcessorWrapper
 45  
         implements MessageProcessor, Lifecycle, MuleContextAware, FlowConstructAware
 46  
     {
 47  
         private MessageProcessor delegate;
 48  
 
 49  
         public LifecyleAwareMessageProcessorWrapper(MessageProcessor delegate)
 50  0
         {
 51  0
             this.delegate = delegate;
 52  0
         }
 53  
 
 54  
         public void initialise() throws InitialisationException
 55  
         {
 56  0
             if (delegate instanceof Initialisable)
 57  
             {
 58  0
                 ((Initialisable) delegate).initialise();
 59  
             }
 60  
 
 61  0
         }
 62  
 
 63  
         public void start() throws MuleException
 64  
         {
 65  0
             if (delegate instanceof Startable)
 66  
             {
 67  0
                 ((Startable) delegate).start();
 68  
             }
 69  
 
 70  0
         }
 71  
 
 72  
         public void stop() throws MuleException
 73  
         {
 74  0
             if (delegate instanceof Stoppable)
 75  
             {
 76  0
                 ((Stoppable) delegate).stop();
 77  
             }
 78  
 
 79  0
         }
 80  
 
 81  
         public void dispose()
 82  
         {
 83  0
             if (delegate instanceof Disposable)
 84  
             {
 85  0
                 ((Disposable) delegate).dispose();
 86  
             }
 87  
 
 88  0
         }
 89  
 
 90  
         public void setFlowConstruct(FlowConstruct flowConstruct)
 91  
         {
 92  0
             if (delegate instanceof FlowConstructAware)
 93  
             {
 94  0
                 ((FlowConstructAware) delegate).setFlowConstruct(flowConstruct);
 95  
             }
 96  
 
 97  0
         }
 98  
 
 99  
         public void setMuleContext(MuleContext context)
 100  
         {
 101  0
             if (delegate instanceof MuleContextAware)
 102  
             {
 103  0
                 ((MuleContextAware) delegate).setMuleContext(context);
 104  
             }
 105  
 
 106  0
         }
 107  
 
 108  
         public MuleEvent process(MuleEvent event) throws MuleException
 109  
         {
 110  0
             return delegate.process(event);
 111  
         }
 112  
     }
 113  
 }