< prev index next >
src/share/classes/com/sun/jndi/dns/DnsContextFactory.java
Print this page
rev 1563 : 6969683: Generify ResolverConfiguration codes
Reviewed-by: alanb, chegar
@@ -133,21 +133,21 @@
if (urls.length == 0) {
throw new ConfigurationException("DNS pseudo-URL required");
}
- List servers = new ArrayList();
+ List<String> servers = new ArrayList<String>();
for (int i = 0; i < urls.length; i++) {
String server = urls[i].getHost();
int port = urls[i].getPort();
if (server == null && port < 0) {
// No server or port given, so look to underlying platform.
// ResolverConfiguration does some limited caching, so the
// following is reasonably efficient even if called rapid-fire.
- List platformServers = filterNameServers(
+ List<String> platformServers = filterNameServers(
ResolverConfiguration.open().nameservers(), false);
if (!platformServers.isEmpty()) {
servers.addAll(platformServers);
continue; // on to next URL (if any, which is unlikely)
}
@@ -158,12 +158,11 @@
}
servers.add((port < 0)
? server
: server + ":" + port);
}
- return (String[]) servers.toArray(
- new String[servers.size()]);
+ return servers.toArray(new String[servers.size()]);
}
/*
* Returns true if serversForUrls(urls) would make use of servers
* from the underlying platform.
@@ -222,39 +221,32 @@
* Removes any DNS server that's not permitted to access
* @param input the input server[:port] list, must not be null
* @param oneIsEnough return output once there exists one ok
* @return the filtered list, all non-permitted input removed
*/
- private static List filterNameServers(List input, boolean oneIsEnough) {
+ private static List<String> filterNameServers(List<String> input, boolean oneIsEnough) {
SecurityManager security = System.getSecurityManager();
if (security == null || input == null || input.isEmpty()) {
return input;
} else {
- List output = new ArrayList();
- for (Object o: input) {
- if (o instanceof String) {
- String platformServer = (String)o;
- int colon = platformServer.indexOf(':',
- platformServer.indexOf(']') + 1);
-
+ List<String> output = new ArrayList<String>();
+ for (String platformServer : input) {
+ int colon = platformServer.indexOf(':', platformServer.indexOf(']') + 1);
int p = (colon < 0)
? DEFAULT_PORT
- : Integer.parseInt(
- platformServer.substring(colon + 1));
+ : Integer.parseInt(platformServer.substring(colon + 1));
String s = (colon < 0)
- ? platformServer
- : platformServer.substring(0, colon);
+ ? platformServer : platformServer.substring(0, colon);
try {
security.checkConnect(s, p);
output.add(platformServer);
if (oneIsEnough) {
return output;
}
} catch (SecurityException se) {
continue;
}
}
- }
return output;
}
}
}
< prev index next >