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 output 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 XML-Java transformation.
034 * 
035 * @see {@link InputTypeDefinition} {@link Transformer} {@link Validator}
036 */
037@Metadata(label = "configuration")
038@XmlRootElement(name = "outputType")
039@XmlAccessorType(XmlAccessType.FIELD)
040public class OutputTypeDefinition extends OptionalIdentifiedDefinition<OutputTypeDefinition> {
041    @XmlAttribute @Metadata(required = "true")
042    private String urn;
043    @XmlAttribute  @Metadata(defaultValue = "false")
044    private Boolean validate = false;
045
046    public OutputTypeDefinition() {
047    }
048
049    /**
050     * Get output type URN.
051     * @return output type URN
052     */
053    public String getUrn() {
054        return urn;
055    }
056
057    /**
058     * Set output type URN.
059     * @param urn output type URN
060     * @return this OutputTypeDefinition instance
061     */
062    public void setUrn(String urn) {
063        this.urn = urn;
064    }
065
066    /**
067     * Set output type via Java Class.
068     * @param clazz Java Class
069     */
070    public void setJavaClass(Class<?> clazz) {
071        this.urn = "java:" + clazz.getName();
072    }
073
074    /**
075     * Get if validation is required for this output type.
076     * @return true if validate
077     */
078    public boolean isValidate() {
079        return this.validate;
080    }
081
082    /**
083     * Set if validation is required for this output type.
084     * @param validate true if validate
085     */
086    public void setValidate(boolean validate) {
087        this.validate = validate;
088    }
089
090    @Override
091    public String toString() {
092        return "outputType[" + urn + "]";
093    }
094
095    @Override
096    public String getLabel() {
097        return "outputType[" + urn + "]";
098    }
099
100}