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.impl.RouteContext; 028 import org.apache.camel.model.dataformat.ArtixDSDataFormat; 029 import org.apache.camel.model.dataformat.CsvDataFormat; 030 import org.apache.camel.model.dataformat.DataFormatType; 031 import org.apache.camel.model.dataformat.JaxbDataFormat; 032 import org.apache.camel.model.dataformat.SerializationDataFormat; 033 import org.apache.camel.model.dataformat.StringDataFormat; 034 import org.apache.camel.model.dataformat.XMLBeansDataFormat; 035 import org.apache.camel.processor.MarshalProcessor; 036 import org.apache.camel.spi.DataFormat; 037 038 /** 039 * Marshals to a binary payload using the given {@link DataFormatType} 040 * 041 * @version $Revision: 36321 $ 042 */ 043 @XmlRootElement(name = "marshal") 044 @XmlAccessorType(XmlAccessType.FIELD) 045 public class MarshalType extends OutputType<ProcessorType> { 046 @XmlAttribute(required = false) 047 private String ref; 048 // TODO cannot use @XmlElementRef as it doesn't allow optional properties 049 // @XmlElementRef 050 @XmlElements({ 051 @XmlElement(required = false, name = "artixDS", type = ArtixDSDataFormat.class), 052 @XmlElement(required = false, name = "csv", type = CsvDataFormat.class), 053 @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class), 054 @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class), 055 @XmlElement(required = false, name = "string", type = StringDataFormat.class), 056 @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class)} 057 ) 058 private DataFormatType dataFormatType; 059 060 public MarshalType() { 061 } 062 063 public MarshalType(DataFormatType dataFormatType) { 064 this.dataFormatType = dataFormatType; 065 } 066 067 public MarshalType(String ref) { 068 this.ref = ref; 069 } 070 071 @Override 072 public String toString() { 073 if (dataFormatType != null) { 074 return "Marshal[" + dataFormatType + "]"; 075 } else { 076 return "Marshal[ref: " + ref + "]"; 077 } 078 } 079 080 public String getRef() { 081 return ref; 082 } 083 084 public void setRef(String ref) { 085 this.ref = ref; 086 } 087 088 public DataFormatType getDataFormatType() { 089 return dataFormatType; 090 } 091 092 public void setDataFormatType(DataFormatType dataFormatType) { 093 this.dataFormatType = dataFormatType; 094 } 095 096 @Override 097 public Processor createProcessor(RouteContext routeContext) { 098 DataFormat dataFormat = DataFormatType.getDataFormat(routeContext, getDataFormatType(), ref); 099 return new MarshalProcessor(dataFormat); 100 } 101 }