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.XmlAttribute; 022import javax.xml.bind.annotation.XmlType; 023 024import org.apache.camel.model.InputTypeDefinition; 025import org.apache.camel.model.OutputTypeDefinition; 026import org.apache.camel.spi.DataType; 027import org.apache.camel.spi.Metadata; 028import org.apache.camel.spi.Validator; 029 030/** 031 * <p> 032 * Represents a {@link Validator} which declaratively validates message content 033 * according to the input type declared by {@link InputTypeDefinition} and/or 034 * output type declared by {@link OutputTypeDefinition}. 035 * </p> 036 * <p> 037 * If you specify type='xml:ABC', the validator will be picked up when current 038 * message type is 'xml:ABC'. If you specify type='json', then it will be picked 039 * up for all of json validation. {@see Validator} {@see InputTypeDefinition} 040 * {@see OutputTypeDefinition} 041 */ 042@Metadata(label = "validation") 043@XmlType(name = "validator") 044@XmlAccessorType(XmlAccessType.FIELD) 045public abstract class ValidatorDefinition { 046 047 @XmlAttribute 048 private String type; 049 050 public String getType() { 051 return type; 052 } 053 054 /** 055 * Set the data type name. If you specify 'xml:XYZ', the validator will be 056 * picked up if message type is 'xml:XYZ'. If you specify just 'xml', the 057 * validator matches with all of 'xml' message type like 'xml:ABC' or 058 * 'xml:DEF'. 059 * 060 * @param type data type name 061 */ 062 public void setType(String type) { 063 this.type = type; 064 } 065 066 /** 067 * Set the data type using Java class. 068 * 069 * @param clazz Java class 070 */ 071 public void setType(Class<?> clazz) { 072 this.type = new DataType(clazz).toString(); 073 } 074}