KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > boot > CustomSocketFactory


1 package com.sslexplorer.boot;
2
3 import java.io.IOException JavaDoc;
4 import java.net.InetAddress JavaDoc;
5 import java.net.Socket JavaDoc;
6 import java.net.UnknownHostException JavaDoc;
7
8 import javax.net.SocketFactory;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12
13 public class CustomSocketFactory extends SocketFactory {
14
15     static Log log = LogFactory.getLog(CustomSSLSocketFactory.class);
16
17     static SocketFactory instance;
18     static Class JavaDoc socketFactoryImpl = CustomSocketFactory.class;
19     
20     public Socket JavaDoc createSocket(String JavaDoc arg0, int arg1) throws IOException JavaDoc,
21             UnknownHostException JavaDoc {
22         return new Socket JavaDoc(arg0, arg1);
23     }
24
25     public Socket JavaDoc createSocket(InetAddress JavaDoc arg0, int arg1) throws IOException JavaDoc {
26         return new Socket JavaDoc(arg0, arg1);
27     }
28
29     public Socket JavaDoc createSocket(String JavaDoc arg0, int arg1, InetAddress JavaDoc arg2, int arg3)
30             throws IOException JavaDoc, UnknownHostException JavaDoc {
31         return new Socket JavaDoc(arg0, arg1, arg2, arg3);
32     }
33
34     public Socket JavaDoc createSocket(InetAddress JavaDoc arg0, int arg1, InetAddress JavaDoc arg2,
35             int arg3) throws IOException JavaDoc {
36         return new Socket JavaDoc(arg0, arg1, arg2, arg3);
37     }
38
39     public static SocketFactory getDefault() {
40         try {
41             return instance == null ? instance = (SocketFactory) socketFactoryImpl.newInstance() : instance;
42         } catch (Exception JavaDoc e) {
43             log.error("Could not create instance of class " + socketFactoryImpl.getCanonicalName(), e);
44             return instance == null ? instance = new CustomSocketFactory() : instance;
45         }
46     }
47     
48     public static void setFactoryImpl(Class JavaDoc socketFactoryImpl) {
49         CustomSocketFactory.socketFactoryImpl = socketFactoryImpl;
50         instance = null;
51     }
52 }
53
Popular Tags