Coverage Report - org.apache.camel.processor.DelegateProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
DelegateProcessor
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 org.apache.camel.Exchange;
 20  
 import org.apache.camel.Processor;
 21  
 import org.apache.camel.impl.ServiceSupport;
 22  
 import org.apache.camel.spi.Policy;
 23  
 import org.apache.camel.util.ServiceHelper;
 24  
 
 25  
 /**
 26  
  * A Delegate pattern which delegates processing to a nested processor which can
 27  
  * be useful for implementation inheritance when writing an {@link Policy}
 28  
  * 
 29  
  * @version $Revision: 519941 $
 30  
  */
 31  
 public class DelegateProcessor extends ServiceSupport implements Processor {
 32  
     private Processor processor;
 33  
 
 34  36
     public DelegateProcessor() {
 35  36
     }
 36  
 
 37  105
     public DelegateProcessor(Processor processor) {
 38  105
         this.processor = processor;
 39  105
     }
 40  
 
 41  
     public void process(Exchange exchange) throws Exception {
 42  36
         processNext(exchange);
 43  36
     }
 44  
 
 45  
     protected void processNext(Exchange exchange) throws Exception {
 46  48
         if (processor != null) {
 47  48
             processor.process(exchange);
 48  
         }
 49  48
     }
 50  
 
 51  
     @Override
 52  
     public String toString() {
 53  45
         return "Delegate(" + processor + ")";
 54  
     }
 55  
 
 56  
     public Processor getProcessor() {
 57  165
         return processor;
 58  
     }
 59  
 
 60  
     public void setProcessor(Processor processor) {
 61  36
         this.processor = processor;
 62  36
     }
 63  
 
 64  
     protected void doStart() throws Exception {
 65  114
         ServiceHelper.startServices(processor);
 66  114
     }
 67  
 
 68  
     protected void doStop() throws Exception {
 69  102
         ServiceHelper.stopServices(processor);
 70  102
     }
 71  
 
 72  
     /**
 73  
      * Proceed with the underlying delegated processor
 74  
      */
 75  
     public void proceed(Exchange exchange) throws Exception {
 76  12
         processNext(exchange);
 77  12
     }
 78  
 }