View Javadoc
1   /*
2    * Copyright 2015 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.platform.camel.ihe.core;
17  
18  import org.apache.camel.*;
19  
20  import static java.util.Objects.requireNonNull;
21  
22  /**
23   * Adapter for HL7v2 interceptors which allows them
24   * to be exposed as Camel {@link Producer}s.
25   *
26   * @author Dmytro Rud
27   */
28  public class Interceptor2ProducerAdapter implements Producer, DelegateProcessor, ServicePoolAware {
29      private final Processor interceptor;
30      private final Producer originalProducer;
31  
32      public Interceptor2ProducerAdapter(Processor interceptor, Producer originalProducer) {
33          this.interceptor = requireNonNull(interceptor);
34          this.originalProducer = requireNonNull(originalProducer);
35      }
36  
37      @Override
38      public Processor getProcessor() {
39          return interceptor;
40      }
41  
42      @Override
43      public void process(Exchange exchange) throws Exception {
44          interceptor.process(exchange);
45      }
46  
47      @Override
48      public Endpoint getEndpoint() {
49          return originalProducer.getEndpoint();
50      }
51  
52      @Override
53      public Exchange createExchange() {
54          return originalProducer.getEndpoint().createExchange();
55      }
56  
57      @Override
58      public Exchange createExchange(ExchangePattern pattern) {
59          return originalProducer.getEndpoint().createExchange(pattern);
60      }
61  
62      @Override
63      @Deprecated
64      public Exchange createExchange(Exchange exchange) {
65          return originalProducer.getEndpoint().createExchange(exchange);
66      }
67  
68      @Override
69      public void start() throws Exception {
70          originalProducer.start();
71      }
72  
73      @Override
74      public void stop() throws Exception {
75          originalProducer.stop();
76      }
77  
78      @Override
79      public boolean isSingleton() {
80          return originalProducer.isSingleton();
81      }
82  }