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.XmlTransient;
023import javax.xml.bind.annotation.XmlType;
024
025import org.apache.camel.spi.DataFormat;
026import org.apache.camel.spi.Metadata;
027
028/**
029 * Represents a Camel data format
030 */
031@Metadata(label = "dataformat,transformation")
032@XmlType(name = "dataFormat")
033@XmlAccessorType(XmlAccessType.FIELD)
034@SuppressWarnings("rawtypes")
035public class DataFormatDefinition extends IdentifiedType {
036    @XmlTransient
037    private DataFormat dataFormat;
038    @XmlTransient
039    private String dataFormatName;
040    @XmlAttribute
041    @Metadata(javaType = "java.lang.Boolean")
042    private String contentTypeHeader;
043
044    public DataFormatDefinition() {
045    }
046
047    public DataFormatDefinition(DataFormat dataFormat) {
048        this.dataFormat = dataFormat;
049    }
050
051    protected DataFormatDefinition(String dataFormatName) {
052        this.dataFormatName = dataFormatName;
053    }
054
055    public String getDataFormatName() {
056        return dataFormatName;
057    }
058
059    public void setDataFormatName(String dataFormatName) {
060        this.dataFormatName = dataFormatName;
061    }
062
063    public DataFormat getDataFormat() {
064        return dataFormat;
065    }
066
067    public void setDataFormat(DataFormat dataFormat) {
068        this.dataFormat = dataFormat;
069    }
070
071    public String getContentTypeHeader() {
072        return contentTypeHeader;
073    }
074
075    /**
076     * Whether the data format should set the <tt>Content-Type</tt> header with
077     * the type from the data format if the data format is capable of doing so.
078     * <p/>
079     * For example <tt>application/xml</tt> for data formats marshalling to XML,
080     * or <tt>application/json</tt> for data formats marshalling to JSON etc.
081     */
082    public void setContentTypeHeader(String contentTypeHeader) {
083        this.contentTypeHeader = contentTypeHeader;
084    }
085
086    public String getShortName() {
087        String name = getClass().getSimpleName();
088        if (name.endsWith("DataFormat")) {
089            name = name.substring(0, name.indexOf("DataFormat"));
090        }
091        return name;
092    }
093
094}