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