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
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 XML-Java transformation.
036 * 
037 * @see {@link InputTypeDefinition} {@link Transformer} {@link Validator}
038 */
039@Metadata(label = "configuration")
040@XmlRootElement(name = "outputType")
041@XmlAccessorType(XmlAccessType.FIELD)
042public class OutputTypeDefinition extends OptionalIdentifiedDefinition<OutputTypeDefinition> {
043    @XmlAttribute
044    @Metadata(required = true)
045    private String urn;
046    @XmlAttribute
047    @Metadata(javaType = "java.lang.Boolean", defaultValue = "false")
048    private String validate = "false";
049
050    public OutputTypeDefinition() {
051    }
052
053    public OutputTypeDefinition urn(String urn) {
054        setUrn(urn);
055        return this;
056    }
057
058    public OutputTypeDefinition javaClass(Class<?> clazz) {
059        setJavaClass(clazz);
060        return this;
061    }
062
063    public OutputTypeDefinition validate(boolean validate) {
064        setValidate(Boolean.toString(validate));
065        return this;
066    }
067
068    /**
069     * Get output type URN.
070     * 
071     * @return output type URN
072     */
073    public String getUrn() {
074        return urn;
075    }
076
077    /**
078     * Set output type URN.
079     * 
080     * @param urn output type URN
081     * @return this OutputTypeDefinition instance
082     */
083    public void setUrn(String urn) {
084        this.urn = urn;
085    }
086
087    /**
088     * Set output type via Java Class.
089     * 
090     * @param clazz Java Class
091     */
092    public void setJavaClass(Class<?> clazz) {
093        this.urn = "java:" + clazz.getName();
094    }
095
096    /**
097     * Get if validation is required for this output type.
098     * 
099     * @return true if validate
100     */
101    public String getValidate() {
102        return this.validate;
103    }
104
105    /**
106     * Set if validation is required for this output type.
107     * 
108     * @param validate true if validate
109     */
110    public void setValidate(String validate) {
111        this.validate = validate;
112    }
113
114    @Override
115    public String toString() {
116        return "outputType[" + urn + "]";
117    }
118
119    @Override
120    public String getShortName() {
121        return "outputType";
122    }
123
124    @Override
125    public String getLabel() {
126        return "outputType[" + urn + "]";
127    }
128
129}