Coverage Report - org.mule.routing.ExpressionSplitter
 
Classes in this File Line Coverage Branch Coverage Complexity
ExpressionSplitter
0%
0/30
0%
0/8
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.routing;
 8  
 
 9  
 import org.mule.DefaultMuleMessage;
 10  
 import org.mule.api.MuleEvent;
 11  
 import org.mule.api.MuleMessage;
 12  
 import org.mule.api.expression.ExpressionManager;
 13  
 import org.mule.api.lifecycle.Initialisable;
 14  
 import org.mule.api.lifecycle.InitialisationException;
 15  
 import org.mule.expression.ExpressionConfig;
 16  
 
 17  
 import java.util.ArrayList;
 18  
 import java.util.Collections;
 19  
 import java.util.List;
 20  
 
 21  
 /**
 22  
  * Splits a message using the expression provided invoking the next message processor
 23  
  * one for each split part.
 24  
  * <p>
 25  
  * <b>EIP Reference:</b> <a href="http://www.eaipatterns.com/Sequencer.html">http://www.eaipatterns.com/Sequencer.html</a>
 26  
  */
 27  
 public class ExpressionSplitter extends AbstractSplitter
 28  
     implements Initialisable
 29  
 {
 30  
 
 31  
     protected ExpressionManager expressionManager;
 32  0
     protected ExpressionConfig config = new ExpressionConfig();
 33  
 
 34  
     public ExpressionSplitter()
 35  0
     {
 36  
         // Used by spring
 37  0
     }
 38  
 
 39  
     public ExpressionSplitter(ExpressionConfig config)
 40  0
     {
 41  0
         this.config = config;
 42  0
         setEvaluator(config.getEvaluator());
 43  0
     }
 44  
 
 45  
     public void initialise() throws InitialisationException
 46  
     {
 47  0
         expressionManager = muleContext.getExpressionManager();
 48  0
         config.validate(expressionManager);
 49  0
     }
 50  
 
 51  
     protected List<MuleMessage> splitMessage(MuleEvent event)
 52  
     {
 53  0
         Object result = event.getMuleContext().getExpressionManager().evaluate(
 54  
             config.getFullExpression(expressionManager), event.getMessage());
 55  0
         if (result instanceof List<?>)
 56  
         {
 57  0
             List<MuleMessage> messages = new ArrayList<MuleMessage>();
 58  0
             for (Object object : (List<?>) result)
 59  
             {
 60  0
                 messages.add(new DefaultMuleMessage(object, muleContext));
 61  
             }
 62  0
             return messages;
 63  
         }
 64  0
         else if (result instanceof MuleMessage)
 65  
         {
 66  0
             return Collections.singletonList((MuleMessage) result);
 67  
         }
 68  
         else
 69  
         {
 70  0
             return Collections.<MuleMessage> singletonList(new DefaultMuleMessage(result, muleContext));
 71  
         }
 72  
     }
 73  
 
 74  
     public String getCustomEvaluator()
 75  
     {
 76  0
         return config.getCustomEvaluator();
 77  
     }
 78  
 
 79  
     public void setCustomEvaluator(String customEvaluator)
 80  
     {
 81  0
         config.setCustomEvaluator(customEvaluator);
 82  0
     }
 83  
 
 84  
     public String getEvaluator()
 85  
     {
 86  0
         return config.getEvaluator();
 87  
     }
 88  
 
 89  
     public void setEvaluator(String evaluator)
 90  
     {
 91  
         // Switch to XPath node since we want the Dom nodes not the value of the node
 92  0
         if (evaluator.equals("xpath"))
 93  
         {
 94  0
             evaluator = "xpath-node";
 95  
         }
 96  0
         config.setEvaluator(evaluator);
 97  0
     }
 98  
 
 99  
     public String getExpression()
 100  
     {
 101  0
         return config.getExpression();
 102  
     }
 103  
 
 104  
     public void setExpression(String expression)
 105  
     {
 106  0
         this.config.setExpression(expression);
 107  0
     }
 108  
 
 109  
 }