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