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 org.apache.camel.Exchange; 19 import org.apache.camel.Expression; 20 import org.apache.camel.Processor; 21 22 /** 23 * Abstract base class for classes that adapt <i>transform support library</i> 24 * interfaces to Apache Camel's {@link Processor}. 25 * 26 * @author Martin Krasser 27 */ 28 public abstract class ProcessorAdapter extends AdapterSupport implements Processor { 29 30 @Override // make use of co-variant return types to support DSL 31 public ProcessorAdapter input(Expression inputExpression) { 32 return (ProcessorAdapter)super.input(inputExpression); 33 } 34 35 @Override // make use of co-variant return types to support DSL 36 public ProcessorAdapter params(Expression paramsExpression) { 37 return (ProcessorAdapter)super.params(paramsExpression); 38 } 39 40 @Override // make use of co-variant return types to support DSL 41 public ProcessorAdapter staticParams(Object... params) { 42 return (ProcessorAdapter)super.staticParams(params); 43 } 44 45 /** 46 * Dispatches the <code>exchange</code> to 47 * {@link #doProcess(Exchange, Object, Object...)} implementations. 48 * 49 * @see #input(Expression) 50 * @see #params(Expression) 51 * @see #staticParams(Object...) 52 */ 53 @Override 54 public void process(Exchange exchange) throws Exception { 55 Object input = adaptInput(exchange); 56 Object params = adaptParams(exchange); 57 if (params == null) { 58 doProcess(exchange, input, (Object[])null); 59 } else if (params.getClass().isArray()) { 60 doProcess(exchange, input, (Object[])params); 61 } else { 62 doProcess(exchange, input, params); 63 } 64 } 65 66 /** 67 * Processes input data and populates the output exchange. 68 * 69 * @param exchange 70 * message exchange where to write processing results. 71 * @param inputData 72 * input data. 73 * @param inputParams 74 * input parameters. 75 * @throws Exception 76 * if a processing error occurs. 77 */ 78 protected abstract void doProcess(Exchange exchange, Object inputData, 79 Object... inputParams) throws Exception; 80 81 }