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.model.ExpressionNodeHelper;
026import org.apache.camel.model.language.ExpressionDefinition;
027import org.apache.camel.spi.Metadata;
028import org.apache.camel.spi.Validator;
029
030/**
031 * Represents a predicate {@link Validator} which leverages expression or
032 * predicates to perform content validation. A
033 * {@link org.apache.camel.impl.validator.ProcessorValidator} will be created
034 * internally with a
035 * {@link org.apache.camel.processor.validation.PredicateValidatingProcessor}
036 * which validates the message according to specified expression/predicates.
037 * {@see ValidatorDefinition} {@see Validator}
038 */
039@Metadata(label = "validation")
040@XmlType(name = "predicateValidator")
041@XmlAccessorType(XmlAccessType.FIELD)
042public class PredicateValidatorDefinition extends ValidatorDefinition {
043
044    @XmlElementRef
045    private ExpressionDefinition expression;
046
047    public ExpressionDefinition getExpression() {
048        return expression;
049    }
050
051    public void setExpression(ExpressionDefinition expression) {
052        // favour using the helper to set the expression as it can unwrap some
053        // unwanted builders when using Java DSL
054        this.expression = ExpressionNodeHelper.toExpressionDefinition((Expression) expression);
055    }
056
057}