1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.components.simple; |
12 | |
|
13 | |
import org.mule.umo.UMOEventContext; |
14 | |
import org.mule.umo.lifecycle.Callable; |
15 | |
import org.mule.umo.lifecycle.Initialisable; |
16 | |
import org.mule.umo.lifecycle.InitialisationException; |
17 | |
import org.mule.util.IOUtils; |
18 | |
|
19 | |
import java.io.IOException; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | 0 | public class StaticComponent implements Callable, Initialisable |
27 | |
{ |
28 | |
|
29 | |
private Object data; |
30 | |
private String dataFile; |
31 | |
private String prefix; |
32 | |
private String postfix; |
33 | |
|
34 | |
public void initialise() throws InitialisationException |
35 | |
{ |
36 | 0 | if (dataFile != null) |
37 | |
{ |
38 | |
try |
39 | |
{ |
40 | 0 | data = IOUtils.getResourceAsString(dataFile, getClass()); |
41 | |
} |
42 | 0 | catch (IOException e) |
43 | |
{ |
44 | 0 | throw new InitialisationException(e, this); |
45 | 0 | } |
46 | |
} |
47 | 0 | } |
48 | |
|
49 | |
public Object getData() |
50 | |
{ |
51 | 0 | return data; |
52 | |
} |
53 | |
|
54 | |
public void setData(Object data) |
55 | |
{ |
56 | 0 | this.data = data; |
57 | 0 | } |
58 | |
|
59 | |
public String getDataFile() |
60 | |
{ |
61 | 0 | return dataFile; |
62 | |
} |
63 | |
|
64 | |
public void setDataFile(String dataFile) |
65 | |
{ |
66 | 0 | this.dataFile = dataFile; |
67 | 0 | } |
68 | |
|
69 | |
public String getPrefix() |
70 | |
{ |
71 | 0 | return prefix; |
72 | |
} |
73 | |
|
74 | |
public void setPrefix(String prefix) |
75 | |
{ |
76 | 0 | this.prefix = prefix; |
77 | 0 | } |
78 | |
|
79 | |
public String getPostfix() |
80 | |
{ |
81 | 0 | return postfix; |
82 | |
} |
83 | |
|
84 | |
public void setPostfix(String postfix) |
85 | |
{ |
86 | 0 | this.postfix = postfix; |
87 | 0 | } |
88 | |
|
89 | |
public Object onCall(UMOEventContext eventContext) throws Exception |
90 | |
{ |
91 | 0 | if (data != null) |
92 | |
{ |
93 | 0 | return data; |
94 | |
} |
95 | |
|
96 | 0 | String eventData = eventContext.getTransformedMessageAsString(); |
97 | |
|
98 | 0 | if (prefix != null) |
99 | |
{ |
100 | 0 | eventData = prefix + eventData; |
101 | |
} |
102 | |
|
103 | 0 | if (postfix != null) |
104 | |
{ |
105 | 0 | eventData += postfix; |
106 | |
} |
107 | |
|
108 | 0 | return eventData; |
109 | |
} |
110 | |
} |