View Javadoc

1   package ca.uhn.hl7v2.hoh.util;
2   
3   import java.io.IOException;
4   import java.net.ServerSocket;
5   import java.net.Socket;
6   
7   import javax.net.ServerSocketFactory;
8   
9   import ca.uhn.hl7v2.hoh.sockets.ISocketFactory;
10  import ca.uhn.hl7v2.util.SocketFactory;
11  
12  /**
13   * Wraps an HoH {@link ISocketFactory} instance for use in HAPI. Note that the
14   * wrapped methods will only be used to create TLS socket instances.
15   */
16  public class HapiSocketTlsFactoryWrapper implements SocketFactory {
17  
18  	private ISocketFactory mySocketFactory;
19  
20  	/**
21  	 * Constuctor
22  	 * 
23  	 * @param theSocketFactoryToWrap
24  	 *            The socket factory to wrap. This instance will only be used
25  	 *            for {@link #createTlsSocket()} and
26  	 *            {@link #createTlsServerSocket()}
27  	 */
28  	public HapiSocketTlsFactoryWrapper(ISocketFactory theSocketFactoryToWrap) {
29  		mySocketFactory = theSocketFactoryToWrap;
30  	}
31  
32  	/**
33  	 * {@inheritDoc}
34  	 */
35  	public Socket createSocket() throws IOException {
36  		return javax.net.SocketFactory.getDefault().createSocket();
37  	}
38  
39  	/**
40  	 * {@inheritDoc}
41  	 */
42  	public Socket createTlsSocket() throws IOException {
43  		return mySocketFactory.createClientSocket();
44  	}
45  
46  	/**
47  	 * {@inheritDoc}
48  	 */
49  	public ServerSocket createServerSocket() throws IOException {
50  		return ServerSocketFactory.getDefault().createServerSocket();
51  	}
52  
53  	/**
54  	 * {@inheritDoc}
55  	 */
56  	public ServerSocket createTlsServerSocket() throws IOException {
57  		return mySocketFactory.createServerSocket();
58  	}
59  
60  }