1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.transformer.simple; |
8 | |
|
9 | |
import org.mule.api.transformer.DiscoverableTransformer; |
10 | |
import org.mule.api.transformer.TransformerException; |
11 | |
import org.mule.config.i18n.CoreMessages; |
12 | |
import org.mule.transformer.AbstractTransformer; |
13 | |
import org.mule.transformer.types.DataTypeFactory; |
14 | |
import org.mule.util.SerializationUtils; |
15 | |
|
16 | |
import java.io.InputStream; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
public class ByteArrayToSerializable extends AbstractTransformer implements DiscoverableTransformer |
23 | |
{ |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | 0 | private int priorityWeighting = DiscoverableTransformer.DEFAULT_PRIORITY_WEIGHTING + 1; |
29 | |
|
30 | |
public ByteArrayToSerializable() |
31 | 0 | { |
32 | 0 | registerSourceType(DataTypeFactory.BYTE_ARRAY); |
33 | 0 | registerSourceType(DataTypeFactory.INPUT_STREAM); |
34 | 0 | } |
35 | |
|
36 | |
@Override |
37 | |
public Object doTransform(Object src, String encoding) throws TransformerException |
38 | |
{ |
39 | |
try |
40 | |
{ |
41 | |
final Object result; |
42 | 0 | if (src instanceof byte[]) |
43 | |
{ |
44 | 0 | result = SerializationUtils.deserialize((byte[]) src, muleContext); |
45 | |
} |
46 | |
else |
47 | |
{ |
48 | 0 | result = SerializationUtils.deserialize((InputStream) src, muleContext); |
49 | |
} |
50 | 0 | return result; |
51 | |
} |
52 | 0 | catch (Exception e) |
53 | |
{ |
54 | 0 | throw new TransformerException( |
55 | |
CoreMessages.transformFailed("byte[]", "Object"), this, e); |
56 | |
} |
57 | |
} |
58 | |
|
59 | |
public int getPriorityWeighting() |
60 | |
{ |
61 | 0 | return priorityWeighting; |
62 | |
} |
63 | |
|
64 | |
public void setPriorityWeighting(int priorityWeighting) |
65 | |
{ |
66 | 0 | this.priorityWeighting = priorityWeighting; |
67 | 0 | } |
68 | |
} |