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.transformer;
018
019import javax.xml.bind.annotation.XmlAccessType;
020import javax.xml.bind.annotation.XmlAccessorType;
021import javax.xml.bind.annotation.XmlAttribute;
022import javax.xml.bind.annotation.XmlElement;
023import javax.xml.bind.annotation.XmlElements;
024import javax.xml.bind.annotation.XmlType;
025
026import org.apache.camel.CamelContext;
027import org.apache.camel.impl.transformer.DataFormatTransformer;
028import org.apache.camel.model.DataFormatDefinition;
029import org.apache.camel.model.dataformat.ASN1DataFormat;
030import org.apache.camel.model.dataformat.AvroDataFormat;
031import org.apache.camel.model.dataformat.BarcodeDataFormat;
032import org.apache.camel.model.dataformat.Base64DataFormat;
033import org.apache.camel.model.dataformat.BeanioDataFormat;
034import org.apache.camel.model.dataformat.BindyDataFormat;
035import org.apache.camel.model.dataformat.BoonDataFormat;
036import org.apache.camel.model.dataformat.CastorDataFormat;
037import org.apache.camel.model.dataformat.CryptoDataFormat;
038import org.apache.camel.model.dataformat.CsvDataFormat;
039import org.apache.camel.model.dataformat.CustomDataFormat;
040import org.apache.camel.model.dataformat.FhirJsonDataFormat;
041import org.apache.camel.model.dataformat.FhirXmlDataFormat;
042import org.apache.camel.model.dataformat.FlatpackDataFormat;
043import org.apache.camel.model.dataformat.GzipDataFormat;
044import org.apache.camel.model.dataformat.HL7DataFormat;
045import org.apache.camel.model.dataformat.HessianDataFormat;
046import org.apache.camel.model.dataformat.IcalDataFormat;
047import org.apache.camel.model.dataformat.JacksonXMLDataFormat;
048import org.apache.camel.model.dataformat.JaxbDataFormat;
049import org.apache.camel.model.dataformat.JibxDataFormat;
050import org.apache.camel.model.dataformat.JsonDataFormat;
051import org.apache.camel.model.dataformat.LZFDataFormat;
052import org.apache.camel.model.dataformat.MimeMultipartDataFormat;
053import org.apache.camel.model.dataformat.PGPDataFormat;
054import org.apache.camel.model.dataformat.ProtobufDataFormat;
055import org.apache.camel.model.dataformat.RssDataFormat;
056import org.apache.camel.model.dataformat.SerializationDataFormat;
057import org.apache.camel.model.dataformat.SoapJaxbDataFormat;
058import org.apache.camel.model.dataformat.StringDataFormat;
059import org.apache.camel.model.dataformat.SyslogDataFormat;
060import org.apache.camel.model.dataformat.TarFileDataFormat;
061import org.apache.camel.model.dataformat.ThriftDataFormat;
062import org.apache.camel.model.dataformat.TidyMarkupDataFormat;
063import org.apache.camel.model.dataformat.UniVocityCsvDataFormat;
064import org.apache.camel.model.dataformat.UniVocityFixedWidthDataFormat;
065import org.apache.camel.model.dataformat.UniVocityTsvDataFormat;
066import org.apache.camel.model.dataformat.XMLBeansDataFormat;
067import org.apache.camel.model.dataformat.XMLSecurityDataFormat;
068import org.apache.camel.model.dataformat.XStreamDataFormat;
069import org.apache.camel.model.dataformat.XmlJsonDataFormat;
070import org.apache.camel.model.dataformat.XmlRpcDataFormat;
071import org.apache.camel.model.dataformat.YAMLDataFormat;
072import org.apache.camel.model.dataformat.ZipDataFormat;
073import org.apache.camel.model.dataformat.ZipFileDataFormat;
074import org.apache.camel.spi.DataFormat;
075import org.apache.camel.spi.Metadata;
076import org.apache.camel.spi.Transformer;
077
078/**
079 * Represents a {@link DataFormatTransformer} which leverages {@link DataFormat} to perform
080 * transformation. One of the DataFormat 'ref' or DataFormat 'type' needs to be specified.
081 * 
082 * {@see TransformerDefinition}
083 * {@see DataFormatTransformer}
084 */
085@Metadata(label = "transformation")
086@XmlType(name = "dataFormatTransformer")
087@XmlAccessorType(XmlAccessType.FIELD)
088public class DataFormatTransformerDefinition extends TransformerDefinition {
089
090    @XmlElements({
091        @XmlElement(required = false, name = "asn1", type = ASN1DataFormat.class),
092        @XmlElement(required = false, name = "avro", type = AvroDataFormat.class),
093        @XmlElement(required = false, name = "barcode", type = BarcodeDataFormat.class),
094        @XmlElement(required = false, name = "base64", type = Base64DataFormat.class),
095        @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class),
096        @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class),
097        @XmlElement(required = false, name = "boon", type = BoonDataFormat.class),
098        @XmlElement(required = false, name = "castor", type = CastorDataFormat.class),
099        @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class),
100        @XmlElement(required = false, name = "csv", type = CsvDataFormat.class),
101        // TODO: Camel 3.0 - Should be named customDataFormat to avoid naming clash with custom loadbalancer
102        @XmlElement(required = false, name = "custom", type = CustomDataFormat.class),
103        @XmlElement(required = false, name = "fhirJson", type = FhirJsonDataFormat.class),
104        @XmlElement(required = false, name = "fhirXml", type = FhirXmlDataFormat.class),
105        @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class),
106        @XmlElement(required = false, name = "gzip", type = GzipDataFormat.class),
107        @XmlElement(required = false, name = "hessian", type = HessianDataFormat.class),
108        @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
109        @XmlElement(required = false, name = "ical", type = IcalDataFormat.class),
110        @XmlElement(required = false, name = "jacksonxml", type = JacksonXMLDataFormat.class),
111        @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class),
112        @XmlElement(required = false, name = "jibx", type = JibxDataFormat.class),
113        @XmlElement(required = false, name = "json", type = JsonDataFormat.class),
114        @XmlElement(required = false, name = "lzf", type = LZFDataFormat.class),
115        @XmlElement(required = false, name = "mimeMultipart", type = MimeMultipartDataFormat.class),
116        @XmlElement(required = false, name = "protobuf", type = ProtobufDataFormat.class),
117        @XmlElement(required = false, name = "rss", type = RssDataFormat.class),
118        @XmlElement(required = false, name = "secureXML", type = XMLSecurityDataFormat.class),
119        @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
120        @XmlElement(required = false, name = "soapjaxb", type = SoapJaxbDataFormat.class),
121        @XmlElement(required = false, name = "string", type = StringDataFormat.class),
122        @XmlElement(required = false, name = "syslog", type = SyslogDataFormat.class),
123        @XmlElement(required = false, name = "tarfile", type = TarFileDataFormat.class),
124        @XmlElement(required = false, name = "thrift", type = ThriftDataFormat.class),
125        @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class),
126        @XmlElement(required = false, name = "univocity-csv", type = UniVocityCsvDataFormat.class),
127        @XmlElement(required = false, name = "univocity-fixed", type = UniVocityFixedWidthDataFormat.class),
128        @XmlElement(required = false, name = "univocity-tsv", type = UniVocityTsvDataFormat.class),
129        @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
130        @XmlElement(required = false, name = "xmljson", type = XmlJsonDataFormat.class),
131        @XmlElement(required = false, name = "xmlrpc", type = XmlRpcDataFormat.class),
132        @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),
133        @XmlElement(required = false, name = "pgp", type = PGPDataFormat.class),
134        @XmlElement(required = false, name = "yaml", type = YAMLDataFormat.class),
135        @XmlElement(required = false, name = "zip", type = ZipDataFormat.class),
136        @XmlElement(required = false, name = "zipFile", type = ZipFileDataFormat.class)}
137        )
138    private DataFormatDefinition dataFormatType;
139
140    @XmlAttribute
141    private String ref;
142
143    @Override
144    protected Transformer doCreateTransformer(CamelContext context) {
145        return new DataFormatTransformer(context)
146                .setDataFormatType(dataFormatType)
147                .setDataFormatRef(ref)
148                .setModel(getScheme())
149                .setFrom(getFromType())
150                .setTo(getToType());
151    }
152
153    public String getRef() {
154        return ref;
155    }
156
157    /**
158     * Set the reference of the DataFormat.
159     *
160     * @param ref reference of the DataFormat
161     */
162    public void setRef(String ref) {
163        this.ref = ref;
164    }
165
166    public DataFormatDefinition getDataFormatType() {
167        return dataFormatType;
168    }
169
170    /**
171     * The data format to be used
172     */
173    public void setDataFormatType(DataFormatDefinition dataFormatType) {
174        this.dataFormatType = dataFormatType;
175    }
176
177}
178