throws XMLDBException {
/* TODO: introduce authentication some day */
if (!acceptsURI(uri)) {
throw new XMLDBException(ErrorCodes.INVALID_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);
}
String collPath = uri.substring(firstSlash);
// The path must start with a /
if ( collPath.startsWith( "/" ) ) {
// 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 = "/";
}
try {
return new CollectionImpl(db, colName);
}
catch(XMLDBException e) {
if(e.errorCode == ErrorCodes.NO_SUCH_COLLECTION) {
// per getCollection contract, return null if not found
return null;
}
throw e;
}
}
else {
throw new XMLDBException(ErrorCodes.INVALID_URI,
"Collection name must begin with a '/'" );
}
}