KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.sslexplorer.boot;
2
3 import java.io.IOException JavaDoc;
4 import java.net.InetAddress JavaDoc;
5 import java.net.ServerSocket JavaDoc;
6
7 import javax.net.ServerSocketFactory;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12 /**
13  */

14 public class CustomServerSocketFactory extends ServerSocketFactory {
15
16     private static final Log log = LogFactory.getLog(CustomServerSocketFactory.class);
17     private static ServerSocketFactory instance;
18     private static Class JavaDoc<? extends ServerSocketFactory> socketFactoryImpl = CustomServerSocketFactory.class;
19
20     @Override JavaDoc
21     public ServerSocket JavaDoc createServerSocket(int port) throws IOException JavaDoc {
22         return new ServerSocket JavaDoc(port);
23     }
24
25     @Override JavaDoc
26     public ServerSocket JavaDoc createServerSocket(int port, int backlog) throws IOException JavaDoc {
27         return new ServerSocket JavaDoc(port, backlog);
28     }
29
30     @Override JavaDoc
31     public ServerSocket JavaDoc createServerSocket(int port, int backlog, InetAddress JavaDoc address) throws IOException JavaDoc {
32         return new ServerSocket JavaDoc(port, backlog, address);
33     }
34
35     public static ServerSocketFactory getDefault() {
36         try {
37             return instance == null ? instance = (ServerSocketFactory) socketFactoryImpl.newInstance() : instance;
38         } catch (Exception JavaDoc e) {
39             log.error("Could not create instance of class " + socketFactoryImpl.getCanonicalName(), e);
40             return instance == null ? instance = new CustomServerSocketFactory() : instance;
41         }
42     }
43
44     /**
45      * @param socketFactoryImpl
46      */

47     public static void setFactoryImpl(Class JavaDoc<? extends ServerSocketFactory> socketFactoryImpl) {
48         CustomServerSocketFactory.socketFactoryImpl = socketFactoryImpl;
49     }
50 }
Popular Tags