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 java.util.Map; 020 021import javax.xml.bind.annotation.XmlAccessType; 022import javax.xml.bind.annotation.XmlAccessorType; 023import javax.xml.bind.annotation.XmlAnyAttribute; 024import javax.xml.bind.annotation.XmlAttribute; 025import javax.xml.bind.annotation.XmlTransient; 026import javax.xml.bind.annotation.XmlType; 027import javax.xml.namespace.QName; 028 029import org.apache.camel.spi.DataFormat; 030import org.apache.camel.spi.Metadata; 031 032/** 033 * Represents a Camel data format 034 */ 035@Metadata(label = "dataformat,transformation") 036@XmlType(name = "dataFormat") 037@XmlAccessorType(XmlAccessType.FIELD) 038public class DataFormatDefinition extends IdentifiedType implements OtherAttributesAware, DefinitionPropertyPlaceholderConfigurer { 039 @XmlTransient 040 private DataFormat dataFormat; 041 @XmlTransient 042 private String dataFormatName; 043 // use xs:any to support optional property placeholders 044 @XmlAnyAttribute 045 private Map<QName, Object> otherAttributes; 046 @XmlAttribute 047 private Boolean contentTypeHeader; 048 049 public DataFormatDefinition() { 050 } 051 052 public DataFormatDefinition(DataFormat dataFormat) { 053 this.dataFormat = dataFormat; 054 } 055 056 protected DataFormatDefinition(String dataFormatName) { 057 this.dataFormatName = dataFormatName; 058 } 059 060 public String getDataFormatName() { 061 return dataFormatName; 062 } 063 064 public void setDataFormatName(String dataFormatName) { 065 this.dataFormatName = dataFormatName; 066 } 067 068 public DataFormat getDataFormat() { 069 return dataFormat; 070 } 071 072 public void setDataFormat(DataFormat dataFormat) { 073 this.dataFormat = dataFormat; 074 } 075 076 @Override 077 public Map<QName, Object> getOtherAttributes() { 078 return otherAttributes; 079 } 080 081 /** 082 * Adds an optional attribute 083 */ 084 @Override 085 public void setOtherAttributes(Map<QName, Object> otherAttributes) { 086 this.otherAttributes = otherAttributes; 087 } 088 089 public Boolean getContentTypeHeader() { 090 return contentTypeHeader; 091 } 092 093 /** 094 * Whether the data format should set the <tt>Content-Type</tt> header with 095 * the type from the data format if the data format is capable of doing so. 096 * <p/> 097 * For example <tt>application/xml</tt> for data formats marshalling to XML, 098 * or <tt>application/json</tt> for data formats marshalling to JSon etc. 099 */ 100 public void setContentTypeHeader(Boolean contentTypeHeader) { 101 this.contentTypeHeader = contentTypeHeader; 102 } 103 104 public String getShortName() { 105 String name = getClass().getSimpleName(); 106 if (name.endsWith("DataFormat")) { 107 name = name.substring(0, name.indexOf("DataFormat")); 108 } 109 return name; 110 } 111 112}