KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > transport > mock > MockTransportFactory


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.transport.mock;
19
20 import java.io.IOException JavaDoc;
21 import java.net.URI JavaDoc;
22 import java.net.URISyntaxException JavaDoc;
23
24 import org.apache.activemq.transport.MutexTransport;
25 import org.apache.activemq.transport.ResponseCorrelator;
26 import org.apache.activemq.transport.Transport;
27 import org.apache.activemq.transport.TransportFactory;
28 import org.apache.activemq.transport.TransportServer;
29 import org.apache.activemq.util.IntrospectionSupport;
30 import org.apache.activemq.util.URISupport;
31 import org.apache.activemq.util.URISupport.CompositeData;
32
33 public class MockTransportFactory extends TransportFactory {
34
35     public Transport doConnect(URI JavaDoc location) throws URISyntaxException JavaDoc, Exception JavaDoc {
36         Transport transport = createTransport(URISupport.parseComposite(location));
37         transport = new MutexTransport(transport);
38         transport = new ResponseCorrelator(transport);
39         return transport;
40     }
41     
42     public Transport doCompositeConnect(URI JavaDoc location) throws URISyntaxException JavaDoc, Exception JavaDoc {
43         return createTransport(URISupport.parseComposite(location));
44     }
45     
46     /**
47      * @param location
48      * @return
49      * @throws Exception
50      */

51     public Transport createTransport(CompositeData compositData) throws Exception JavaDoc {
52         MockTransport transport = new MockTransport( TransportFactory.compositeConnect(compositData.getComponents()[0]) );
53         IntrospectionSupport.setProperties(transport, compositData.getParameters());
54         return transport;
55     }
56
57     public TransportServer doBind(String JavaDoc brokerId,URI JavaDoc location) throws IOException JavaDoc {
58         throw new IOException JavaDoc("This protocol does not support being bound.");
59     }
60
61 }
62
Popular Tags