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     */
017    package org.apache.camel.model.dataformat;
018    
019    import java.util.ArrayList;
020    import java.util.HashMap;
021    import java.util.List;
022    import java.util.Map;
023    
024    import javax.xml.bind.annotation.XmlAccessType;
025    import javax.xml.bind.annotation.XmlAccessorType;
026    import javax.xml.bind.annotation.XmlElement;
027    import javax.xml.bind.annotation.XmlElementRef;
028    import javax.xml.bind.annotation.XmlElements;
029    import javax.xml.bind.annotation.XmlRootElement;
030    import javax.xml.bind.annotation.XmlType;
031    
032    /**
033     * Represents the XML type for a collection of DataFormats.
034     */
035    @XmlRootElement(name = "dataFormats")
036    @XmlAccessorType(XmlAccessType.FIELD)
037    public class DataFormatsType {
038    
039        // TODO cannot use @XmlElementRef as it doesn't allow optional properties
040        // @XmlElementRef
041        @XmlElements({
042            @XmlElement(required = false, name = "artixDS", type = ArtixDSDataFormat.class),
043            @XmlElement(required = false, name = "csv", type = CsvDataFormat.class),
044            @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class),
045            @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
046            @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class),
047            @XmlElement(required = false, name = "json", type = JsonDataFormat.class),
048            @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
049            @XmlElement(required = false, name = "string", type = StringDataFormat.class),
050            @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
051            @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),
052            @XmlElement(required = false, name = "zip", type = ZipDataFormat.class)}
053            )
054        private List<DataFormatType> dataFormats;
055    
056    
057        public void setDataFormats(List<DataFormatType> dataFormats) {
058            this.dataFormats = dataFormats;
059        }
060    
061        public List<DataFormatType> getDataFormats() {
062            return dataFormats;
063        }
064    
065        /***
066         * @return A Map of the contained DataFormatType's indexed by id.
067         */
068        public Map<String, DataFormatType> asMap() {
069            Map<String, DataFormatType> dataFormatsAsMap = new HashMap<String, DataFormatType>();
070            for (DataFormatType dataFormatType : getDataFormats()) {
071                dataFormatsAsMap.put(dataFormatType.getId(), dataFormatType);
072            }
073            return dataFormatsAsMap;
074        }
075    }