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; 018 019 import javax.xml.bind.annotation.XmlAccessType; 020 import javax.xml.bind.annotation.XmlAccessorType; 021 import javax.xml.bind.annotation.XmlAttribute; 022 import javax.xml.bind.annotation.XmlElement; 023 import javax.xml.bind.annotation.XmlElements; 024 import javax.xml.bind.annotation.XmlRootElement; 025 026 import org.apache.camel.Processor; 027 import org.apache.camel.model.dataformat.AvroDataFormat; 028 import org.apache.camel.model.dataformat.BeanioDataFormat; 029 import org.apache.camel.model.dataformat.BindyDataFormat; 030 import org.apache.camel.model.dataformat.C24IODataFormat; 031 import org.apache.camel.model.dataformat.CastorDataFormat; 032 import org.apache.camel.model.dataformat.CryptoDataFormat; 033 import org.apache.camel.model.dataformat.CsvDataFormat; 034 import org.apache.camel.model.dataformat.CustomDataFormat; 035 import org.apache.camel.model.dataformat.FlatpackDataFormat; 036 import org.apache.camel.model.dataformat.GzipDataFormat; 037 import org.apache.camel.model.dataformat.HL7DataFormat; 038 import org.apache.camel.model.dataformat.JaxbDataFormat; 039 import org.apache.camel.model.dataformat.JibxDataFormat; 040 import org.apache.camel.model.dataformat.JsonDataFormat; 041 import org.apache.camel.model.dataformat.PGPDataFormat; 042 import org.apache.camel.model.dataformat.ProtobufDataFormat; 043 import org.apache.camel.model.dataformat.RssDataFormat; 044 import org.apache.camel.model.dataformat.SerializationDataFormat; 045 import org.apache.camel.model.dataformat.SoapJaxbDataFormat; 046 import org.apache.camel.model.dataformat.StringDataFormat; 047 import org.apache.camel.model.dataformat.SyslogDataFormat; 048 import org.apache.camel.model.dataformat.TidyMarkupDataFormat; 049 import org.apache.camel.model.dataformat.XMLBeansDataFormat; 050 import org.apache.camel.model.dataformat.XMLSecurityDataFormat; 051 import org.apache.camel.model.dataformat.XStreamDataFormat; 052 import org.apache.camel.model.dataformat.XmlJsonDataFormat; 053 import org.apache.camel.model.dataformat.ZipDataFormat; 054 import org.apache.camel.processor.MarshalProcessor; 055 import org.apache.camel.spi.DataFormat; 056 import org.apache.camel.spi.RouteContext; 057 058 /** 059 * Marshals to a binary payload using the given {@link DataFormatDefinition} 060 * 061 * @version 062 */ 063 @XmlRootElement(name = "marshal") 064 @XmlAccessorType(XmlAccessType.FIELD) 065 public class MarshalDefinition extends NoOutputDefinition<MarshalDefinition> { 066 067 // TODO: Camel 3.0, ref attribute should be removed as RefDataFormat is to be used instead 068 069 @XmlAttribute 070 @Deprecated 071 private String ref; 072 // cannot use @XmlElementRef as it doesn't allow optional properties 073 @XmlElements({ 074 @XmlElement(required = false, name = "avro", type = AvroDataFormat.class), 075 @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class), 076 @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class), 077 @XmlElement(required = false, name = "c24io", type = C24IODataFormat.class), 078 @XmlElement(required = false, name = "castor", type = CastorDataFormat.class), 079 @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class), 080 @XmlElement(required = false, name = "csv", type = CsvDataFormat.class), 081 @XmlElement(required = false, name = "custom", type = CustomDataFormat.class), 082 @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class), 083 @XmlElement(required = false, name = "gzip", type = GzipDataFormat.class), 084 @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class), 085 @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class), 086 @XmlElement(required = false, name = "jibx", type = JibxDataFormat.class), 087 @XmlElement(required = false, name = "json", type = JsonDataFormat.class), 088 @XmlElement(required = false, name = "protobuf", type = ProtobufDataFormat.class), 089 @XmlElement(required = false, name = "rss", type = RssDataFormat.class), 090 @XmlElement(required = false, name = "secureXML", type = XMLSecurityDataFormat.class), 091 @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class), 092 @XmlElement(required = false, name = "soapjaxb", type = SoapJaxbDataFormat.class), 093 @XmlElement(required = false, name = "string", type = StringDataFormat.class), 094 @XmlElement(required = false, name = "syslog", type = SyslogDataFormat.class), 095 @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class), 096 @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class), 097 @XmlElement(required = false, name = "xmljson", type = XmlJsonDataFormat.class), 098 @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class), 099 @XmlElement(required = false, name = "pgp", type = PGPDataFormat.class), 100 @XmlElement(required = false, name = "zip", type = ZipDataFormat.class)} 101 ) 102 private DataFormatDefinition dataFormatType; 103 104 public MarshalDefinition() { 105 } 106 107 public MarshalDefinition(DataFormatDefinition dataFormatType) { 108 this.dataFormatType = dataFormatType; 109 } 110 111 public MarshalDefinition(String ref) { 112 this.ref = ref; 113 } 114 115 @Override 116 public String toString() { 117 return "Marshal[" + description() + "]"; 118 } 119 120 protected String description() { 121 return dataFormatType != null ? dataFormatType.toString() : "ref:" + ref; 122 } 123 124 @Override 125 public String getLabel() { 126 return "marshal[" + description() + "]"; 127 } 128 129 @Override 130 public String getShortName() { 131 return "marshal"; 132 } 133 134 public String getRef() { 135 return ref; 136 } 137 138 public void setRef(String ref) { 139 this.ref = ref; 140 } 141 142 public DataFormatDefinition getDataFormatType() { 143 return dataFormatType; 144 } 145 146 public void setDataFormatType(DataFormatDefinition dataFormatType) { 147 this.dataFormatType = dataFormatType; 148 } 149 150 @Override 151 public Processor createProcessor(RouteContext routeContext) { 152 DataFormat dataFormat = DataFormatDefinition.getDataFormat(routeContext, getDataFormatType(), ref); 153 return new MarshalProcessor(dataFormat); 154 } 155 }