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 String validate = "false";
049
050    public InputTypeDefinition() {
051    }
052
053    public InputTypeDefinition urn(String urn) {
054        setUrn(urn);
055        return this;
056    }
057
058    public InputTypeDefinition javaClass(Class<?> clazz) {
059        setJavaClass(clazz);
060        return this;
061    }
062
063    public InputTypeDefinition validate(boolean validate) {
064        setValidate(Boolean.toString(validate));
065        return this;
066    }
067
068    /**
069     * Get input type URN.
070     * 
071     * @return input type URN
072     */
073    public String getUrn() {
074        return urn;
075    }
076
077    /**
078     * Set input type URN.
079     * 
080     * @param urn input type URN
081     */
082    public void setUrn(String urn) {
083        this.urn = urn;
084    }
085
086    /**
087     * Set input type via Java Class.
088     * 
089     * @param clazz Java Class
090     */
091    public void setJavaClass(Class<?> clazz) {
092        this.urn = "java:" + clazz.getName();
093    }
094
095    /**
096     * Get if validation is required for this input type.
097     * 
098     * @return true if validate
099     */
100    public String getValidate() {
101        return this.validate;
102    }
103
104    /**
105     * Set if validation is required for this input type.
106     * 
107     * @param validate true if validate
108     */
109    public void setValidate(String validate) {
110        this.validate = validate;
111    }
112
113    @Override
114    public String toString() {
115        return "inputType[" + urn + "]";
116    }
117
118    @Override
119    public String getShortName() {
120        return "inputType";
121    }
122
123    @Override
124    public String getLabel() {
125        return "inputType[" + urn + "]";
126    }
127
128}