1
2
3
4
5
6
7
8
9
10
11 package org.mule.transformers.simple;
12
13 import org.mule.umo.UMOEventContext;
14 import org.mule.umo.transformer.TransformerException;
15
16
17
18
19
20
21 public class ObjectToByteArray extends SerializableToByteArray
22 {
23
24 public ObjectToByteArray()
25 {
26 this.registerSourceType(Object.class);
27 }
28
29
30 public Object transform(Object src, String encoding, UMOEventContext context) throws TransformerException
31 {
32 if (src instanceof String)
33 {
34 try
35 {
36 return src.toString().getBytes(encoding);
37 }
38 catch (Exception e)
39 {
40 throw new TransformerException(this, e);
41 }
42 }
43 else
44 {
45 return super.transform(src, encoding, context);
46 }
47 }
48
49 }