Coverage Report - ca.uhn.hl7v2.app.ConnectionData
 
Classes in this File Line Coverage Branch Coverage Complexity
ConnectionData
67%
50/74
50%
22/44
3.188
 
 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  
     private boolean lazy;
 45  
 
 46  
         public ConnectionData(String host, int port, Parser parser, LowerLayerProtocol protocol) {
 47  0
                 this(host, port, parser, protocol, false);
 48  0
         }
 49  
 
 50  
         public ConnectionData(String host, int port, Parser parser, LowerLayerProtocol protocol,
 51  
                         boolean tls) {
 52  0
                 this(host, port, 0, parser, protocol, tls);
 53  0
         }
 54  
 
 55  
         public ConnectionData(String host, int outboundPort, int inboundPort, Parser parser,
 56  
                         LowerLayerProtocol protocol, boolean tls) {
 57  0
                 this(host, outboundPort, inboundPort, parser, protocol, tls, null, false);
 58  0
         }
 59  
 
 60  
         public ConnectionData(String host, int outboundPort, int inboundPort, Parser parser,
 61  1340
                         LowerLayerProtocol protocol, boolean tls, SocketFactory socketFactory, boolean lazy) {
 62  1340
                 this.host = host;
 63  1340
                 this.port = outboundPort;
 64  1340
                 this.port2 = inboundPort;
 65  1340
                 this.parser = parser;
 66  1340
                 this.protocol = protocol;
 67  1340
                 this.tls = tls;
 68  1340
                 this.socketFactory = socketFactory;
 69  1340
                 if (this.socketFactory == null) {
 70  10
                         this.socketFactory = new StandardSocketFactory();
 71  
                 }
 72  1340
         this.lazy = lazy;
 73  1340
         }
 74  
 
 75  
         public String getHost() {
 76  4520
                 return host;
 77  
         }
 78  
 
 79  
         public int getPort() {
 80  4475
                 return port;
 81  
         }
 82  
 
 83  
         public int getPort2() {
 84  500
                 return port2;
 85  
         }
 86  
 
 87  
         public boolean isTls() {
 88  4380
                 return tls;
 89  
         }
 90  
 
 91  
     boolean isLazy() {
 92  315
         return lazy;
 93  
     }
 94  
 
 95  
     public Parser getParser() {
 96  310
                 return parser;
 97  
         }
 98  
 
 99  
         public LowerLayerProtocol getProtocol() {
 100  310
                 return protocol;
 101  
         }
 102  
 
 103  
         public SocketFactory getSocketFactory() {
 104  360
                 return socketFactory;
 105  
         }
 106  
 
 107  
         public void setSocketFactory(SocketFactory theSocketFactory) {
 108  0
                 socketFactory = theSocketFactory;
 109  0
         }
 110  
 
 111  
         @Override
 112  
         public int hashCode() {
 113  6130
                 final int prime = 31;
 114  6130
                 int result = 1;
 115  6130
                 result = prime * result + ((host == null) ? 0 : host.hashCode());
 116  6130
                 result = prime * result + ((parser == null) ? 0 : parser.hashCode());
 117  6130
                 result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
 118  6130
                 result = prime * result + port;
 119  6130
                 result = prime * result + port2;
 120  6130
                 return result;
 121  
         }
 122  
 
 123  
         @Override
 124  
         public boolean equals(Object obj) {
 125  5165
                 if (this == obj)
 126  0
                         return true;
 127  5165
                 if (obj == null)
 128  0
                         return false;
 129  5165
                 if (getClass() != obj.getClass())
 130  0
                         return false;
 131  5165
                 ConnectionData other = (ConnectionData) obj;
 132  5165
                 if (host == null) {
 133  0
                         if (other.host != null)
 134  0
                                 return false;
 135  5165
                 } else if (!host.equals(other.host))
 136  0
                         return false;
 137  5165
                 if (parser == null) {
 138  0
                         if (other.parser != null)
 139  0
                                 return false;
 140  
                 } else {
 141  5165
                         if (other.parser == null)
 142  0
                                 return false;
 143  5165
                         else if (!parser.getClass().equals(other.parser.getClass()))
 144  0
                                 return false;
 145  
                 }
 146  5165
                 if (protocol == null) {
 147  0
                         if (other.protocol != null)
 148  0
                                 return false;
 149  
                 } else {
 150  5165
                         if (other.protocol == null)
 151  0
                                 return false;
 152  5165
                         else if (!protocol.getClass().equals(other.protocol.getClass()))
 153  0
                                 return false;
 154  
                 }
 155  5165
                 if (port != other.port)
 156  0
                         return false;
 157  5165
                 if (port2 != other.port2)
 158  0
                         return false;
 159  5165
                 return true;
 160  
         }
 161  
 
 162  
         @Override
 163  
         public String toString() {
 164  4020
                 StringBuilder buf = new StringBuilder();
 165  4020
                 buf.append(getHost()).append(":").append(getPort());
 166  4020
                 if (port2 > 0)
 167  1665
                         buf.append(",").append(port2);
 168  4020
                 if (isTls())
 169  15
                         buf.append("(s)");
 170  4020
                 return buf.toString();
 171  
         }
 172  
 
 173  
 }