1 10 11 package org.mule.transformers.simple; 12 13 import org.apache.commons.lang.SerializationUtils; 14 import org.mule.transformers.AbstractEventAwareTransformer; 15 import org.mule.umo.UMOEventContext; 16 import org.mule.umo.UMOMessage; 17 import org.mule.umo.transformer.TransformerException; 18 19 import java.io.Serializable ; 20 21 27 public class SerializableToByteArray extends AbstractEventAwareTransformer 28 { 29 32 private static final long serialVersionUID = 8899970312989435192L; 33 34 public SerializableToByteArray() 35 { 36 registerSourceType(Serializable .class); 37 registerSourceType(byte[].class); 38 this.setReturnClass(byte[].class); 39 } 40 41 public Object transform(Object src, String encoding, UMOEventContext context) throws TransformerException 42 { 43 48 if (isSourceTypeSupported(UMOMessage.class, true)) 49 { 50 src = context.getMessage(); 51 } 52 else if (src instanceof byte[]) 53 { 54 return src; 55 } 56 57 try 58 { 59 return SerializationUtils.serialize((Serializable )src); 60 } 61 catch (Exception e) 62 { 63 throw new TransformerException(this, e); 64 } 65 } 66 } 67 | Popular Tags |