1 10 11 package org.mule.transformers.simple; 12 13 import java.util.Map ; 14 15 import org.mule.config.i18n.Message; 16 import org.mule.transformers.AbstractTransformer; 17 import org.mule.umo.transformer.TransformerException; 18 19 24 25 public class MapLookup extends AbstractTransformer 26 { 27 28 private static final long serialVersionUID = -9033005899991305309L; 29 30 protected Object key; 31 32 public MapLookup() 33 { 34 registerSourceType(Map .class); 35 setReturnClass(Object .class); 36 } 37 38 public Object doTransform(Object src, String encoding) throws TransformerException 39 { 40 if (src instanceof Map ) 41 { 42 if (key != null) 43 { 44 return ((Map )src).get(key); 45 } 46 else 47 { 48 throw new TransformerException( 49 Message.createStaticMessage("Property 'key' must be set in order to use this transformer.")); 50 } 51 } 52 else 53 throw new TransformerException( 54 Message.createStaticMessage("Message to transform must be of type java.util.Map")); 55 } 56 57 public Object getKey() 58 { 59 return key; 60 } 61 62 public void setKey(Object key) 63 { 64 this.key = key; 65 } 66 } 67 | Popular Tags |