KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > net > SocketConnectionFactory


1 package org.sapia.ubik.net;
2
3 import java.io.IOException JavaDoc;
4
5 import java.net.Socket JavaDoc;
6
7 import java.rmi.server.RMIClientSocketFactory JavaDoc;
8
9
10 /**
11  * Implements a factory of <code>SocketConnection</code> instances.
12  *
13  * @author Yanick Duchesne
14  * <dl>
15  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2003 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
16  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
17  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
18  * </dl>
19  */

20 public class SocketConnectionFactory implements ConnectionFactory {
21   protected ClassLoader JavaDoc _loader;
22   protected RMIClientSocketFactory JavaDoc _clientSocketFactory;
23
24   public SocketConnectionFactory() {
25     this(Thread.currentThread().getContextClassLoader());
26   }
27
28   public SocketConnectionFactory(RMIClientSocketFactory JavaDoc client) {
29     this(Thread.currentThread().getContextClassLoader());
30     _clientSocketFactory = client;
31   }
32
33   public SocketConnectionFactory(RMIClientSocketFactory JavaDoc client,
34     ClassLoader JavaDoc loader) {
35     this(loader);
36     _clientSocketFactory = client;
37   }
38
39   public SocketConnectionFactory(ClassLoader JavaDoc loader) {
40     _loader = loader;
41   }
42
43   /**
44    * @see org.sapia.ubik.net.ConnectionFactory#newConnection(String, int)
45    */

46   public Connection newConnection(String JavaDoc host, int port)
47     throws IOException JavaDoc {
48     if (_clientSocketFactory == null) {
49       return new SocketConnection(new Socket JavaDoc(host, port), _loader);
50     } else {
51       return new SocketConnection(_clientSocketFactory.createSocket(host, port),
52         _loader);
53     }
54   }
55
56   /**
57    * Creates a new Connection around the given socket.
58    *
59    * @see org.sapia.ubik.net.ConnectionFactory#newConnection(String, int)
60    * @return a <code>SocketConnection</code>.
61    */

62   public Connection newConnection(Socket JavaDoc sock) throws IOException JavaDoc {
63     return new SocketConnection(sock, _loader);
64   }
65 }
66
Popular Tags