Coverage Report - org.mule.lifecycle.processor.ProcessIfStartedMessageProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
ProcessIfStartedMessageProcessor
0%
0/9
0%
0/2
0
 
 1  
 /*
 2  
  * $Id$
 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.lifecycle.processor;
 12  
 
 13  
 import org.mule.api.MuleEvent;
 14  
 import org.mule.api.NamedObject;
 15  
 import org.mule.api.lifecycle.LifecycleException;
 16  
 import org.mule.api.lifecycle.LifecycleState;
 17  
 import org.mule.api.lifecycle.Startable;
 18  
 import org.mule.config.i18n.CoreMessages;
 19  
 import org.mule.processor.AbstractFilteringMessageProcessor;
 20  
 
 21  
 public class ProcessIfStartedMessageProcessor extends AbstractFilteringMessageProcessor
 22  
 {
 23  
 
 24  
     protected Startable startable;
 25  
     protected LifecycleState lifecycleState;
 26  
 
 27  
     public ProcessIfStartedMessageProcessor(Startable startable, LifecycleState lifecycleState)
 28  0
     {
 29  0
         this.startable = startable;
 30  0
         this.lifecycleState = lifecycleState;
 31  0
     }
 32  
 
 33  
     @Override
 34  
     protected boolean accept(MuleEvent event)
 35  
     {
 36  0
         return lifecycleState.isStarted();
 37  
     }
 38  
 
 39  
     @Override
 40  
     protected MuleEvent handleUnaccepted(MuleEvent event) throws LifecycleException
 41  
     {
 42  0
         throw new LifecycleException(CoreMessages.isStopped(getStartableName(startable)), event.getMessage());
 43  
     }
 44  
 
 45  
     protected String getStartableName(Startable startableObject)
 46  
     {
 47  0
         if (startableObject instanceof NamedObject)
 48  
         {
 49  0
             return ((NamedObject) startableObject).getName();
 50  
         }
 51  
         else
 52  
         {
 53  0
             return startableObject.toString();
 54  
         }
 55  
     }
 56  
 
 57  
 }