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