Coverage Report - org.apache.camel.builder.ProcessorBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
ProcessorBuilder
19% 
N/A 
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.builder;
 18  
 
 19  
 import org.apache.camel.Exchange;
 20  
 import org.apache.camel.Expression;
 21  
 import org.apache.camel.Processor;
 22  
 
 23  
 /**
 24  
  * A builder of a number of different {@link Processor} implementations
 25  
  *
 26  
  * @version $Revision: 1.1 $
 27  
  */
 28  
 public class ProcessorBuilder {
 29  
     
 30  
     /**
 31  
      * Utility classes should not have a public constructor.
 32  
      */
 33  0
     private ProcessorBuilder() {        
 34  0
     }
 35  
 
 36  
     /**
 37  
      * Creates a processor which sets the body of the IN message to the value of the expression
 38  
      */
 39  
     public static Processor setBody(final Expression expression) {
 40  3
         return new Processor() {
 41  
             public void process(Exchange exchange) {
 42  3
                 Object newBody = expression.evaluate(exchange);
 43  3
                 exchange.getIn().setBody(newBody);
 44  3
             }
 45  
 
 46  
             @Override
 47  3
             public String toString() {
 48  3
                 return "setBody(" + expression + ")";
 49  
             }
 50  
         };
 51  
     }
 52  
 
 53  
     /**
 54  
      * Creates a processor which sets the body of the IN message to the value of the expression
 55  
      */
 56  
     public static Processor setOutBody(final Expression expression) {
 57  0
         return new Processor() {
 58  
             public void process(Exchange exchange) {
 59  0
                 Object newBody = expression.evaluate(exchange);
 60  0
                 exchange.getOut().setBody(newBody);
 61  0
             }
 62  
 
 63  
             @Override
 64  0
             public String toString() {
 65  0
                 return "setOutBody(" + expression + ")";
 66  
             }
 67  
         };
 68  
     }
 69  
 
 70  
     /**
 71  
      * Sets the header on the IN message
 72  
      */
 73  
     public static Processor setHeader(final String name, final Expression expression) {
 74  0
         return new Processor() {
 75  
             public void process(Exchange exchange) {
 76  0
                 Object value = expression.evaluate(exchange);
 77  0
                 exchange.getIn().setHeader(name, value);
 78  0
             }
 79  
 
 80  
             @Override
 81  0
             public String toString() {
 82  0
                 return "setHeader(" + name + ", " + expression + ")";
 83  
             }
 84  
         };
 85  
     }
 86  
 
 87  
     /**
 88  
      * Sets the header on the OUT message
 89  
      */
 90  
     public static Processor setOutHeader(final String name, final Expression expression) {
 91  0
         return new Processor() {
 92  
             public void process(Exchange exchange) {
 93  0
                 Object value = expression.evaluate(exchange);
 94  0
                 exchange.getOut().setHeader(name, value);
 95  0
             }
 96  
 
 97  
             @Override
 98  0
             public String toString() {
 99  0
                 return "setOutHeader(" + name + ", " + expression + ")";
 100  
             }
 101  
         };
 102  
     }
 103  
 
 104  
     /**
 105  
      * Sets the property on the exchange
 106  
      */
 107  
     public static Processor setProperty(final String name, final Expression expression) {
 108  0
         return new Processor() {
 109  
             public void process(Exchange exchange) {
 110  0
                 Object value = expression.evaluate(exchange);
 111  0
                 exchange.setProperty(name, value);
 112  0
             }
 113  
 
 114  
             @Override
 115  0
             public String toString() {
 116  0
                 return "setProperty(" + name + ", " + expression + ")";
 117  
             }
 118  
         };
 119  
     }
 120  
 }