1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.tck.testmodels.mule; |
12 | |
|
13 | |
import org.mule.impl.ThreadSafeAccess; |
14 | |
import org.mule.providers.AbstractConnector; |
15 | |
import org.mule.providers.AbstractMessageAdapter; |
16 | |
import org.mule.providers.AbstractMessageDispatcherFactory; |
17 | |
import org.mule.providers.AbstractMessageReceiver; |
18 | |
import org.mule.umo.MessagingException; |
19 | |
import org.mule.umo.UMOComponent; |
20 | |
import org.mule.umo.UMOEvent; |
21 | |
import org.mule.umo.UMOException; |
22 | |
import org.mule.umo.endpoint.UMOEndpoint; |
23 | |
import org.mule.umo.endpoint.UMOImmutableEndpoint; |
24 | |
import org.mule.umo.lifecycle.InitialisationException; |
25 | |
import org.mule.umo.provider.OutputHandler; |
26 | |
import org.mule.umo.provider.UMOMessageAdapter; |
27 | |
import org.mule.umo.provider.UMOMessageDispatcher; |
28 | |
import org.mule.umo.provider.UMOMessageReceiver; |
29 | |
import org.mule.umo.provider.UMOStreamMessageAdapter; |
30 | |
|
31 | |
import java.io.IOException; |
32 | |
import java.io.InputStream; |
33 | |
import java.io.OutputStream; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public class TestConnector extends AbstractConnector |
39 | |
{ |
40 | |
|
41 | |
public TestConnector() |
42 | |
{ |
43 | 778 | super(); |
44 | 778 | setDispatcherFactory(new AbstractMessageDispatcherFactory() |
45 | |
{ |
46 | 778 | public UMOMessageDispatcher create(UMOImmutableEndpoint endpoint) throws UMOException |
47 | |
{ |
48 | 4 | return new TestMessageDispatcher(endpoint); |
49 | |
} |
50 | |
}); |
51 | 778 | } |
52 | |
|
53 | |
protected void doInitialise() throws InitialisationException |
54 | |
{ |
55 | |
|
56 | 22 | } |
57 | |
|
58 | |
protected void doDispose() |
59 | |
{ |
60 | |
|
61 | 46 | } |
62 | |
|
63 | |
protected void doConnect() throws Exception |
64 | |
{ |
65 | |
|
66 | 22 | } |
67 | |
|
68 | |
protected void doDisconnect() throws Exception |
69 | |
{ |
70 | |
|
71 | 22 | } |
72 | |
|
73 | |
protected void doStart() throws UMOException |
74 | |
{ |
75 | |
|
76 | 22 | } |
77 | |
|
78 | |
protected void doStop() throws UMOException |
79 | |
{ |
80 | |
|
81 | 22 | } |
82 | |
|
83 | |
public String getProtocol() |
84 | |
{ |
85 | 916 | return "test"; |
86 | |
} |
87 | |
|
88 | |
public UMOMessageAdapter getMessageAdapter(Object message) throws MessagingException |
89 | |
{ |
90 | 0 | return new DummyMessageAdapter(message); |
91 | |
} |
92 | |
|
93 | |
public UMOStreamMessageAdapter getStreamMessageAdapter(InputStream in, OutputStream out) |
94 | |
throws MessagingException |
95 | |
{ |
96 | 0 | return new DummyMessageAdapter(in); |
97 | |
} |
98 | |
|
99 | |
public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception |
100 | |
{ |
101 | 22 | UMOMessageReceiver receiver = new AbstractMessageReceiver(this, component, endpoint) |
102 | |
{ |
103 | |
protected void doConnect() throws Exception |
104 | |
{ |
105 | |
|
106 | 22 | } |
107 | |
|
108 | |
protected void doDisconnect() throws Exception |
109 | |
{ |
110 | |
|
111 | 20 | } |
112 | |
|
113 | |
protected void doStart() throws UMOException |
114 | |
{ |
115 | |
|
116 | 12 | } |
117 | |
|
118 | |
protected void doStop() throws UMOException |
119 | |
{ |
120 | |
|
121 | 10 | } |
122 | |
|
123 | 22 | protected void doDispose() |
124 | |
{ |
125 | |
|
126 | 0 | } |
127 | |
}; |
128 | 22 | return receiver; |
129 | |
} |
130 | |
|
131 | |
public void destroyReceiver(UMOMessageReceiver receiver, UMOEndpoint endpoint) throws Exception |
132 | |
{ |
133 | |
|
134 | 22 | } |
135 | |
|
136 | |
public class DummyMessageAdapter extends AbstractMessageAdapter implements UMOStreamMessageAdapter |
137 | |
{ |
138 | |
|
139 | |
|
140 | |
|
141 | |
private static final long serialVersionUID = -2304322766342059136L; |
142 | |
|
143 | 0 | private Object message = new String("DummyMessage"); |
144 | |
|
145 | |
public DummyMessageAdapter(Object message) |
146 | 0 | { |
147 | 0 | this.message = message; |
148 | 0 | } |
149 | |
|
150 | |
public Object getPayload() |
151 | |
{ |
152 | 0 | return message; |
153 | |
} |
154 | |
|
155 | |
public byte[] getPayloadAsBytes() throws Exception |
156 | |
{ |
157 | |
|
158 | 0 | return message.toString().getBytes(); |
159 | |
} |
160 | |
|
161 | |
public String getPayloadAsString(String encoding) throws Exception |
162 | |
{ |
163 | 0 | return message.toString(); |
164 | |
} |
165 | |
|
166 | |
public InputStream getInputStream() |
167 | |
{ |
168 | 0 | return null; |
169 | |
} |
170 | |
|
171 | |
public OutputStream getOutputStream() |
172 | |
{ |
173 | 0 | return null; |
174 | |
} |
175 | |
|
176 | |
public void write(UMOEvent event) throws IOException |
177 | |
{ |
178 | |
|
179 | 0 | } |
180 | |
|
181 | |
public OutputHandler getOutputHandler() |
182 | |
{ |
183 | 0 | return null; |
184 | |
} |
185 | |
|
186 | |
public void setOutputHandler(OutputHandler handler) |
187 | |
{ |
188 | |
|
189 | 0 | } |
190 | |
|
191 | |
public void release() |
192 | |
{ |
193 | |
|
194 | 0 | } |
195 | |
|
196 | |
public ThreadSafeAccess newThreadCopy() |
197 | |
{ |
198 | 0 | return this; |
199 | |
} |
200 | |
} |
201 | |
|
202 | |
} |