1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transformer.simple; |
12 | |
|
13 | |
import org.mule.api.MuleMessage; |
14 | |
import org.mule.api.transformer.DiscoverableTransformer; |
15 | |
import org.mule.api.transformer.TransformerException; |
16 | |
import org.mule.transformer.AbstractTransformer; |
17 | |
|
18 | |
import java.io.Serializable; |
19 | |
|
20 | |
import org.apache.commons.lang.SerializationUtils; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public class SerializableToByteArray extends AbstractTransformer implements DiscoverableTransformer |
30 | |
{ |
31 | |
|
32 | 2350 | private int priorityWeighting = DiscoverableTransformer.DEFAULT_PRIORITY_WEIGHTING; |
33 | |
|
34 | |
public SerializableToByteArray() |
35 | 2350 | { |
36 | 2350 | this.registerSourceType(Serializable.class); |
37 | 2350 | this.setReturnClass(byte[].class); |
38 | 2350 | } |
39 | |
|
40 | |
public boolean isAcceptUMOMessage() |
41 | |
{ |
42 | 0 | return this.isSourceTypeSupported(MuleMessage.class, true); |
43 | |
} |
44 | |
|
45 | |
public void setAcceptUMOMessage(boolean value) |
46 | |
{ |
47 | 0 | if (value) |
48 | |
{ |
49 | 0 | this.registerSourceType(MuleMessage.class); |
50 | |
} |
51 | |
else |
52 | |
{ |
53 | 0 | this.unregisterSourceType(MuleMessage.class); |
54 | |
} |
55 | 0 | } |
56 | |
|
57 | |
public Object doTransform(Object src, String encoding) throws TransformerException |
58 | |
{ |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
try |
67 | |
{ |
68 | 24 | return SerializationUtils.serialize((Serializable) src); |
69 | |
} |
70 | 0 | catch (Exception e) |
71 | |
{ |
72 | 0 | throw new TransformerException(this, e); |
73 | |
} |
74 | |
} |
75 | |
|
76 | |
public int getPriorityWeighting() |
77 | |
{ |
78 | 0 | return priorityWeighting; |
79 | |
} |
80 | |
|
81 | |
public void setPriorityWeighting(int priorityWeighting) |
82 | |
{ |
83 | 0 | this.priorityWeighting = priorityWeighting; |
84 | 0 | } |
85 | |
|
86 | |
} |