*/
public Collection getCollection(String uri, String userName, String password) throws XMLDBException {
/* TODO: introduce authentication some day */
if (!acceptsURI(uri)) {
throw new XMLDBException(ErrorCodes.INVALID_URI,
"Invalid URL: " + uri);
}
/* Chop off driver prefix, and '://' */
uri = uri.substring(getName().length() + 3);
/* Extract host name & port, if present */
int firstSlash = uri.indexOf('/');
if (firstSlash == -1) {
throw new XMLDBException(ErrorCodes.INVALID_URI,
"Invalid URL (must have '/'): " + uri);
}
/* Extract collection name */
String collPath = uri.substring(firstSlash);
if (!collPath.startsWith("/")) {
throw new XMLDBException(ErrorCodes.INVALID_URI,
"Invalid URL (collection name must start with '/'): " + uri);
}
// find the database name. We just skip the first slash
int colIndex = collPath.indexOf('/', 1);
// We assume there's no collection specified
String dbName = collPath.substring(1);
String colName = "/";
// if colIndex isn't -1 then we need to pick out the db and collection
if (colIndex != -1) {
dbName = collPath.substring(1, colIndex);
// The rest of the name locates the collection
colName = collPath.substring(colIndex);
if (colName.equals("")) {
colName = "/";
}
}
// TODO: Is this correct behavior?
if (!database.getName().equals(dbName)) {
throw new XMLDBException(ErrorCodes.NO_SUCH_DATABASE,
"Unknown database (must be '" + database.getName() + "'): " + uri);
}
try {
return new CollectionImpl(database, colName);