Mercurial > 510Connectbot
comparison src/com/five_ten_sg/connectbot/transport/TransportFactory.java @ 11:f3b3bbd227b8 tn5250
adding tn5250 files
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 22 May 2014 18:26:27 -0700 |
parents | 0ce5cc452d02 |
children | b39bcf616a6f |
comparison
equal
deleted
inserted
replaced
10:e773d0952613 | 11:f3b3bbd227b8 |
---|---|
34 public class TransportFactory { | 34 public class TransportFactory { |
35 private static final String TAG = "ConnectBot.TransportFactory"; | 35 private static final String TAG = "ConnectBot.TransportFactory"; |
36 | 36 |
37 private static String[] transportNames = { | 37 private static String[] transportNames = { |
38 SSH.getProtocolName(), | 38 SSH.getProtocolName(), |
39 TN5250.getProtocolName(), | |
39 Telnet.getProtocolName(), | 40 Telnet.getProtocolName(), |
40 Local.getProtocolName(), | 41 Local.getProtocolName(), |
41 }; | 42 }; |
42 | 43 |
43 /** | 44 /** |
45 * @return | 46 * @return |
46 */ | 47 */ |
47 public static AbsTransport getTransport(String protocol) { | 48 public static AbsTransport getTransport(String protocol) { |
48 if (SSH.getProtocolName().equals(protocol)) { | 49 if (SSH.getProtocolName().equals(protocol)) { |
49 return new SSH(); | 50 return new SSH(); |
51 } | |
52 else if (TN5250.getProtocolName().equals(protocol)) { | |
53 return new TN5250(); | |
50 } | 54 } |
51 else if (Telnet.getProtocolName().equals(protocol)) { | 55 else if (Telnet.getProtocolName().equals(protocol)) { |
52 return new Telnet(); | 56 return new Telnet(); |
53 } | 57 } |
54 else if (Local.getProtocolName().equals(protocol)) { | 58 else if (Local.getProtocolName().equals(protocol)) { |
61 | 65 |
62 public static Uri getUri(String scheme, String input) { | 66 public static Uri getUri(String scheme, String input) { |
63 Log.d("TransportFactory", String.format( | 67 Log.d("TransportFactory", String.format( |
64 "Attempting to discover URI for scheme=%s on input=%s", scheme, | 68 "Attempting to discover URI for scheme=%s on input=%s", scheme, |
65 input)); | 69 input)); |
66 | 70 AbsTransport t = getTransport(protocol); |
67 if (SSH.getProtocolName().equals(scheme)) | 71 if (t == null) return null; |
68 return SSH.getUri(input); | 72 return t.getUri(input); |
69 else if (Telnet.getProtocolName().equals(scheme)) | |
70 return Telnet.getUri(input); | |
71 else if (Local.getProtocolName().equals(scheme)) { | |
72 Log.d("TransportFactory", "Got to the local parsing area"); | |
73 return Local.getUri(input); | |
74 } | |
75 else | |
76 return null; | |
77 } | 73 } |
78 | 74 |
79 public static String[] getTransportNames() { | 75 public static String[] getTransportNames() { |
80 return transportNames; | 76 return transportNames; |
81 } | 77 } |
86 | 82 |
87 return a.getClass().equals(b.getClass()); | 83 return a.getClass().equals(b.getClass()); |
88 } | 84 } |
89 | 85 |
90 public static boolean canForwardPorts(String protocol) { | 86 public static boolean canForwardPorts(String protocol) { |
91 // TODO uh, make this have less knowledge about its children | 87 AbsTransport t = getTransport(protocol); |
92 if (SSH.getProtocolName().equals(protocol)) { | 88 if (t == null) return false; |
93 return true; | 89 return t.canForwardPorts(); |
94 } | |
95 else { | |
96 return false; | |
97 } | |
98 } | 90 } |
99 | 91 |
100 /** | 92 /** |
101 * @param protocol text name of protocol | 93 * @param protocol text name of protocol |
102 * @param context | 94 * @param context |
103 * @return expanded format hint | 95 * @return expanded format hint |
104 */ | 96 */ |
105 public static String getFormatHint(String protocol, Context context) { | 97 public static String getFormatHint(String protocol, Context context) { |
106 if (SSH.getProtocolName().equals(protocol)) { | 98 AbsTransport t = getTransport(protocol); |
107 return SSH.getFormatHint(context); | 99 if (t == null) return "???"; |
108 } | 100 return t.getFormatHint(context); |
109 else if (Telnet.getProtocolName().equals(protocol)) { | |
110 return Telnet.getFormatHint(context); | |
111 } | |
112 else if (Local.getProtocolName().equals(protocol)) { | |
113 return Local.getFormatHint(context); | |
114 } | |
115 else { | |
116 return AbsTransport.getFormatHint(context); | |
117 } | |
118 } | 101 } |
119 | 102 |
120 /** | 103 /** |
121 * @param hostdb Handle to HostDatabase | 104 * @param hostdb Handle to HostDatabase |
122 * @param uri URI to target server | 105 * @param uri URI to target server |