}
public Connector createConnector() throws HgBadArgumentException {
Pair<ClassLoader, String> connectorToBe = connFactory.get(uri.getScheme());
if (connectorToBe == null || connectorToBe.second() == null) {
throw new HgBadArgumentException(String.format("Can't instantiate connector for scheme '%s'", uri.getScheme()), null);
}
try {
Class<?> connClass = connectorToBe.first().loadClass(connectorToBe.second());
if (!Connector.class.isAssignableFrom(connClass)) {
throw new HgBadArgumentException(String.format("Connector %s for scheme '%s' is not a subclass of %s", connectorToBe.second(), uri.getScheme(), Connector.class.getName()), null);
}
final Object connector = connClass.newInstance();
return Connector.class.cast(connector);
} catch (ClassNotFoundException ex) {
throw new HgBadArgumentException(String.format("Can't instantiate connector %s for scheme '%s'", connectorToBe.second(), uri.getScheme()), ex);
} catch (InstantiationException ex) {
throw new HgBadArgumentException(String.format("Can't instantiate connector %s for scheme '%s'", connectorToBe.second(), uri.getScheme()), ex);
} catch (IllegalAccessException ex) {
throw new HgBadArgumentException(String.format("Can't instantiate connector %s for scheme '%s'", connectorToBe.second(), uri.getScheme()), ex);
}
}