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.transformer; 018 019import javax.xml.bind.annotation.XmlAccessType; 020import javax.xml.bind.annotation.XmlAccessorType; 021import javax.xml.bind.annotation.XmlAttribute; 022import javax.xml.bind.annotation.XmlType; 023 024import org.apache.camel.model.InputTypeDefinition; 025import org.apache.camel.model.OutputTypeDefinition; 026import org.apache.camel.spi.DataType; 027import org.apache.camel.spi.Metadata; 028 029/** 030 * <p> 031 * Represents a {@link org.apache.camel.spi.Transformer} which declaratively 032 * transforms message content according to the input type declared by 033 * {@link InputTypeDefinition} and/or output type declared by 034 * {@link OutputTypeDefinition}. 035 * </p> 036 * <p> 037 * If you specify from='java:com.example.ABC' and to='xml:XYZ', the transformer 038 * will be picked up when current message type is 'java:com.example.ABC' and 039 * expected message type is 'xml:XYZ'. If you specify from='java' to='xml', then 040 * it will be picked up for all of java to xml transformation. Also it's 041 * possible to specify scheme='xml' so that the transformer will be picked up 042 * for all of java to xml and xml to java transformation. 043 * </p> 044 * {@see org.apache.camel.spi.Transformer} {@see InputTypeDefinition} 045 * {@see OutputTypeDefinition} 046 */ 047@Metadata(label = "transformation") 048@XmlType(name = "transformer") 049@XmlAccessorType(XmlAccessType.FIELD) 050public abstract class TransformerDefinition { 051 052 @XmlAttribute 053 private String scheme; 054 @XmlAttribute 055 private String fromType; 056 @XmlAttribute 057 private String toType; 058 059 public String getScheme() { 060 return scheme; 061 } 062 063 /** 064 * Set a scheme name supported by the transformer. If you specify 'csv', the 065 * transformer will be picked up for all of 'csv' from/to Java 066 * transformation. Note that the scheme matching is performed only when no 067 * exactly matched transformer exists. 068 * 069 * @param scheme scheme name 070 */ 071 public void setScheme(String scheme) { 072 this.scheme = scheme; 073 } 074 075 public String getFromType() { 076 return fromType; 077 } 078 079 /** 080 * Set the 'from' data type name. If you specify 'xml:XYZ', the transformer 081 * will be picked up if source type is 'xml:XYZ'. If you specify just 'xml', 082 * the transformer matches with all of 'xml' source type like 'xml:ABC' or 083 * 'xml:DEF'. 084 * 085 * @param from 'from' data type name 086 */ 087 public void setFromType(String from) { 088 this.fromType = from; 089 } 090 091 /** 092 * Set the 'from' data type using Java class. 093 * 094 * @param clazz 'from' Java class 095 */ 096 public void setFromType(Class<?> clazz) { 097 this.fromType = new DataType(clazz).toString(); 098 } 099 100 public String getToType() { 101 return toType; 102 } 103 104 /** 105 * Set the 'to' data type name. If you specify 'json:XYZ', the transformer 106 * will be picked up if destination type is 'json:XYZ'. If you specify just 107 * 'json', the transformer matches with all of 'json' destination type like 108 * 'json:ABC' or 'json:DEF'. 109 * 110 * @param to 'to' data type name 111 */ 112 public void setToType(String to) { 113 this.toType = to; 114 } 115 116 /** 117 * Set the 'to' data type using Java class. 118 * 119 * @param clazz 'to' Java class 120 */ 121 public void setToType(Class<?> clazz) { 122 this.toType = new DataType(clazz).toString(); 123 } 124 125}