if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFCompositeDataSourceCID, nsnull, kIRDFCompositeDataSourceIID, (void**) getter_AddRefs(db)))) {
rv = nsComponentManager::CreateInstance(kRDFCompositeDataSourceCID, nsnull, kIRDFCompositeDataSourceIID, getter_AddRefs(db));  if (NS_FAILED(rv)) {
RDFXULBuilderImpl::CreateBuilder(const nsCID& aBuilderCID, nsIContent* aElement,                                 const nsString& aDataSources){    nsresult rv;    // construct a new builder    nsCOMPtr<nsIRDFContentModelBuilder> builder;    if (NS_FAILED(rv = nsComponentManager::CreateInstance(aBuilderCID,                                                    nsnull,                                                    kIRDFContentModelBuilderIID,                                                    (void**) getter_AddRefs(builder)))) {        NS_ERROR("unable to create tree content model builder");        return rv;    }    if (NS_FAILED(rv = builder->SetRootContent(aElement))) {        NS_ERROR("unable to set builder's root content element");        return rv;    }    // create a database for the builder    nsCOMPtr<nsIRDFCompositeDataSource> db;    if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFCompositeDataSourceCID,                                                    nsnull,                                                    kIRDFCompositeDataSourceIID,                                                    (void**) getter_AddRefs(db)))) {        NS_ERROR("unable to construct new composite data source");        return rv;    }    // Add the local store as the first data source in the db.    {        nsCOMPtr<nsIRDFDataSource> localstore;        rv = gRDFService->GetDataSource("rdf:local-store", getter_AddRefs(localstore));        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get local store");        if (NS_FAILED(rv)) return rv;        rv = db->AddDataSource(localstore);        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add local store to db");        if (NS_FAILED(rv)) return rv;    }    // Parse datasources: they are assumed to be a whitespace    // separated list of URIs; e.g.,    //    //     rdf:bookmarks rdf:history http://foo.bar.com/blah.cgi?baz=9    //    PRInt32 first = 0;    while(1) {        while (first < aDataSources.Length() && nsString::IsSpace(aDataSources[first]))            ++first;        if (first >= aDataSources.Length())            break;        PRInt32 last = first;        while (last < aDataSources.Length() && !nsString::IsSpace(aDataSources[last]))            ++last;        nsAutoString uri;        aDataSources.Mid(uri, first, last - first);        first = last + 1;        nsCOMPtr<nsIRDFDataSource> ds;        // Some monkey business to convert the nsAutoString to a        // C-string safely. Sure'd be nice to have this be automagic.        {            char buf[256], *p = buf;            if (uri.Length() >= sizeof(buf))                p = new char[uri.Length() + 1];            uri.ToCString(p, uri.Length() + 1);            rv = gRDFService->GetDataSource(p, getter_AddRefs(ds));            if (p != buf)                delete[] p;        }        if (NS_FAILED(rv)) {            // This is only a warning because the data source may not            // be accessable for any number of reasons, including            // security, a bad URL, etc.            NS_WARNING("unable to load datasource");            continue;        }        if (NS_FAILED(rv = db->AddDataSource(ds))) {            NS_ERROR("unable to add datasource to composite data source");            return rv;        }    }    if (NS_FAILED(rv = builder->SetDataBase(db))) {        NS_ERROR("unable to set builder's database");        return rv;    }    // add it to the set of builders in use by the document    if (NS_FAILED(rv = mDocument->AddContentModelBuilder(builder))) {        NS_ERROR("unable to add builder to the document");        return rv;    }    return NS_OK;}