Coverage Report - org.mule.config.dsl.routers.ContentBasedRouter
 
Classes in this File Line Coverage Branch Coverage Complexity
ContentBasedRouter
0%
0/18
0%
0/12
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.dsl.routers;
 8  
 
 9  
 import org.mule.RequestContext;
 10  
 import org.mule.api.MessagingException;
 11  
 import org.mule.api.MuleEvent;
 12  
 import org.mule.api.MuleException;
 13  
 import org.mule.api.MuleMessage;
 14  
 import org.mule.api.endpoint.ImmutableEndpoint;
 15  
 import org.mule.api.processor.MessageProcessor;
 16  
 import org.mule.routing.outbound.AbstractOutboundRouter;
 17  
 
 18  
 /**
 19  
  * TODO
 20  
  */
 21  0
 public class ContentBasedRouter extends AbstractOutboundRouter
 22  
 {
 23  
     @Override
 24  
     public MuleEvent route(MuleEvent theEvent) throws MessagingException
 25  
     {
 26  0
         MuleMessage message = theEvent.getMessage();
 27  
 
 28  0
         for (MessageProcessor target : routes)
 29  
         {
 30  
             try
 31  
             {
 32  0
                 if (isMatch(message))
 33  
                 {
 34  0
                     MuleEvent event = RequestContext.setEvent(theEvent);
 35  0
                     return target.process(event);
 36  
                 }
 37  
             }
 38  0
             catch (MuleException e)
 39  
             {
 40  0
                 throw new MessagingException(e.getI18nMessage(), theEvent, e);
 41  0
             }
 42  
         }
 43  
         //TODO
 44  0
         throw new RuntimeException("Event not processed");
 45  
     }
 46  
 
 47  
     public boolean isMatch(MuleMessage message) throws MuleException
 48  
     {
 49  0
         for (MessageProcessor target : routes)
 50  
         {
 51  0
             if (target instanceof ImmutableEndpoint)
 52  
             {
 53  0
                 ImmutableEndpoint endpoint = (ImmutableEndpoint)target;
 54  0
                 if (endpoint.getFilter() == null || endpoint.getFilter().accept(message))
 55  
                 {
 56  0
                     return true;
 57  
                 }
 58  0
             }
 59  
             else
 60  
             {
 61  0
                 return true;
 62  
             }
 63  
         }
 64  0
         return false;
 65  
     }
 66  
 }