1 /* 2 * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com 3 * The software in this package is published under the terms of the CPAL v1.0 4 * license, a copy of which has been included with this distribution in the 5 * LICENSE.txt file. 6 */ 7 package org.mule.api.annotations; 8 9 import java.lang.annotation.Documented; 10 import java.lang.annotation.ElementType; 11 import java.lang.annotation.Retention; 12 import java.lang.annotation.RetentionPolicy; 13 import java.lang.annotation.Target; 14 15 /** 16 * Used to mark a that a class contains methods which are Mule Transformer, which means it will be made available in the Mule container. 17 * Transformers are used to convert one object type to another. Mule uses them to provide automatic conversion of Java types 18 * and now support Mime type conversion too. 19 * 20 * The parameters passed into the method define the source object(s) to transform, the return type of the method defines the return object type. 21 * Transformers can define additional source types, that when received will be automatically converted to the parameter type accepted by 22 * the annotated method. 23 * 24 * There are some rules to follow when writing a transformer method - 25 * <ol> 26 * <li>The method's declaring class must be annotated with ContainsTransformerMethods</li> 27 * <li>The annotation must appear on a concrete method, not on an abstract or interface method</li> 28 * <li>The method must be public</li> 29 * <li>The method must have a non-void return type</li> 30 * <li>The method must have at least one parameter argument</li> 31 * </ol> 32 * 33 * It is good practice to define any custom transformers in their own class (a class can have more than one transformer method). 34 * A transformer class should be thread-safe and not have any transitive state, meaning that it should not maintain state as 35 * a result of a transformation. It is fine for transformers to have configuration state, such as in an XSLT or XQuery template file 36 * (note that Mule already provides transformers for XSLT and XQuery). 37 */ 38 @Target(ElementType.METHOD) 39 @Retention(RetentionPolicy.RUNTIME) 40 @Documented 41 public @interface Transformer 42 { 43 /** 44 * The 'priorityWeighting property is used to resolve conflicts where there is more than one transformers that match 45 * the selection criteria. 10 is the highest priority and 1 is the lowest. 46 * 47 * @return the priority weighting for this transformer. If the class defines more than one transform method, every transform 48 * method will have the same weighting. 49 */ 50 int priorityWeighting() default 5; 51 52 //TODO BL-140 add when we get support for Transformer mime types 53 // String sourceMimeType() default MimeTypes.ANY; 54 // 55 // String resultMimeType() default MimeTypes.ANY; 56 57 /** 58 * SourceTypes define additional types that this transformer will accepts as a sourceType (beyond the method parameter). 59 * At run time if the current message matches one of these source types, Mule will attempt to transform from 60 * the source type to the method parameter type. This means that transformations can be chained. The user can create 61 * other transformers to be a part of this chain. 62 * 63 * @return an array of class types which allow the transformer to be matched on 64 */ 65 Class[] sourceTypes() default {}; 66 }