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