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.process; 17 18 import org.apache.camel.Exchange; 19 import org.apache.camel.Processor; 20 import org.apache.camel.Producer; 21 22 /** 23 * Implements a validation process. The incoming {@link Exchange} is validated 24 * against a <code>validator</code> (a {#link Processor}) set at construction 25 * time. If validation succeeds the validation result is returned to the 26 * initiator and the in-message of the incoming {@link Exchange} is forwarded to 27 * the next processor using an in-only {@link Exchange}. If validation fails 28 * (validator returned fault or exception) then the validation fault or 29 * exception is returned to the initiator and processing stops. 30 * 31 * @author Martin Krasser 32 */ 33 public class Validation extends Responder { 34 35 /** 36 * Creates a new {@link Validation} process. 37 * 38 * @param validator 39 * processor that creates a validation response. 40 */ 41 public Validation(Processor validator) { 42 super(validator); 43 } 44 45 /** 46 * Creates a new {@link Validation} process. 47 * 48 * @param validator 49 * producer that creates a validation response. 50 */ 51 public Validation(Producer validator) { 52 super(validator); 53 } 54 55 /** 56 * Returns <code>false</code> if the <code>response</code> exchange 57 * failed indicating that processing shall stop. 58 * 59 * @param original 60 * original message exchange. 61 * @param response 62 * response message exchange. 63 * @return <code>false</code> if <code>response</code> failed, 64 * <code>true</code> otherwise. 65 */ 66 @Override 67 protected boolean process(Exchange original, Exchange response) { 68 return !response.isFailed(); 69 } 70 71 }