/** *DissectNamingURLstringstoobtainreferencedhost,portand *objectname. * *@returnanobjectwhichcontainseachoftheabove *components. * *@throwsMalformedURLExceptionifgivenurlstringismalformed
*/ privatestatic ParsedNamingURL parseURL(String str) throws MalformedURLException
{ try { return intParseURL(str);
} catch (URISyntaxException ex) { /* With RFC 3986 URI handling, 'rmi://:<port>' and *'//:<port>' forms will result in a URI syntax exception *Converttheauthoritytoalocalhost:<port>form
*/
MalformedURLException mue = new MalformedURLException( "invalid URL String: " + str);
mue.initCause(ex); int indexSchemeEnd = str.indexOf(':'); int indexAuthorityBegin = str.indexOf("//:"); if (indexAuthorityBegin < 0) { throw mue;
} if ((indexAuthorityBegin == 0) ||
((indexSchemeEnd > 0) &&
(indexAuthorityBegin == indexSchemeEnd + 1))) { int indexHostBegin = indexAuthorityBegin + 2;
String newStr = str.substring(0, indexHostBegin) + "localhost" +
str.substring(indexHostBegin); try { return intParseURL(newStr);
} catch (URISyntaxException inte) { throw mue;
} catch (MalformedURLException inte) { throw inte;
}
} throw mue;
}
}
privatestatic ParsedNamingURL intParseURL(String str) throws MalformedURLException, URISyntaxException
{
URI uri = new URI(str); if (uri.isOpaque()) { thrownew MalformedURLException( "not a hierarchical URL: " + str);
} if (uri.getFragment() != null) { thrownew MalformedURLException( "invalid character, '#', in URL name: " + str);
} elseif (uri.getQuery() != null) { thrownew MalformedURLException( "invalid character, '?', in URL name: " + str);
} elseif (uri.getUserInfo() != null) { thrownew MalformedURLException( "invalid character, '@', in URL host: " + str);
}
String scheme = uri.getScheme(); if (scheme != null && !scheme.equals("rmi")) { thrownew MalformedURLException("invalid URL scheme: " + str);
}
String name = uri.getPath(); if (name != null) { if (name.startsWith("/")) {
name = name.substring(1);
} if (name.length() == 0) {
name = null;
}
}
String host = uri.getHost(); if (host == null) {
host = ""; try { /* *With2396URIhandling,formssuchas'rmi://host:bar' *or'rmi://:<port>' are parsed into a registry based *authority.Weonlywanttoallowserverbasednaming *authorities.
*/
uri.parseServerAuthority();
} catch (URISyntaxException use) { // Check if the authority is of form ':<port>'
String authority = uri.getAuthority(); if (authority != null && authority.startsWith(":")) { // Convert the authority to 'localhost:<port>' form
authority = "localhost" + authority; try {
uri = new URI(null, authority, null, null, null); // Make sure it now parses to a valid server based // naming authority
uri.parseServerAuthority();
} catch (URISyntaxException use2) { thrownew
MalformedURLException("invalid authority: " + str);
}
} else { thrownew
MalformedURLException("invalid authority: " + str);
}
}
} int port = uri.getPort(); if (port == -1) {
port = Registry.REGISTRY_PORT;
} returnnew ParsedNamingURL(host, port, name);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.