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