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.CastorDataFormat;
031 import org.apache.camel.model.dataformat.CryptoDataFormat;
032 import org.apache.camel.model.dataformat.CsvDataFormat;
033 import org.apache.camel.model.dataformat.CustomDataFormat;
034 import org.apache.camel.model.dataformat.FlatpackDataFormat;
035 import org.apache.camel.model.dataformat.GzipDataFormat;
036 import org.apache.camel.model.dataformat.HL7DataFormat;
037 import org.apache.camel.model.dataformat.JaxbDataFormat;
038 import org.apache.camel.model.dataformat.JibxDataFormat;
039 import org.apache.camel.model.dataformat.JsonDataFormat;
040 import org.apache.camel.model.dataformat.PGPDataFormat;
041 import org.apache.camel.model.dataformat.ProtobufDataFormat;
042 import org.apache.camel.model.dataformat.RssDataFormat;
043 import org.apache.camel.model.dataformat.SerializationDataFormat;
044 import org.apache.camel.model.dataformat.SoapJaxbDataFormat;
045 import org.apache.camel.model.dataformat.StringDataFormat;
046 import org.apache.camel.model.dataformat.SyslogDataFormat;
047 import org.apache.camel.model.dataformat.TidyMarkupDataFormat;
048 import org.apache.camel.model.dataformat.XMLBeansDataFormat;
049 import org.apache.camel.model.dataformat.XMLSecurityDataFormat;
050 import org.apache.camel.model.dataformat.XStreamDataFormat;
051 import org.apache.camel.model.dataformat.ZipDataFormat;
052 import org.apache.camel.processor.UnmarshalProcessor;
053 import org.apache.camel.spi.DataFormat;
054 import org.apache.camel.spi.RouteContext;
055
056 /**
057 * Unmarshals the binary payload using the given {@link DataFormatDefinition}
058 *
059 * @version
060 */
061 @XmlRootElement(name = "unmarshal")
062 @XmlAccessorType(XmlAccessType.FIELD)
063 public class UnmarshalDefinition extends NoOutputDefinition<UnmarshalDefinition> {
064
065 // TODO: Camel 3.0, ref attribute should be removed as RefDataFormat is to be used instead
066
067 @XmlAttribute
068 @Deprecated
069 private String ref;
070 // cannot use @XmlElementRef as it doesn't allow optional properties
071 @XmlElements({
072 @XmlElement(required = false, name = "avro", type = AvroDataFormat.class),
073 @XmlElement(required = false, name = "beanio", type = BeanioDataFormat.class),
074 @XmlElement(required = false, name = "bindy", type = BindyDataFormat.class),
075 @XmlElement(required = false, name = "castor", type = CastorDataFormat.class),
076 @XmlElement(required = false, name = "crypto", type = CryptoDataFormat.class),
077 @XmlElement(required = false, name = "csv", type = CsvDataFormat.class),
078 @XmlElement(required = false, name = "custom", type = CustomDataFormat.class),
079 @XmlElement(required = false, name = "flatpack", type = FlatpackDataFormat.class),
080 @XmlElement(required = false, name = "gzip", type = GzipDataFormat.class),
081 @XmlElement(required = false, name = "hl7", type = HL7DataFormat.class),
082 @XmlElement(required = false, name = "jaxb", type = JaxbDataFormat.class),
083 @XmlElement(required = false, name = "jibx", type = JibxDataFormat.class),
084 @XmlElement(required = false, name = "json", type = JsonDataFormat.class),
085 @XmlElement(required = false, name = "protobuf", type = ProtobufDataFormat.class),
086 @XmlElement(required = false, name = "rss", type = RssDataFormat.class),
087 @XmlElement(required = false, name = "secureXML", type = XMLSecurityDataFormat.class),
088 @XmlElement(required = false, name = "serialization", type = SerializationDataFormat.class),
089 @XmlElement(required = false, name = "soapjaxb", type = SoapJaxbDataFormat.class),
090 @XmlElement(required = false, name = "string", type = StringDataFormat.class),
091 @XmlElement(required = false, name = "syslog", type = SyslogDataFormat.class),
092 @XmlElement(required = false, name = "tidyMarkup", type = TidyMarkupDataFormat.class),
093 @XmlElement(required = false, name = "xmlBeans", type = XMLBeansDataFormat.class),
094 @XmlElement(required = false, name = "xstream", type = XStreamDataFormat.class),
095 @XmlElement(required = false, name = "pgp", type = PGPDataFormat.class),
096 @XmlElement(required = false, name = "zip", type = ZipDataFormat.class)}
097 )
098 private DataFormatDefinition dataFormatType;
099
100 public UnmarshalDefinition() {
101 }
102
103 public UnmarshalDefinition(DataFormatDefinition dataFormatType) {
104 this.dataFormatType = dataFormatType;
105 }
106
107 public UnmarshalDefinition(String ref) {
108 this.ref = ref;
109 }
110
111 @Override
112 public String toString() {
113 return "Unmarshal[" + description() + "]";
114 }
115
116 protected String description() {
117 if (dataFormatType != null) {
118 return dataFormatType.toString();
119 } else {
120 return "ref:" + ref;
121 }
122 }
123
124 @Override
125 public String getShortName() {
126 return "unmarshal";
127 }
128
129 @Override
130 public String getLabel() {
131 return "unmarshal[" + description() + "]";
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 UnmarshalProcessor(dataFormat);
154 }
155 }