Bug 88287; add blocking style GetDataSource method so callers can ensure they use an already registered data source; r=sgehani, sr=waterson

This commit is contained in:
law%netscape.com 2001-12-06 03:44:42 +00:00
Родитель 75dabdbc63
Коммит 2881bb9951
2 изменённых файлов: 23 добавлений и 4 удалений

Просмотреть файл

@ -135,6 +135,11 @@ interface nsIRDFService : nsISupports {
// new data source. If construction is successful, the data source will
// be initialized via <tt>nsIRDFDataSource::Init()</tt>.
nsIRDFDataSource GetDataSource(in string aURI);
// Same as GetDataSource, but if a remote/XML data source needs to be
// constructed, then this method will issue a <b>blocking</b> Refresh
// call on that data source.
nsIRDFDataSource GetDataSourceBlocking(in string aURI);
};
%{C++

Просмотреть файл

@ -125,6 +125,7 @@ public:
// Implementation methods
nsresult RegisterLiteral(nsIRDFLiteral* aLiteral, PRBool aReplace = PR_FALSE);
nsresult UnregisterLiteral(nsIRDFLiteral* aLiteral);
nsresult GetDataSource(const char *aURI, PRBool aBlock, nsIRDFDataSource **aDataSource );
};
static RDFServiceImpl* gRDFService; // The one-and-only RDF service
@ -1153,6 +1154,22 @@ RDFServiceImpl::UnregisterDataSource(nsIRDFDataSource* aDataSource)
NS_IMETHODIMP
RDFServiceImpl::GetDataSource(const char* aURI, nsIRDFDataSource** aDataSource)
{
// Use the other GetDataSource and ask for a non-blocking Refresh.
// If you wanted it loaded synchronously, then you should've tried to do it
// yourself, or used GetDataSourceBlocking.
return GetDataSource( aURI, PR_FALSE, aDataSource );
}
NS_IMETHODIMP
RDFServiceImpl::GetDataSourceBlocking(const char* aURI, nsIRDFDataSource** aDataSource)
{
// Use GetDataSource and ask for a blocking Refresh.
return GetDataSource( aURI, PR_TRUE, aDataSource );
}
nsresult
RDFServiceImpl::GetDataSource(const char* aURI, PRBool aBlock, nsIRDFDataSource** aDataSource)
{
NS_PRECONDITION(aURI != nsnull, "null ptr");
if (! aURI)
@ -1213,9 +1230,6 @@ RDFServiceImpl::GetDataSource(const char* aURI, nsIRDFDataSource** aDataSource)
ds = do_CreateInstance(kRDFXMLDataSourceCID, &rv);
if (NS_FAILED(rv)) return rv;
// Start the datasource load asynchronously. If you wanted it
// loaded synchronously, then you should've tried to do it
// yourself.
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(ds));
NS_ASSERTION(remote, "not a remote RDF/XML data source!");
if (! remote) return NS_ERROR_UNEXPECTED;
@ -1223,7 +1237,7 @@ RDFServiceImpl::GetDataSource(const char* aURI, nsIRDFDataSource** aDataSource)
rv = remote->Init(aURI);
if (NS_FAILED(rv)) return rv;
rv = remote->Refresh(PR_FALSE);
rv = remote->Refresh(aBlock);
if (NS_FAILED(rv)) return rv;
}