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