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