KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > maverick > http > SocketWithLayeredTransportFactory


1 package com.maverick.http;
2
3 import java.io.IOException JavaDoc;
4 import java.net.InetAddress JavaDoc;
5 import java.net.UnknownHostException JavaDoc;
6
7 public class SocketWithLayeredTransportFactory {
8
9     // #ifdef DEBUG
10
static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory.getLog(SocketWithLayeredTransportFactory.class);
11     // #endif
12

13     static SocketWithLayeredTransportFactory instance = null;
14     static Class JavaDoc socketFactoryImpl = SocketWithLayeredTransportFactory.class;
15     
16     public SocketWithLayeredTransport createSocket(String JavaDoc arg0, int arg1) throws IOException JavaDoc,
17             UnknownHostException JavaDoc {
18         return new SocketWithLayeredTransport(arg0, arg1);
19     }
20
21     public SocketWithLayeredTransport createSocket(InetAddress JavaDoc arg0, int arg1) throws IOException JavaDoc {
22         return new SocketWithLayeredTransport(arg0, arg1);
23     }
24     
25     
26     public static SocketWithLayeredTransportFactory getDefault() {
27         
28         try {
29             return instance==null ? instance = (SocketWithLayeredTransportFactory) socketFactoryImpl.newInstance() : instance;
30         } catch (Exception JavaDoc e) {
31             //#ifdef DEBUG
32
log.error("Failed to create instance of socket factory" + socketFactoryImpl.getName(), e);
33             //#endif
34
return instance = new SocketWithLayeredTransportFactory();
35         }
36     }
37     
38     public static void setFactoryImpl(Class JavaDoc socketFactoryImpl) {
39         SocketWithLayeredTransportFactory.socketFactoryImpl = socketFactoryImpl;
40     }
41 }
42
Popular Tags