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  
17  package org.openehealth.ipf.platform.camel.ihe.core;
18  
19  
20  import org.apache.camel.Endpoint;
21  import org.apache.camel.Exchange;
22  import org.apache.camel.Processor;
23  import org.openehealth.ipf.commons.ihe.core.chain.ChainableImpl;
24  
25  import java.nio.charset.Charset;
26  
27  /**
28   * Convenience implementation of {@link Interceptor} for inheritance
29   *
30   * @since 3.1
31   */
32  public abstract class InterceptorSupport<E extends Endpoint> extends ChainableImpl implements Interceptor<E> {
33  
34      private Processor wrappedProcessor;
35      private E endpoint;
36  
37      @Override
38      public Processor getWrappedProcessor() {
39          return wrappedProcessor;
40      }
41  
42      @Override
43      public void setWrappedProcessor(Processor wrappedProcessor) {
44          this.wrappedProcessor = wrappedProcessor;
45      }
46  
47      @Override
48      public E getEndpoint() {
49          return endpoint;
50      }
51  
52      @Override
53      public void setEndpoint(E endpoint) {
54          this.endpoint = endpoint;
55      }
56  
57      /**
58       * Returns character set configured in the given Camel exchange,
59       * or, when none found, the system default character set.
60       * @param exchange
61       *      Camel exchange.
62       * @return
63       *      character set name.
64       */
65      protected static String characterSet(Exchange exchange) {
66          return exchange.getProperty(Exchange.CHARSET_NAME, Charset.defaultCharset().name(), String.class);
67      }
68  }