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; 023 024import org.apache.camel.spi.Metadata; 025 026/** 027 * Set the expected data type of the output message. If the actual message type 028 * is different at runtime, camel look for a required {@link Transformer} and 029 * apply if exists. If validate attribute is true then camel applies 030 * {@link Validator} as well. Type name consists of two parts, 'scheme' and 031 * 'name' connected with ':'. For Java type 'name' is a fully qualified class 032 * name. For example {@code java:java.lang.String}, {@code json:ABCOrder}. It's 033 * also possible to specify only scheme part, so that it works like a wildcard. 034 * If only 'xml' is specified, all the XML message matches. It's handy to add 035 * only one transformer/validator for all the XML-Java transformation. 036 * 037 * @see {@link InputTypeDefinition} {@link Transformer} {@link Validator} 038 */ 039@Metadata(label = "configuration") 040@XmlRootElement(name = "outputType") 041@XmlAccessorType(XmlAccessType.FIELD) 042public class OutputTypeDefinition extends OptionalIdentifiedDefinition<OutputTypeDefinition> { 043 @XmlAttribute 044 @Metadata(required = true) 045 private String urn; 046 @XmlAttribute 047 @Metadata(defaultValue = "false") 048 private Boolean validate = false; 049 050 public OutputTypeDefinition() { 051 } 052 053 /** 054 * Get output type URN. 055 * 056 * @return output type URN 057 */ 058 public String getUrn() { 059 return urn; 060 } 061 062 /** 063 * Set output type URN. 064 * 065 * @param urn output type URN 066 * @return this OutputTypeDefinition instance 067 */ 068 public void setUrn(String urn) { 069 this.urn = urn; 070 } 071 072 /** 073 * Set output type via Java Class. 074 * 075 * @param clazz Java Class 076 */ 077 public void setJavaClass(Class<?> clazz) { 078 this.urn = "java:" + clazz.getName(); 079 } 080 081 /** 082 * Get if validation is required for this output type. 083 * 084 * @return true if validate 085 */ 086 public boolean isValidate() { 087 return this.validate; 088 } 089 090 /** 091 * Set if validation is required for this output type. 092 * 093 * @param validate true if validate 094 */ 095 public void setValidate(boolean validate) { 096 this.validate = validate; 097 } 098 099 @Override 100 public String toString() { 101 return "outputType[" + urn + "]"; 102 } 103 104 @Override 105 public String getShortName() { 106 return "outputType"; 107 } 108 109 @Override 110 public String getLabel() { 111 return "outputType[" + urn + "]"; 112 } 113 114}