Coverage Report - org.apache.camel.impl.ProcessorEndpoint
 
Classes in this File Line Coverage Branch Coverage Complexity
ProcessorEndpoint
69% 
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.impl;
 18  
 
 19  
 import org.apache.camel.CamelContext;
 20  
 import org.apache.camel.Component;
 21  
 import org.apache.camel.Consumer;
 22  
 import org.apache.camel.Exchange;
 23  
 import org.apache.camel.Processor;
 24  
 import org.apache.camel.Producer;
 25  
 
 26  
 /**
 27  
  * An endpoint which allows exchanges to be sent into it which just invokes a
 28  
  * given {@link Processor}. This component does not support the use of
 29  
  * consumers.
 30  
  * 
 31  
  * @version $Revision: 1.1 $
 32  
  */
 33  
 public class ProcessorEndpoint extends DefaultEndpoint<Exchange> {
 34  
     private final Processor processor;
 35  
 
 36  
     public ProcessorEndpoint(String endpointUri, CamelContext context, Processor processor) {
 37  0
         super(endpointUri, context);
 38  0
         this.processor = processor;
 39  0
     }
 40  
 
 41  
     public ProcessorEndpoint(String endpointUri, Component component, Processor processor) {
 42  15
         super(endpointUri, component);
 43  15
         this.processor = processor;
 44  15
     }
 45  
 
 46  
     public Exchange createExchange() {
 47  9
         return new DefaultExchange(getContext());
 48  
     }
 49  
 
 50  
     public Producer<Exchange> createProducer() throws Exception {
 51  15
         return new DefaultProducer<Exchange>(this) {
 52  15
             public void process(Exchange exchange) throws Exception {
 53  27
                 onExchange(exchange);
 54  27
             }
 55  
         };
 56  
     }
 57  
 
 58  
     public Consumer<Exchange> createConsumer(Processor processor) throws Exception {
 59  0
         throw new UnsupportedOperationException("You cannot consume from this endpoint!");
 60  
     }
 61  
 
 62  
     public Processor getProcessor() {
 63  0
         return processor;
 64  
     }
 65  
 
 66  
     protected void onExchange(Exchange exchange) throws Exception {
 67  27
         processor.process(exchange);
 68  27
     }
 69  
 
 70  
     public boolean isSingleton() {
 71  15
         return true;
 72  
     }
 73  
 }