1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
35
36 class ConnectionData {
37 private final String host;
38 private final int port;
39 private final int port2;
40 private final boolean tls;
41 private final Parser parser;
42 private final LowerLayerProtocol protocol;
43 private SocketFactory socketFactory;
44 private final boolean lazy;
45
46 public ConnectionData(String host, int port, Parser parser, LowerLayerProtocol protocol) {
47 this(host, port, parser, protocol, false);
48 }
49
50 public ConnectionData(String host, int port, Parser parser, LowerLayerProtocol protocol,
51 boolean tls) {
52 this(host, port, 0, parser, protocol, tls);
53 }
54
55 public ConnectionData(String host, int outboundPort, int inboundPort, Parser parser,
56 LowerLayerProtocol protocol, boolean tls) {
57 this(host, outboundPort, inboundPort, parser, protocol, tls, null, false);
58 }
59
60 public ConnectionData(String host, int outboundPort, int inboundPort, Parser parser,
61 LowerLayerProtocol protocol, boolean tls, SocketFactory socketFactory, boolean lazy) {
62 this.host = host;
63 this.port = outboundPort;
64 this.port2 = inboundPort;
65 this.parser = parser;
66 this.protocol = protocol;
67 this.tls = tls;
68 this.socketFactory = socketFactory;
69 if (this.socketFactory == null) {
70 this.socketFactory = new StandardSocketFactory();
71 }
72 this.lazy = lazy;
73 }
74
75 public String getHost() {
76 return host;
77 }
78
79 public int getPort() {
80 return port;
81 }
82
83 public int getPort2() {
84 return port2;
85 }
86
87 public boolean isTls() {
88 return tls;
89 }
90
91 boolean isLazy() {
92 return lazy;
93 }
94
95 public Parser getParser() {
96 return parser;
97 }
98
99 public LowerLayerProtocol getProtocol() {
100 return protocol;
101 }
102
103 public SocketFactory getSocketFactory() {
104 return socketFactory;
105 }
106
107 public void setSocketFactory(SocketFactory theSocketFactory) {
108 socketFactory = theSocketFactory;
109 }
110
111 @Override
112 public int hashCode() {
113 final int prime = 31;
114 int result = 1;
115 result = prime * result + ((host == null) ? 0 : host.hashCode());
116 result = prime * result + ((parser == null) ? 0 : parser.hashCode());
117 result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
118 result = prime * result + port;
119 result = prime * result + port2;
120 return result;
121 }
122
123 @Override
124 public boolean equals(Object obj) {
125 if (this == obj)
126 return true;
127 if (obj == null)
128 return false;
129 if (getClass() != obj.getClass())
130 return false;
131 ConnectionData other = (ConnectionData) obj;
132 if (host == null) {
133 if (other.host != null)
134 return false;
135 } else if (!host.equals(other.host))
136 return false;
137 if (parser == null) {
138 if (other.parser != null)
139 return false;
140 } else {
141 if (other.parser == null)
142 return false;
143 else if (!parser.getClass().equals(other.parser.getClass()))
144 return false;
145 }
146 if (protocol == null) {
147 if (other.protocol != null)
148 return false;
149 } else {
150 if (other.protocol == null)
151 return false;
152 else if (!protocol.getClass().equals(other.protocol.getClass()))
153 return false;
154 }
155 if (port != other.port)
156 return false;
157 return port2 == other.port2;
158 }
159
160 @Override
161 public String toString() {
162 StringBuilder buf = new StringBuilder();
163 buf.append(getHost()).append(":").append(getPort());
164 if (port2 > 0)
165 buf.append(",").append(port2);
166 if (isTls())
167 buf.append("(s)");
168 return buf.toString();
169 }
170
171 }