Coverage Report - org.apache.camel.processor.Splitter
 
Classes in this File Line Coverage Branch Coverage Complexity
Splitter
100% 
100% 
0
 
 1  
 /**
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.camel.processor;
 18  
 
 19  
 import java.util.Iterator;
 20  
 
 21  
 import org.apache.camel.Exchange;
 22  
 import org.apache.camel.Expression;
 23  
 import org.apache.camel.Processor;
 24  
 import org.apache.camel.converter.ObjectConverter;
 25  
 import org.apache.camel.impl.ServiceSupport;
 26  
 import org.apache.camel.util.ServiceHelper;
 27  
 
 28  
 import static org.apache.camel.util.ObjectHelper.notNull;
 29  
 
 30  
 /**
 31  
  * Implements a dynamic <a
 32  
  * href="http://activemq.apache.org/camel/splitter.html">Splitter</a> pattern
 33  
  * where an expression is evaluated to iterate through each of the parts of a
 34  
  * message and then each part is then send to some endpoint.
 35  
  * 
 36  
  * @version $Revision: 563607 $
 37  
  */
 38  
 public class Splitter extends ServiceSupport implements Processor {
 39  
     private final Processor processor;
 40  
     private final Expression expression;
 41  
 
 42  6
     public Splitter(Expression expression, Processor destination) {
 43  6
         this.processor = destination;
 44  6
         this.expression = expression;
 45  6
         notNull(destination, "destination");
 46  6
         notNull(expression, "expression");
 47  6
     }
 48  
 
 49  
     @Override
 50  
     public String toString() {
 51  12
         return "Splitter[on: " + expression + " to: " + processor + "]";
 52  
     }
 53  
 
 54  
     public void process(Exchange exchange) throws Exception {
 55  3
         Object value = expression.evaluate(exchange);
 56  3
         Iterator iter = ObjectConverter.iterator(value);
 57  15
         while (iter.hasNext()) {
 58  12
             Object part = iter.next();
 59  12
             Exchange newExchange = exchange.copy();
 60  12
             newExchange.getIn().setBody(part);
 61  12
             processor.process(newExchange);
 62  12
         }
 63  3
     }
 64  
 
 65  
     protected void doStart() throws Exception {
 66  3
         ServiceHelper.startServices(processor);
 67  3
     }
 68  
 
 69  
     protected void doStop() throws Exception {
 70  3
         ServiceHelper.stopServices(processor);
 71  3
     }
 72  
 }