mode = REMOTE; if ( user == null ) { user = "guest"; password = "guest"; } else if(password == null) password = "";  int p = 0; if ( ( p = c.indexOf( "/db", 2 ) ) > -1 ) { address = "http: c = c.substring( p ); } else throw new XMLDBException( ErrorCodes.INVALID_DATABASE, "malformed url: " + address ); if ( rpcClient == null ) try { rpcClient = new XmlRpcClient( address ); } catch ( MalformedURLException e ) { throw new XMLDBException( ErrorCodes.INVALID_DATABASE, "malformed url: " + address, e ); } rpcClient.setBasicAuthentication( user, password ); return readCollection( c, rpcClient, address );
return getRemoteCollection(user, password, address, c);
    public Collection getCollection( String collection, String user,                                     String password ) throws XMLDBException {        if ( !collection.startsWith( selector ) )            throw new XMLDBException( ErrorCodes.INVALID_DATABASE,                "collection " + collection +                " does not start with '" + selector + "'" );        String address = DEFAULT_HOST;        String c = collection.substring( selector.length() );        if(c.endsWith("/") && c.length() > 1)            c = c.substring(0, c.length() - 1);        Collection current = null;        if ( c.startsWith( "///" ) ) {        	mode = LOCAL;            // use local database instance            if ( !BrokerPool.isConfigured( dbName ) ) {                if ( autoCreate )                    configure();                else                    throw new XMLDBException( ErrorCodes.COLLECTION_CLOSED,                        "local database server not running" );            }            BrokerPool pool;            try {                pool = BrokerPool.getInstance( dbName );            } catch ( EXistException e ) {                throw new XMLDBException( ErrorCodes.VENDOR_ERROR,                    "db not correctly initialized",                    e );            }            User u = null;            if ( user == null ) {                user = "guest";                password = "guest";            }            if ( user != null ) {                u = pool.getSecurityManager().getUser( user );                if ( u == null ) {                	throw new XMLDBException( ErrorCodes.PERMISSION_DENIED,                        "user " + user + " does not exist" );                }                if ( !u.validate( password ) ) {                	throw new XMLDBException( ErrorCodes.PERMISSION_DENIED,                        "invalid password" );                }            }            try {                current = new LocalCollection( u, pool, c.substring( 2 ) );                return ( current != null )                     ? current : null;            } catch ( XMLDBException e ) {                switch ( e.errorCode ) {                    case ErrorCodes.NO_SUCH_RESOURCE:                    case ErrorCodes.NO_SUCH_COLLECTION:                    case ErrorCodes.INVALID_COLLECTION:                    case ErrorCodes.INVALID_RESOURCE:                        return null;                    default:                        throw e;                }            }        }        else if ( c.startsWith( "//" ) ) {            // use remote database via XML-RPC            mode = REMOTE;            if ( user == null ) {                user = "guest";                password = "guest";            } else if(password == null)                password = "";            // try to figure out server address            int p = 0;            if ( ( p = c.indexOf( "/db", 2 ) ) > -1 ) {                address = "http://" + c.substring( 2, p );                c = c.substring( p );            }            else                throw new XMLDBException( ErrorCodes.INVALID_DATABASE,                    "malformed url: " + address );            if ( rpcClient == null )                try {                    rpcClient = new XmlRpcClient( address );                } catch ( MalformedURLException e ) {                    throw new XMLDBException( ErrorCodes.INVALID_DATABASE,                        "malformed url: " + address,                        e );                }            rpcClient.setBasicAuthentication( user, password );            return readCollection( c, rpcClient, address );        }        else            throw new XMLDBException( ErrorCodes.INVALID_DATABASE,                "malformed url: " + address );    }