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 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 | |
} |