Coverage Report - ca.uhn.hl7v2.protocol.impl.ClientSocketStreamSource
 
Classes in this File Line Coverage Branch Coverage Complexity
ClientSocketStreamSource
83%
10/12
N/A
1.5
 
 1  
 /*
 2  
  * Created on 19-Apr-2004
 3  
  */
 4  
 package ca.uhn.hl7v2.protocol.impl;
 5  
 
 6  
 import java.io.IOException;
 7  
 import java.net.Socket;
 8  
 import java.net.SocketAddress;
 9  
 
 10  
 import ca.uhn.hl7v2.protocol.TransportException;
 11  
 
 12  
 /**
 13  
  * A client-side <code>SocketStreamSource</code>.  
 14  
  * 
 15  
  * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
 16  
  * @version $Revision: 1.1 $ updated on $Date: 2007-02-19 02:24:26 $ by $Author: jamesagnew $
 17  
  */
 18  
 public class ClientSocketStreamSource extends SocketStreamSource {
 19  
 
 20  
     private SocketAddress myAddress;
 21  
     private Socket mySocket;
 22  
 
 23  
     /**
 24  
      * @param theAddress the address at which to connect sockets
 25  
      * @throws TransportException
 26  
      */
 27  15
     public ClientSocketStreamSource(SocketAddress theAddress) throws TransportException {
 28  15
         myAddress = theAddress;
 29  15
     }
 30  
 
 31  
     /** 
 32  
      * @see ca.uhn.hl7v2.protocol.impl.SocketStreamSource#getSocket()
 33  
      */
 34  
     public Socket getSocket() {
 35  145
         return mySocket;
 36  
     }
 37  
 
 38  
     /** 
 39  
      * Gets fresh instances of sockets.  
 40  
      */
 41  
     public void connect() throws TransportException {
 42  15
         mySocket = getSocket(myAddress);
 43  15
     }
 44  
 
 45  
     private Socket getSocket(SocketAddress theAddress) throws TransportException {
 46  15
         Socket s = new Socket();        
 47  
         try {
 48  15
             s.connect(theAddress);
 49  0
         } catch (IOException e) {
 50  0
             throw new TransportException(e);
 51  15
         }
 52  15
         return s;        
 53  
     }
 54  
 
 55  
 }