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.XmlElement; 023import javax.xml.bind.annotation.XmlElements; 024import javax.xml.bind.annotation.XmlRootElement; 025 026import org.apache.camel.Processor; 027import org.apache.camel.model.dataformat.ASN1DataFormat; 028import org.apache.camel.model.dataformat.AvroDataFormat; 029import org.apache.camel.model.dataformat.Base64DataFormat; 030import org.apache.camel.model.dataformat.BeanioDataFormat; 031import org.apache.camel.model.dataformat.BindyDataFormat; 032import org.apache.camel.model.dataformat.BoonDataFormat; 033import org.apache.camel.model.dataformat.CastorDataFormat; 034import org.apache.camel.model.dataformat.CryptoDataFormat; 035import org.apache.camel.model.dataformat.CsvDataFormat; 036import org.apache.camel.model.dataformat.CustomDataFormat; 037import org.apache.camel.model.dataformat.FhirJsonDataFormat; 038import org.apache.camel.model.dataformat.FhirXmlDataFormat; 039import org.apache.camel.model.dataformat.FlatpackDataFormat; 040import org.apache.camel.model.dataformat.GzipDataFormat; 041import org.apache.camel.model.dataformat.HL7DataFormat; 042import org.apache.camel.model.dataformat.HessianDataFormat; 043import org.apache.camel.model.dataformat.IcalDataFormat; 044import org.apache.camel.model.dataformat.JacksonXMLDataFormat; 045import org.apache.camel.model.dataformat.JaxbDataFormat; 046import org.apache.camel.model.dataformat.JibxDataFormat; 047import org.apache.camel.model.dataformat.JsonDataFormat; 048import org.apache.camel.model.dataformat.PGPDataFormat; 049import org.apache.camel.model.dataformat.ProtobufDataFormat; 050import org.apache.camel.model.dataformat.RssDataFormat; 051import org.apache.camel.model.dataformat.SerializationDataFormat; 052import org.apache.camel.model.dataformat.SoapJaxbDataFormat; 053import org.apache.camel.model.dataformat.StringDataFormat; 054import org.apache.camel.model.dataformat.SyslogDataFormat; 055import org.apache.camel.model.dataformat.TarFileDataFormat; 056import org.apache.camel.model.dataformat.ThriftDataFormat; 057import org.apache.camel.model.dataformat.TidyMarkupDataFormat; 058import org.apache.camel.model.dataformat.UniVocityCsvDataFormat; 059import org.apache.camel.model.dataformat.UniVocityFixedWidthDataFormat; 060import org.apache.camel.model.dataformat.UniVocityTsvDataFormat; 061import org.apache.camel.model.dataformat.XMLBeansDataFormat; 062import org.apache.camel.model.dataformat.XMLSecurityDataFormat; 063import org.apache.camel.model.dataformat.XStreamDataFormat; 064import org.apache.camel.model.dataformat.XmlJsonDataFormat; 065import org.apache.camel.model.dataformat.XmlRpcDataFormat; 066import org.apache.camel.model.dataformat.YAMLDataFormat; 067import org.apache.camel.model.dataformat.ZipDataFormat; 068import org.apache.camel.model.dataformat.ZipFileDataFormat; 069import org.apache.camel.processor.UnmarshalProcessor; 070import org.apache.camel.spi.DataFormat; 071import org.apache.camel.spi.Metadata; 072import org.apache.camel.spi.RouteContext; 073 074/** 075 * Converts the message data received from the wire into a format that Apache Camel processors can consume 076 * 077 * @version 078 */ 079@Metadata(label = "eip,transformation") 080@XmlRootElement(name = "unmarshal") 081@XmlAccessorType(XmlAccessType.FIELD) 082public class UnmarshalDefinition extends NoOutputDefinition<UnmarshalDefinition> { 083 084 // TODO: Camel 3.0, ref attribute should be removed as UnmarshalDataFormat is to be used instead 085 086 @XmlElements({ 087 @XmlElement(required = false, name = "asn1", type = ASN1DataFormat.class), 088 @XmlElement(required = false, name = "avro", type = AvroDataFormat.class), 089 @XmlElement(required = false, name = "base64", type = Base64DataFormat.class), 090 @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class), 091 @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class), 092 @XmlElement(required = false, name = "boon", type = BoonDataFormat.class), 093 @XmlElement(required = false, name = "castor", type = CastorDataFormat.class), 094 @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class), 095 @XmlElement(required = false, name = "csv", type = CsvDataFormat.class), 096 @XmlElement(required = false, name = "custom", type = CustomDataFormat.class), 097 @XmlElement(required = false, name = "fhirJson", type = FhirJsonDataFormat.class), 098 @XmlElement(required = false, name = "fhirXml", type = FhirXmlDataFormat.class), 099 @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class), 100 @XmlElement(required = false, name = "gzip", type = GzipDataFormat.class), 101 @XmlElement(required = false, name = "hessian", type = HessianDataFormat.class), 102 @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class), 103 @XmlElement(required = false, name = "ical", type = IcalDataFormat.class), 104 @XmlElement(required = false, name = "jacksonxml", type = JacksonXMLDataFormat.class), 105 @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class), 106 @XmlElement(required = false, name = "jibx", type = JibxDataFormat.class), 107 @XmlElement(required = false, name = "json", type = JsonDataFormat.class), 108 @XmlElement(required = false, name = "protobuf", type = ProtobufDataFormat.class), 109 @XmlElement(required = false, name = "rss", type = RssDataFormat.class), 110 @XmlElement(required = false, name = "secureXML", type = XMLSecurityDataFormat.class), 111 @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class), 112 @XmlElement(required = false, name = "soapjaxb", type = SoapJaxbDataFormat.class), 113 @XmlElement(required = false, name = "string", type = StringDataFormat.class), 114 @XmlElement(required = false, name = "syslog", type = SyslogDataFormat.class), 115 @XmlElement(required = false, name = "tarfile", type = TarFileDataFormat.class), 116 @XmlElement(required = false, name = "thrift", type = ThriftDataFormat.class), 117 @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class), 118 @XmlElement(required = false, name = "univocity-csv", type = UniVocityCsvDataFormat.class), 119 @XmlElement(required = false, name = "univocity-fixed", type = UniVocityFixedWidthDataFormat.class), 120 @XmlElement(required = false, name = "univocity-tsv", type = UniVocityTsvDataFormat.class), 121 @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class), 122 @XmlElement(required = false, name = "xmljson", type = XmlJsonDataFormat.class), 123 @XmlElement(required = false, name = "xmlrpc", type = XmlRpcDataFormat.class), 124 @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class), 125 @XmlElement(required = false, name = "pgp", type = PGPDataFormat.class), 126 @XmlElement(required = false, name = "yaml", type = YAMLDataFormat.class), 127 @XmlElement(required = false, name = "zip", type = ZipDataFormat.class), 128 @XmlElement(required = false, name = "zipFile", type = ZipFileDataFormat.class)} 129 ) 130 private DataFormatDefinition dataFormatType; 131 // cannot use @XmlElementRef as it doesn't allow optional properties 132 133 @XmlAttribute 134 @Deprecated 135 private String ref; 136 137 public UnmarshalDefinition() { 138 } 139 140 public UnmarshalDefinition(DataFormatDefinition dataFormatType) { 141 this.dataFormatType = dataFormatType; 142 } 143 144 public UnmarshalDefinition(String ref) { 145 this.ref = ref; 146 } 147 148 @Override 149 public String toString() { 150 return "Unmarshal[" + description() + "]"; 151 } 152 153 protected String description() { 154 if (dataFormatType != null) { 155 return dataFormatType.toString(); 156 } else { 157 return "ref:" + ref; 158 } 159 } 160 161 @Override 162 public String getShortName() { 163 return "unmarshal"; 164 } 165 166 @Override 167 public String getLabel() { 168 return "unmarshal[" + description() + "]"; 169 } 170 171 public String getRef() { 172 return ref; 173 } 174 175 /** 176 * To refer to a custom data format to use as unmarshaller 177 * 178 * @deprecated use custom dataformat instead 179 */ 180 @Deprecated 181 public void setRef(String ref) { 182 this.ref = ref; 183 } 184 185 public DataFormatDefinition getDataFormatType() { 186 return dataFormatType; 187 } 188 189 /** 190 * The data format to be used 191 */ 192 public void setDataFormatType(DataFormatDefinition dataFormatType) { 193 this.dataFormatType = dataFormatType; 194 } 195 196 @Override 197 public Processor createProcessor(RouteContext routeContext) { 198 DataFormat dataFormat = DataFormatDefinition.getDataFormat(routeContext, getDataFormatType(), ref); 199 return new UnmarshalProcessor(dataFormat); 200 } 201}