Coverage Report - ca.uhn.hl7v2.app.ConnectionData
 
Classes in this File Line Coverage Branch Coverage Complexity
ConnectionData
66%
48/72
50%
22/44
3.333
 
 1  
 /**
 2  
 The contents of this file are subject to the Mozilla Public License Version 1.1 
 3  
 (the "License"); you may not use this file except in compliance with the License. 
 4  
 You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
 5  
 Software distributed under the License is distributed on an "AS IS" basis, 
 6  
 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
 7  
 specific language governing rights and limitations under the License. 
 8  
 
 9  
 The Original Code is "Connection.java".  Description: 
 10  
 "A TCP/IP connection to a remote HL7 server." 
 11  
 
 12  
 The Initial Developer of the Original Code is University Health Network. Copyright (C) 
 13  
 2002.  All Rights Reserved. 
 14  
 
 15  
 Contributor(s): ______________________________________. 
 16  
 
 17  
 Alternatively, the contents of this file may be used under the terms of the 
 18  
 GNU General Public License (the  "GPL"), in which case the provisions of the GPL are 
 19  
 applicable instead of those above.  If you wish to allow use of your version of this 
 20  
 file only under the terms of the GPL and not to allow others to use your version 
 21  
 of this file under the MPL, indicate your decision by deleting  the provisions above 
 22  
 and replace  them with the notice and other provisions required by the GPL License.  
 23  
 If you do not delete the provisions above, a recipient may use your version of 
 24  
 this file under either the MPL or the GPL. 
 25  
  */
 26  
 package ca.uhn.hl7v2.app;
 27  
 
 28  
 import ca.uhn.hl7v2.llp.LowerLayerProtocol;
 29  
 import ca.uhn.hl7v2.parser.Parser;
 30  
 import ca.uhn.hl7v2.util.SocketFactory;
 31  
 import ca.uhn.hl7v2.util.StandardSocketFactory;
 32  
 
 33  
 /**
 34  
  * Connection meta data class.
 35  
  */
 36  
 class ConnectionData {
 37  
         private String host;
 38  
         private int port;
 39  
         private int port2;
 40  
         private boolean tls;
 41  
         private Parser parser;
 42  
         private LowerLayerProtocol protocol;
 43  
         private SocketFactory socketFactory;
 44  
 
 45  
         public ConnectionData(String host, int port, Parser parser, LowerLayerProtocol protocol) {
 46  0
                 this(host, port, parser, protocol, false);
 47  0
         }
 48  
 
 49  
         public ConnectionData(String host, int port, Parser parser, LowerLayerProtocol protocol,
 50  
                         boolean tls) {
 51  0
                 this(host, port, 0, parser, protocol, tls);
 52  0
         }
 53  
 
 54  
         public ConnectionData(String host, int outboundPort, int inboundPort, Parser parser,
 55  
                         LowerLayerProtocol protocol, boolean tls) {
 56  0
                 this(host, outboundPort, inboundPort, parser, protocol, tls, null);
 57  0
         }
 58  
 
 59  
         public ConnectionData(String host, int outboundPort, int inboundPort, Parser parser,
 60  259
                         LowerLayerProtocol protocol, boolean tls, SocketFactory socketFactory) {
 61  259
                 this.host = host;
 62  259
                 this.port = outboundPort;
 63  259
                 this.port2 = inboundPort;
 64  259
                 this.parser = parser;
 65  259
                 this.protocol = protocol;
 66  259
                 this.tls = tls;
 67  259
                 this.socketFactory = socketFactory;
 68  259
                 if (this.socketFactory == null) {
 69  2
                         this.socketFactory = new StandardSocketFactory();
 70  
                 }
 71  259
         }
 72  
 
 73  
         public String getHost() {
 74  870
                 return host;
 75  
         }
 76  
 
 77  
         public int getPort() {
 78  861
                 return port;
 79  
         }
 80  
 
 81  
         public int getPort2() {
 82  93
                 return port2;
 83  
         }
 84  
 
 85  
         public boolean isTls() {
 86  842
                 return tls;
 87  
         }
 88  
 
 89  
         public Parser getParser() {
 90  55
                 return parser;
 91  
         }
 92  
 
 93  
         public LowerLayerProtocol getProtocol() {
 94  55
                 return protocol;
 95  
         }
 96  
 
 97  
         public SocketFactory getSocketFactory() {
 98  65
                 return socketFactory;
 99  
         }
 100  
 
 101  
         public void setSocketFactory(SocketFactory theSocketFactory) {
 102  0
                 socketFactory = theSocketFactory;
 103  0
         }
 104  
 
 105  
         @Override
 106  
         public int hashCode() {
 107  1192
                 final int prime = 31;
 108  1192
                 int result = 1;
 109  1192
                 result = prime * result + ((host == null) ? 0 : host.hashCode());
 110  1192
                 result = prime * result + ((parser == null) ? 0 : parser.hashCode());
 111  1192
                 result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
 112  1192
                 result = prime * result + port;
 113  1192
                 result = prime * result + port2;
 114  1192
                 return result;
 115  
         }
 116  
 
 117  
         @Override
 118  
         public boolean equals(Object obj) {
 119  1021
                 if (this == obj)
 120  0
                         return true;
 121  1021
                 if (obj == null)
 122  0
                         return false;
 123  1021
                 if (getClass() != obj.getClass())
 124  0
                         return false;
 125  1021
                 ConnectionData other = (ConnectionData) obj;
 126  1021
                 if (host == null) {
 127  0
                         if (other.host != null)
 128  0
                                 return false;
 129  1021
                 } else if (!host.equals(other.host))
 130  0
                         return false;
 131  1021
                 if (parser == null) {
 132  0
                         if (other.parser != null)
 133  0
                                 return false;
 134  
                 } else {
 135  1021
                         if (other.parser == null)
 136  0
                                 return false;
 137  1021
                         else if (!parser.getClass().equals(other.parser.getClass()))
 138  0
                                 return false;
 139  
                 }
 140  1021
                 if (protocol == null) {
 141  0
                         if (other.protocol != null)
 142  0
                                 return false;
 143  
                 } else {
 144  1021
                         if (other.protocol == null)
 145  0
                                 return false;
 146  1021
                         else if (!protocol.getClass().equals(other.protocol.getClass()))
 147  0
                                 return false;
 148  
                 }
 149  1021
                 if (port != other.port)
 150  0
                         return false;
 151  1021
                 if (port2 != other.port2)
 152  0
                         return false;
 153  1021
                 return true;
 154  
         }
 155  
 
 156  
         @Override
 157  
         public String toString() {
 158  777
                 StringBuilder buf = new StringBuilder();
 159  777
                 buf.append(getHost()).append(":").append(getPort());
 160  777
                 if (port2 > 0)
 161  333
                         buf.append(",").append(port2);
 162  777
                 if (isTls())
 163  3
                         buf.append("(s)");
 164  777
                 return buf.toString();
 165  
         }
 166  
 
 167  
 }