1 10 11 package org.mule.tck.testmodels.mule; 12 13 import org.mule.providers.AbstractConnector; 14 import org.mule.providers.AbstractMessageAdapter; 15 import org.mule.providers.AbstractMessageReceiver; 16 import org.mule.umo.MessagingException; 17 import org.mule.umo.UMOComponent; 18 import org.mule.umo.UMOEvent; 19 import org.mule.umo.UMOException; 20 import org.mule.umo.endpoint.UMOEndpoint; 21 import org.mule.umo.endpoint.UMOImmutableEndpoint; 22 import org.mule.umo.lifecycle.InitialisationException; 23 import org.mule.umo.provider.OutputHandler; 24 import org.mule.umo.provider.UMOMessageAdapter; 25 import org.mule.umo.provider.UMOMessageDispatcher; 26 import org.mule.umo.provider.UMOMessageDispatcherFactory; 27 import org.mule.umo.provider.UMOMessageReceiver; 28 import org.mule.umo.provider.UMOStreamMessageAdapter; 29 30 import java.io.IOException ; 31 import java.io.InputStream ; 32 import java.io.OutputStream ; 33 34 41 public class TestConnector extends AbstractConnector 42 { 43 52 public UMOMessageDispatcher getDispatcher(UMOImmutableEndpoint endpoint) throws UMOException 53 { 54 return new TestMessageDispatcher(endpoint); 55 } 56 57 60 public TestConnector() 61 { 62 super(); 63 setDispatcherFactory(new UMOMessageDispatcherFactory() 64 { 65 66 public UMOMessageDispatcher create(UMOImmutableEndpoint endpoint) throws UMOException 67 { 68 return new TestMessageDispatcher(endpoint); 69 } 70 }); 71 } 72 73 78 protected void doDispose() 79 { 80 } 82 83 88 public void doInitialise() throws InitialisationException 89 { 90 } 92 93 98 public String getProtocol() 99 { 100 return "test"; 101 } 102 103 108 protected void doStart() throws UMOException 109 { 110 } 112 113 118 protected void doStop() throws UMOException 119 { 120 } 122 123 128 public UMOMessageAdapter getMessageAdapter(Object message) throws MessagingException 129 { 130 return new DummyMessageAdapter(message); 131 } 132 133 public UMOStreamMessageAdapter getStreamMessageAdapter(InputStream in, OutputStream out) 134 throws MessagingException 135 { 136 return new DummyMessageAdapter(in); 137 } 138 139 public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception 140 { 141 UMOMessageReceiver receiver = new AbstractMessageReceiver(this, component, endpoint) 142 { 143 public void doConnect() throws Exception 144 { 145 } 147 148 public void doDisconnect() throws Exception 149 { 150 } 152 }; 153 return receiver; 154 } 155 156 public void destroyReceiver(UMOMessageReceiver receiver, UMOEndpoint endpoint) throws Exception 157 { 158 } 160 161 public class DummyMessageAdapter extends AbstractMessageAdapter implements UMOStreamMessageAdapter 162 { 163 166 private static final long serialVersionUID = -2304322766342059136L; 167 168 private Object message = new String ("DummyMessage"); 169 170 public DummyMessageAdapter(Object message) 171 { 172 this.message = message; 173 } 174 175 180 public Object getPayload() 181 { 182 return message; 183 } 184 185 190 public byte[] getPayloadAsBytes() throws Exception 191 { 192 193 return message.toString().getBytes(); 194 } 195 196 201 public String getPayloadAsString(String encoding) throws Exception 202 { 203 return message.toString(); 204 } 205 206 public InputStream getInputStream() 207 { 208 return null; 209 } 210 211 public OutputStream getOutputStream() 212 { 213 return null; 214 } 215 216 public void write(UMOEvent event) throws IOException 217 { 218 } 220 221 public OutputHandler getOutputHandler() 222 { 223 return null; 224 } 225 226 public void setOutputHandler(OutputHandler handler) 227 { 228 } 230 231 public void release() 232 { 233 } 235 } 236 237 } 238 | Popular Tags |