01: package examples.tls;
02:
03: import javax.sip.address.*;
04: import java.util.*;
05:
06: public class HopImpl implements Hop {
07: /** Creates new Hop
08: *@param hop is a hop string in the form of host:port/Transport
09: *@throws IllegalArgument exception if string is not properly formatted or
10: * null.
11: */
12: private String host;
13: private int port;
14: private String transport;
15:
16: public String getHost() {
17: return this .host;
18: }
19:
20: public int getPort() {
21: return this .port;
22: }
23:
24: public String getTransport() {
25: return this .transport;
26: }
27:
28: public HopImpl(String hop) throws IllegalArgumentException {
29: if (hop == null)
30: throw new IllegalArgumentException("Null arg!");
31: System.out.println("hop = " + hop);
32: StringTokenizer stringTokenizer = new StringTokenizer(hop + "/");
33: String hostPort = stringTokenizer.nextToken("/");
34: transport = stringTokenizer.nextToken().trim();
35: // System.out.println("Hop: transport = " + transport);
36: if (transport == null)
37: transport = "UDP";
38: else if (transport == "")
39: transport = "UDP";
40: if (transport.compareToIgnoreCase("UDP") != 0
41: && transport.compareToIgnoreCase("TLS") != 0
42: && transport.compareToIgnoreCase("TCP") != 0) {
43: System.out.println("Bad transport string " + transport);
44: throw new IllegalArgumentException(hop);
45: }
46:
47: stringTokenizer = new StringTokenizer(hostPort + ":");
48: host = stringTokenizer.nextToken(":");
49: if (host == null || host.equals(""))
50: throw new IllegalArgumentException("no host!");
51: String portString = null;
52: try {
53: portString = stringTokenizer.nextToken(":");
54: } catch (NoSuchElementException ex) {
55: // Ignore.
56: }
57: if (portString == null || portString.equals("")) {
58: port = 5060;
59: } else {
60: try {
61: port = Integer.parseInt(portString);
62: } catch (NumberFormatException ex) {
63: throw new IllegalArgumentException("Bad port spec");
64: }
65: }
66: }
67:
68: }
|