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