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.dataformat;
018
019import java.util.HashMap;
020import java.util.List;
021import java.util.Map;
022
023import javax.xml.bind.annotation.XmlAccessType;
024import javax.xml.bind.annotation.XmlAccessorType;
025import javax.xml.bind.annotation.XmlElement;
026import javax.xml.bind.annotation.XmlElements;
027import javax.xml.bind.annotation.XmlRootElement;
028
029import org.apache.camel.model.DataFormatDefinition;
030import org.apache.camel.spi.Metadata;
031
032/**
033 * Configure data formats.
034 */
035@Metadata(label = "dataformat,transformation", title = "Data formats")
036@XmlRootElement(name = "dataFormats")
037@XmlAccessorType(XmlAccessType.FIELD)
038public class DataFormatsDefinition {
039
040    // cannot use @XmlElementRef as it doesn't allow optional properties
041    @XmlElements({@XmlElement(required = false, name = "any23", type = Any23DataFormat.class),
042            @XmlElement(required = false, name = "asn1", type = ASN1DataFormat.class),
043            @XmlElement(required = false, name = "avro", type = AvroDataFormat.class),
044            @XmlElement(required = false, name = "barcode", type = BarcodeDataFormat.class),
045            @XmlElement(required = false, name = "base64", type = Base64DataFormat.class),
046            @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class),
047            @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class),
048            @XmlElement(required = false, name = "cbor", type = CBORDataFormat.class),
049            @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class),
050            @XmlElement(required = false, name = "csv", type = CsvDataFormat.class),
051            @XmlElement(required = false, name = "custom", type = CustomDataFormat.class),
052            @XmlElement(required = false, name = "fhirJson", type = FhirJsonDataFormat.class),
053            @XmlElement(required = false, name = "fhirXml", type = FhirXmlDataFormat.class),
054            @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class),
055            @XmlElement(required = false, name = "grok", type = GrokDataFormat.class),
056            @XmlElement(required = false, name = "gzip", type = GzipDataFormat.class),
057            @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
058            @XmlElement(required = false, name = "ical", type = IcalDataFormat.class),
059            @XmlElement(required = false, name = "jacksonxml", type = JacksonXMLDataFormat.class),
060            @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class),
061            @XmlElement(required = false, name = "json", type = JsonDataFormat.class),
062            @XmlElement(required = false, name = "jsonApi", type = JsonApiDataFormat.class),
063            @XmlElement(required = false, name = "lzf", type = LZFDataFormat.class),
064            @XmlElement(required = false, name = "mimeMultipart", type = MimeMultipartDataFormat.class),
065            @XmlElement(required = false, name = "protobuf", type = ProtobufDataFormat.class),
066            @XmlElement(required = false, name = "rss", type = RssDataFormat.class),
067            @XmlElement(required = false, name = "secureXML", type = XMLSecurityDataFormat.class),
068            @XmlElement(required = false, name = "soapjaxb", type = SoapJaxbDataFormat.class),
069            @XmlElement(required = false, name = "syslog", type = SyslogDataFormat.class),
070            @XmlElement(required = false, name = "tarfile", type = TarFileDataFormat.class),
071            @XmlElement(required = false, name = "thrift", type = ThriftDataFormat.class),
072            @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class),
073            @XmlElement(required = false, name = "univocity-csv", type = UniVocityCsvDataFormat.class),
074            @XmlElement(required = false, name = "univocity-fixed", type = UniVocityFixedWidthDataFormat.class),
075            @XmlElement(required = false, name = "univocity-tsv", type = UniVocityTsvDataFormat.class),
076            @XmlElement(required = false, name = "xmlrpc", type = XmlRpcDataFormat.class),
077            @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),
078            @XmlElement(required = false, name = "pgp", type = PGPDataFormat.class),
079            @XmlElement(required = false, name = "yaml", type = YAMLDataFormat.class),
080            @XmlElement(required = false, name = "zip", type = ZipDeflaterDataFormat.class),
081            @XmlElement(required = false, name = "zipfile", type = ZipFileDataFormat.class)})
082    private List<DataFormatDefinition> dataFormats;
083
084    /**
085     * A list holding the configured data formats
086     */
087    public void setDataFormats(List<DataFormatDefinition> dataFormats) {
088        this.dataFormats = dataFormats;
089    }
090
091    public List<DataFormatDefinition> getDataFormats() {
092        return dataFormats;
093    }
094
095    /***
096     * @return A Map of the contained DataFormatType's indexed by id.
097     */
098    public Map<String, DataFormatDefinition> asMap() {
099        Map<String, DataFormatDefinition> dataFormatsAsMap = new HashMap<>();
100        for (DataFormatDefinition dataFormatType : getDataFormats()) {
101            dataFormatsAsMap.put(dataFormatType.getId(), dataFormatType);
102        }
103        return dataFormatsAsMap;
104    }
105}