View Javadoc
1   /*
2    * Copyright 2008 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.core.adapter;
17  
18  import static org.openehealth.ipf.platform.camel.core.util.Exchanges.prepareResult;
19  
20  import org.apache.camel.Exchange;
21  import org.openehealth.ipf.commons.core.modules.api.Transmogrifier;
22  
23  /**
24   * Adapts a {@link Transmogrifier}. 
25   * 
26   * @author Martin Krasser
27   */
28  public class TransmogrifierAdapter extends ProcessorAdapter {
29  
30      private final Transmogrifier transmogrifier;
31  
32      /**
33       * Creates a new {@link TransmogrifierAdapter} and sets the delegate
34       * {@link Transmogrifier}.
35       * 
36       * @param transmogrifier
37       *            a transmogrifier.
38       */
39      public TransmogrifierAdapter(Transmogrifier transmogrifier) {
40          this.transmogrifier = transmogrifier;
41      }
42      
43      /**
44       * Delegates processing of input data and input parameters to a
45       * {@link Transmogrifier} object. The transmogrification result is written
46       * to body of the message returned by
47       * {@link org.openehealth.ipf.platform.camel.core.util.Exchanges#prepareResult(Exchange)}.
48       * 
49       * @param exchange
50       *            message exchange where to write processing results.
51       * @param inputData
52       *            input data.
53       * @param inputParams
54       *            input parameters.
55       * @throws Exception
56       *             if a processing error occurs.
57       */
58      @Override
59      protected void doProcess(Exchange exchange, Object inputData, 
60              Object... inputParams) throws Exception {
61  
62          prepareResult(exchange).setBody(transmogrifier.zap(inputData, inputParams));
63      }
64  
65  }