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 */ 017package org.apache.camel.processor.binding; 018 019import org.apache.camel.Processor; 020import org.apache.camel.processor.MarshalProcessor; 021import org.apache.camel.processor.UnmarshalProcessor; 022import org.apache.camel.spi.Binding; 023import org.apache.camel.spi.DataFormat; 024import org.apache.camel.support.ServiceSupport; 025import org.apache.camel.util.ObjectHelper; 026 027/** 028 * Represents a {@link org.apache.camel.spi.Binding} which Marshals the message in the ProduceProcessor and 029 * Unmarshals the message in the ConsumeProcessor 030 */ 031@Deprecated 032public class DataFormatBinding extends ServiceSupport implements Binding { 033 private DataFormat producerDataFormat; 034 private DataFormat consumerDataFormat; 035 036 public DataFormatBinding() { 037 } 038 039 public DataFormatBinding(DataFormat dataFormat) { 040 this(dataFormat, dataFormat); 041 } 042 043 public DataFormatBinding(DataFormat consumerDataFormat, DataFormat producerDataFormat) { 044 this.consumerDataFormat = consumerDataFormat; 045 this.producerDataFormat = producerDataFormat; 046 } 047 048 @Override 049 public Processor createProduceProcessor() { 050 ObjectHelper.notNull(producerDataFormat, "producerDataFormat"); 051 return new MarshalProcessor(producerDataFormat); 052 } 053 054 @Override 055 public Processor createConsumeProcessor() { 056 ObjectHelper.notNull(consumerDataFormat, "consumerDataFormat"); 057 return new UnmarshalProcessor(consumerDataFormat); 058 } 059 060 /** 061 * Sets the data format for both producer and consumer sides 062 */ 063 public void setDataFormat(DataFormat dataFormat) { 064 setConsumerDataFormat(dataFormat); 065 setProducerDataFormat(dataFormat); 066 } 067 068 public DataFormat getConsumerDataFormat() { 069 return consumerDataFormat; 070 } 071 072 public void setConsumerDataFormat(DataFormat consumerDataFormat) { 073 this.consumerDataFormat = consumerDataFormat; 074 } 075 076 public DataFormat getProducerDataFormat() { 077 return producerDataFormat; 078 } 079 080 public void setProducerDataFormat(DataFormat producerDataFormat) { 081 this.producerDataFormat = producerDataFormat; 082 } 083 084 @Override 085 protected void doStart() throws Exception { 086 // noop 087 } 088 089 @Override 090 protected void doStop() throws Exception { 091 // noop 092 } 093}