KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > tck > testmodels > mule > TestConnector


1 /*
2  * $Id: TestConnector.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

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 JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.io.OutputStream JavaDoc;
33
34 /**
35  * <p>
36  * <code>TestConnector</code> us a mock connector
37  *
38  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
39  * @version $Revision: 3798 $
40  */

41 public class TestConnector extends AbstractConnector
42 {
43     /**
44      * The connector can pool dispatchers based on their endpointUri or can ingnore
45      * the endpointUri altogether and use a ThreadLocal or always create new.
46      *
47      * @param endpoint the endpoint that can be used to key cached dispatchers
48      * @return the component associated with the endpointUri If there is no component
49      * for the current thread one will be created
50      * @throws org.mule.umo.UMOException if creation of a component fails
51      */

52     public UMOMessageDispatcher getDispatcher(UMOImmutableEndpoint endpoint) throws UMOException
53     {
54         return new TestMessageDispatcher(endpoint);
55     }
56
57     /**
58      *
59      */

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     /*
74      * (non-Javadoc)
75      *
76      * @see org.mule.providers.AbstractConnector#doDispose()
77      */

78     protected void doDispose()
79     {
80         // template method
81
}
82
83     /*
84      * (non-Javadoc)
85      *
86      * @see org.mule.providers.AbstractConnector#doInitialise()
87      */

88     public void doInitialise() throws InitialisationException
89     {
90         // template method
91
}
92
93     /*
94      * (non-Javadoc)
95      *
96      * @see org.mule.umo.provider.UMOConnector#getProtocol()
97      */

98     public String JavaDoc getProtocol()
99     {
100         return "test";
101     }
102
103     /*
104      * (non-Javadoc)
105      *
106      * @see org.mule.providers.AbstractConnector#doStart()
107      */

108     protected void doStart() throws UMOException
109     {
110         // template method
111
}
112
113     /*
114      * (non-Javadoc)
115      *
116      * @see org.mule.providers.AbstractConnector#doStop()
117      */

118     protected void doStop() throws UMOException
119     {
120         // template method
121
}
122
123     /*
124      * (non-Javadoc)
125      *
126      * @see org.mule.umo.provider.UMOConnector#getMessageAdapter(java.lang.Object)
127      */

128     public UMOMessageAdapter getMessageAdapter(Object JavaDoc message) throws MessagingException
129     {
130         return new DummyMessageAdapter(message);
131     }
132
133     public UMOStreamMessageAdapter getStreamMessageAdapter(InputStream JavaDoc in, OutputStream JavaDoc out)
134         throws MessagingException
135     {
136         return new DummyMessageAdapter(in);
137     }
138
139     public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception JavaDoc
140     {
141         UMOMessageReceiver receiver = new AbstractMessageReceiver(this, component, endpoint)
142         {
143             public void doConnect() throws Exception JavaDoc
144             {
145                 // nothing to do
146
}
147
148             public void doDisconnect() throws Exception JavaDoc
149             {
150                 // nothing to do
151
}
152         };
153         return receiver;
154     }
155
156     public void destroyReceiver(UMOMessageReceiver receiver, UMOEndpoint endpoint) throws Exception JavaDoc
157     {
158         // nothing to do
159
}
160
161     public class DummyMessageAdapter extends AbstractMessageAdapter implements UMOStreamMessageAdapter
162     {
163         /**
164          * Serial version
165          */

166         private static final long serialVersionUID = -2304322766342059136L;
167
168         private Object JavaDoc message = new String JavaDoc("DummyMessage");
169
170         public DummyMessageAdapter(Object JavaDoc message)
171         {
172             this.message = message;
173         }
174
175         /*
176          * (non-Javadoc)
177          *
178          * @see org.mule.umo.provider.UMOMessageAdapter#getPayload()
179          */

180         public Object JavaDoc getPayload()
181         {
182             return message;
183         }
184
185         /*
186          * (non-Javadoc)
187          *
188          * @see org.mule.umo.provider.UMOMessageAdapter#getPayloadAsBytes()
189          */

190         public byte[] getPayloadAsBytes() throws Exception JavaDoc
191         {
192
193             return message.toString().getBytes();
194         }
195
196         /*
197          * (non-Javadoc)
198          *
199          * @see org.mule.umo.provider.UMOMessageAdapter#getPayloadAsString()
200          */

201         public String JavaDoc getPayloadAsString(String JavaDoc encoding) throws Exception JavaDoc
202         {
203             return message.toString();
204         }
205
206         public InputStream JavaDoc getInputStream()
207         {
208             return null;
209         }
210
211         public OutputStream JavaDoc getOutputStream()
212         {
213             return null;
214         }
215
216         public void write(UMOEvent event) throws IOException JavaDoc
217         {
218             // nothing to do
219
}
220
221         public OutputHandler getOutputHandler()
222         {
223             return null;
224         }
225
226         public void setOutputHandler(OutputHandler handler)
227         {
228             // nothing to do
229
}
230
231         public void release()
232         {
233             // nothing to do
234
}
235     }
236
237 }
238
Popular Tags