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; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023 024import org.apache.camel.spi.Metadata; 025 026/** 027 * Set the expected data type of the input message. If the actual message type 028 * is different at runtime, camel look for a required {@link Transformer} and 029 * apply if exists. If validate attribute is true then camel applies 030 * {@link Validator} as well. Type name consists of two parts, 'scheme' and 031 * 'name' connected with ':'. For Java type 'name' is a fully qualified class 032 * name. For example {@code java:java.lang.String}, {@code json:ABCOrder}. It's 033 * also possible to specify only scheme part, so that it works like a wildcard. 034 * If only 'xml' is specified, all the XML message matches. It's handy to add 035 * only one transformer/validator for all the transformation from/to XML. 036 * 037 * @see {@link OutputTypeDefinition} {@link Transformer} {@link Validator} 038 */ 039@Metadata(label = "configuration") 040@XmlRootElement(name = "inputType") 041@XmlAccessorType(XmlAccessType.FIELD) 042public class InputTypeDefinition extends OptionalIdentifiedDefinition<InputTypeDefinition> { 043 @XmlAttribute 044 @Metadata(required = true) 045 private String urn; 046 @XmlAttribute 047 @Metadata(defaultValue = "false") 048 private Boolean validate = false; 049 050 public InputTypeDefinition() { 051 } 052 053 /** 054 * Get input type URN. 055 * 056 * @return input type URN 057 */ 058 public String getUrn() { 059 return urn; 060 } 061 062 /** 063 * Set input type URN. 064 * 065 * @param urn input type URN 066 */ 067 public void setUrn(String urn) { 068 this.urn = urn; 069 } 070 071 /** 072 * Set input type via Java Class. 073 * 074 * @param clazz Java Class 075 */ 076 public void setJavaClass(Class<?> clazz) { 077 this.urn = "java:" + clazz.getName(); 078 } 079 080 /** 081 * Get if validation is required for this input type. 082 * 083 * @return true if validate 084 */ 085 public boolean isValidate() { 086 return this.validate; 087 } 088 089 /** 090 * Set if validation is required for this input type. 091 * 092 * @param validate true if validate 093 */ 094 public void setValidate(boolean validate) { 095 this.validate = validate; 096 } 097 098 @Override 099 public String toString() { 100 return "inputType[" + urn + "]"; 101 } 102 103 @Override 104 public String getShortName() { 105 return "inputType"; 106 } 107 108 @Override 109 public String getLabel() { 110 return "inputType[" + urn + "]"; 111 } 112 113}