1 19 20 package org.netbeans.modules.proxy; 21 22 import java.net.InetSocketAddress ; 23 24 37 public class ConnectivitySettings { 38 41 public static final int CONNECTION_DIRECT = 0; 42 43 46 public static final int CONNECTION_VIA_SOCKS = 1; 47 48 51 public static final int CONNECTION_VIA_HTTPS = 2; 52 53 private static final int CONNECTION_TYPE_MIN = CONNECTION_DIRECT; 54 private static final int CONNECTION_TYPE_MAX = CONNECTION_VIA_HTTPS; 55 56 private int mConnectionType; 57 private String mProxyHost; 58 private int mProxyPort; 59 private String mProxyUsername; 60 private char[] mProxyPassword; 61 private int mKeepAliveIntervalSeconds; 62 63 public String toString() { 64 return "Type: " + mConnectionType + " Proxy: " + mProxyUsername + "@" + mProxyHost + ":" + mProxyPort; 65 } 66 67 70 public ConnectivitySettings() { 71 mConnectionType = CONNECTION_DIRECT; 72 mKeepAliveIntervalSeconds = 60; 73 } 74 75 89 public void setProxy(int type, String host, int port, String username, char[] proxyPassword) { 90 if (type < CONNECTION_TYPE_MIN || type > CONNECTION_TYPE_MAX) throw new IllegalArgumentException ("Illegal connection type"); 91 92 if (type != CONNECTION_DIRECT) { 93 if (port < 1 || port > 65535) throw new IllegalArgumentException ("Illegal proxy port number: " + port); 94 if (host == null || (host = host.trim()).length() == 0) throw new IllegalArgumentException ("A proxy host must be specified"); 95 } 96 97 mConnectionType = type; 98 mProxyHost = host; 99 mProxyPort = port; 100 mProxyUsername = username; 101 mProxyPassword = proxyPassword; 102 } 103 104 public int getKeepAliveIntervalSeconds() { 105 return mKeepAliveIntervalSeconds; 106 } 107 108 public void setKeepAliveIntervalSeconds(int keepAliveIntervalSeconds) { 109 mKeepAliveIntervalSeconds = keepAliveIntervalSeconds; 110 } 111 112 public int getConnectionType() { 113 return mConnectionType; 114 } 115 116 public void setConnectionType(int connectionType) { 117 mConnectionType = connectionType; 118 } 119 120 public String getProxyHost() { 121 return mProxyHost; 122 } 123 124 public void setProxyHost(String proxyHost) { 125 mProxyHost = proxyHost; 126 } 127 128 public int getProxyPort() { 129 return mProxyPort; 130 } 131 132 public void setProxyPort(int proxyPort) { 133 mProxyPort = proxyPort; 134 } 135 136 public String getProxyUsername() { 137 return mProxyUsername; 138 } 139 140 public void setProxyUsername(String proxyUsername) { 141 mProxyUsername = proxyUsername; 142 } 143 144 public char[] getProxyPassword() { 145 return mProxyPassword; 146 } 147 148 public void setProxyPassword(char[] proxyPassword) { 149 mProxyPassword = proxyPassword; 150 } 151 } 152 | Popular Tags |