Coverage Report - org.apache.camel.builder.ProcessorBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
ProcessorBuilder
19% 
N/A 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.builder;
 19  
 
 20  
 import org.apache.camel.Exchange;
 21  
 import org.apache.camel.Expression;
 22  
 import org.apache.camel.Processor;
 23  
 
 24  
 /**
 25  
  * A builder of a number of different {@link Processor} implementations
 26  
  *
 27  
  * @version $Revision: 1.1 $
 28  
  */
 29  0
 public class ProcessorBuilder {
 30  
 
 31  
     /**
 32  
      * Creates a processor which sets the body of the IN message to the value of the expression
 33  
      */
 34  
     public static Processor setBody(final Expression expression) {
 35  1
         return new Processor() {
 36  
             public void process(Exchange exchange) {
 37  1
                 Object newBody = expression.evaluate(exchange);
 38  1
                 exchange.getIn().setBody(newBody);
 39  1
             }
 40  
 
 41  
             @Override
 42  1
             public String toString() {
 43  1
                 return "setBody(" + expression + ")";
 44  
             }
 45  
         };
 46  
     }
 47  
 
 48  
     /**
 49  
      * Creates a processor which sets the body of the IN message to the value of the expression
 50  
      */
 51  
     public static Processor setOutBody(final Expression expression) {
 52  0
         return new Processor() {
 53  
             public void process(Exchange exchange) {
 54  0
                 Object newBody = expression.evaluate(exchange);
 55  0
                 exchange.getOut().setBody(newBody);
 56  0
             }
 57  
 
 58  
             @Override
 59  0
             public String toString() {
 60  0
                 return "setOutBody(" + expression + ")";
 61  
             }
 62  
         };
 63  
     }
 64  
 
 65  
     /**
 66  
      * Sets the header on the IN message
 67  
      */
 68  
     public static Processor setHeader(final String name, final Expression expression) {
 69  0
         return new Processor() {
 70  
             public void process(Exchange exchange) {
 71  0
                 Object value = expression.evaluate(exchange);
 72  0
                 exchange.getIn().setHeader(name, value);
 73  0
             }
 74  
 
 75  
             @Override
 76  0
             public String toString() {
 77  0
                 return "setHeader(" + name + ", " + expression + ")";
 78  
             }
 79  
         };
 80  
     }
 81  
 
 82  
     /**
 83  
      * Sets the header on the OUT message
 84  
      */
 85  
     public static Processor setOutHeader(final String name, final Expression expression) {
 86  0
         return new Processor() {
 87  
             public void process(Exchange exchange) {
 88  0
                 Object value = expression.evaluate(exchange);
 89  0
                 exchange.getOut().setHeader(name, value);
 90  0
             }
 91  
 
 92  
             @Override
 93  0
             public String toString() {
 94  0
                 return "setOutHeader(" + name + ", " + expression + ")";
 95  
             }
 96  
         };
 97  
     }
 98  
 
 99  
     /**
 100  
      * Sets the property on the exchange
 101  
      */
 102  
     public static Processor setProperty(final String name, final Expression expression) {
 103  0
         return new Processor() {
 104  
             public void process(Exchange exchange) {
 105  0
                 Object value = expression.evaluate(exchange);
 106  0
                 exchange.setProperty(name, value);
 107  0
             }
 108  
 
 109  
             @Override
 110  0
             public String toString() {
 111  0
                 return "setProperty(" + name + ", " + expression + ")";
 112  
             }
 113  
         };
 114  
     }
 115  
 }