001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.model.validator; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlElementRef; 022import javax.xml.bind.annotation.XmlType; 023 024import org.apache.camel.Expression; 025import org.apache.camel.Predicate; 026import org.apache.camel.model.ExpressionNodeHelper; 027import org.apache.camel.model.language.ExpressionDefinition; 028import org.apache.camel.spi.Metadata; 029import org.apache.camel.spi.Validator; 030 031/** 032 * Represents a predicate {@link Validator} which leverages expression or 033 * predicates to perform content validation. A 034 * {@link org.apache.camel.impl.validator.ProcessorValidator} will be created 035 * internally with a 036 * {@link org.apache.camel.processor.validation.PredicateValidatingProcessor} 037 * which validates the message according to specified expression/predicates. 038 * {@see ValidatorDefinition} {@see Validator} 039 */ 040@Metadata(label = "validation") 041@XmlType(name = "predicateValidator") 042@XmlAccessorType(XmlAccessType.FIELD) 043public class PredicateValidatorDefinition extends ValidatorDefinition { 044 045 @XmlElementRef 046 private ExpressionDefinition expression; 047 048 public ExpressionDefinition getExpression() { 049 return expression; 050 } 051 052 public void setExpression(ExpressionDefinition expression) { 053 // favour using the helper to set the expression as it can unwrap some 054 // unwanted builders when using Java DSL 055 if (expression instanceof Expression) { 056 this.expression = ExpressionNodeHelper.toExpressionDefinition((Expression)expression); 057 } else if (expression instanceof Predicate) { 058 this.expression = ExpressionNodeHelper.toExpressionDefinition((Predicate)expression); 059 } else { 060 this.expression = expression; 061 } 062 } 063 064}