1
2
3
4
5
6
7
8
9
10
11 package org.mule.tck.testmodels.mule;
12
13 import org.mule.api.MessagingException;
14 import org.mule.api.MuleException;
15 import org.mule.api.ThreadSafeAccess;
16 import org.mule.api.endpoint.InboundEndpoint;
17 import org.mule.api.endpoint.OutboundEndpoint;
18 import org.mule.api.lifecycle.InitialisationException;
19 import org.mule.api.service.Service;
20 import org.mule.api.transport.MessageAdapter;
21 import org.mule.api.transport.MessageDispatcher;
22 import org.mule.api.transport.MessageReceiver;
23 import org.mule.transport.AbstractConnector;
24 import org.mule.transport.AbstractMessageAdapter;
25 import org.mule.transport.AbstractMessageDispatcherFactory;
26 import org.mule.transport.AbstractMessageReceiver;
27
28
29
30
31 public class TestConnector extends AbstractConnector
32 {
33
34 public static final String TEST = "test";
35
36 private String someProperty;
37
38 public TestConnector()
39 {
40 super();
41 setDispatcherFactory(new AbstractMessageDispatcherFactory()
42 {
43 public MessageDispatcher create(OutboundEndpoint endpoint) throws MuleException
44 {
45 return new TestMessageDispatcher(endpoint);
46 }
47 });
48 }
49
50 protected void doInitialise() throws InitialisationException
51 {
52
53 }
54
55 protected void doDispose()
56 {
57
58 }
59
60 protected void doConnect() throws Exception
61 {
62
63 }
64
65 protected void doDisconnect() throws Exception
66 {
67
68 }
69
70 protected void doStart() throws MuleException
71 {
72
73 }
74
75 protected void doStop() throws MuleException
76 {
77
78 }
79
80 public String getProtocol()
81 {
82 return TEST;
83 }
84
85 public MessageAdapter getMessageAdapter(Object message) throws MessagingException
86 {
87 return new DummyMessageAdapter(message);
88 }
89
90 public String getSomeProperty()
91 {
92 return someProperty;
93 }
94
95 public void setSomeProperty(String someProperty)
96 {
97 this.someProperty = someProperty;
98 }
99
100 public MessageReceiver createReceiver(Service service, InboundEndpoint endpoint) throws Exception
101 {
102 MessageReceiver receiver = new AbstractMessageReceiver(this, service, endpoint)
103 {
104
105 protected void doInitialise() throws InitialisationException
106 {
107
108 }
109
110 protected void doConnect() throws Exception
111 {
112
113 }
114
115 protected void doDisconnect() throws Exception
116 {
117
118 }
119
120 protected void doStart() throws MuleException
121 {
122
123 }
124
125 protected void doStop() throws MuleException
126 {
127
128 }
129
130 protected void doDispose()
131 {
132
133 }
134 };
135 return receiver;
136 }
137
138 public void destroyReceiver(MessageReceiver receiver, InboundEndpoint endpoint) throws Exception
139 {
140
141 }
142
143 public class DummyMessageAdapter extends AbstractMessageAdapter
144 {
145
146
147
148 private static final long serialVersionUID = -2304322766342059136L;
149
150 private Object message = new String("DummyMessage");
151
152 public DummyMessageAdapter(Object message)
153 {
154 this.message = message;
155 }
156
157 public Object getPayload()
158 {
159 return message;
160 }
161
162 public byte[] getPayloadAsBytes() throws Exception
163 {
164
165 return message.toString().getBytes();
166 }
167
168 public String getPayloadAsString(String encoding) throws Exception
169 {
170 return message.toString();
171 }
172
173 public void setPayload(Object payload)
174 {
175 this.message = payload;
176 }
177
178 public ThreadSafeAccess newThreadCopy()
179 {
180 return this;
181 }
182 }
183
184 }