String host = url.getHost();
int port = url.getPort();
String path = url.getPath();
String conID = getConnectionID(host, port, username, password);
dbXMLClient dbClient = (dbXMLClient)clientCache.get(conID);
if ( dbClient == null ) {
String driver = props.getProperty(DRIVER, DEFAULT_DRIVER);
try {
dbClient = (dbXMLClient)Class.forName(driver).newInstance();
}
catch ( Exception e ) {
throw new XMLDBException(ErrorCodes.INVALID_DATABASE, "Driver '"+driver+"' could not be instantiated");
}
String connection = props.getProperty(CONNECTION);
if ( connection != null )
dbClient.setProperty(CONNECTION, connection);
if ( host != null && !host.equals(dbXML.DEFAULT_HOST) )
dbClient.setProperty(dbXMLClient.HOST, host);
if ( port != dbXML.DEFAULT_PORT )
dbClient.setProperty(dbXMLClient.PORT, Integer.toString(port));
if ( username != null )
dbClient.setProperty(dbXMLClient.USER, username);
if ( password != null )
dbClient.setProperty(dbXMLClient.PASS, password);
try {
dbClient.connect();
clientCache.put(conID, dbClient);
}
catch ( dbXMLException e ) {
throw new XMLDBException(ErrorCodes.NO_SUCH_DATABASE, e.getMessage());
}
}
try {
CollectionClient colClient = dbClient.getCollection(path);
if ( colClient != null )
return new CollectionImpl(colClient);
else
throw new XMLDBException(ErrorCodes.NO_SUCH_COLLECTION, "No such Collection at '"+uri+"'");
}