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.model; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlRootElement; 023import javax.xml.bind.annotation.XmlTransient; 024 025import org.apache.camel.spi.Metadata; 026 027/** 028 * Converts the message body to another type 029 */ 030@Metadata(label = "eip,transformation") 031@XmlRootElement(name = "convertBodyTo") 032@XmlAccessorType(XmlAccessType.FIELD) 033public class ConvertBodyDefinition extends NoOutputDefinition<ConvertBodyDefinition> { 034 @XmlAttribute(required = true) 035 private String type; 036 @XmlAttribute 037 private String charset; 038 @XmlTransient 039 private Class<?> typeClass; 040 041 public ConvertBodyDefinition() { 042 } 043 044 public ConvertBodyDefinition(String type) { 045 setType(type); 046 } 047 048 public ConvertBodyDefinition(Class<?> typeClass) { 049 setTypeClass(typeClass); 050 setType(typeClass.getCanonicalName()); 051 } 052 053 public ConvertBodyDefinition(Class<?> typeClass, String charset) { 054 setTypeClass(typeClass); 055 setType(typeClass.getCanonicalName()); 056 setCharset(charset); 057 } 058 059 @Override 060 public String toString() { 061 return "ConvertBodyTo[" + getType() + "]"; 062 } 063 064 @Override 065 public String getShortName() { 066 return "convertBodyTo"; 067 } 068 069 @Override 070 public String getLabel() { 071 return "convertBodyTo[" + getType() + "]"; 072 } 073 074 public String getType() { 075 return type; 076 } 077 078 /** 079 * The java type to convert to 080 */ 081 public void setType(String type) { 082 this.type = type; 083 } 084 085 public Class<?> getTypeClass() { 086 return typeClass; 087 } 088 089 public void setTypeClass(Class<?> typeClass) { 090 this.typeClass = typeClass; 091 } 092 093 public String getCharset() { 094 return charset; 095 } 096 097 /** 098 * To use a specific charset when converting 099 */ 100 public void setCharset(String charset) { 101 this.charset = charset; 102 } 103}