Diff results When i used UnregisterDataSource method of nsIRDFService in C++ and JS!

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Diff results When i used UnregisterDataSource method of nsIRDFService in C++ and JS!

benkwan-2
i do these in js components:
var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].
                     getService(Components.interfaces.nsIRDFService);

   //file path with file:///
    var sFile = RSGetPath('/usercfg/','file') + fileName + '.rdf';

    var fileDS = rdfService.GetDataSourceBlocking(sFile);

    var sRoot = rdfService.GetResource(NSROOT + "root");
    var sModels = rdfService.GetResource("http://www.w3.org/1999/02/22-
rdf-syntax-ns#instanceOf");
    var target = fileDS.GetTarget(sRoot, sModels, true);

    if(null==target)
    {
        // generate RDF文件
        ProRDF(fileName);
        // Unregister RDFDataSource
        rdfService.UnregisterDataSource(fileDS);
        // reload
        fileDS = rdfService.GetDataSourceBlocking(sFile);
        target = fileDS.GetTarget(sRoot, sModels, true);
    }

    // If target is null, then we will know that fileDS may be is
empty or not exist.
    // And we should create the rdf first. Otherwise, we can use it
directly.
    if(null!=target)
    {
        //do sth!
    }

in c++ component:
nsresult rv;

        nsCOMPtr<nsIFile> profilePath ;
        rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,getter_AddRefs
(profilePath));
        profilePath->Append(NS_LITERAL_STRING("cerdfdatasource.rdf"));

        nsString rdfFilePath;
        rv = profilePath->GetPath(rdfFilePath);

        nsString preRdfFilePath = NS_LITERAL_STRING("file:\\\\\\");
        preRdfFilePath.Append(rdfFilePath.get());

        nsCString cRdfFilePath;

        NS_UTF16ToCString
(preRdfFilePath,NS_CSTRING_ENCODING_NATIVE_FILESYSTEM,cRdfFilePath);

        nsCOMPtr<nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/
rdf-service;1",&rv);

        nsCOMPtr<nsIRDFDataSource> rdfDataSource;
        rv = rdfService->GetDataSourceBlocking(cRdfFilePath.get
(),getter_AddRefs(rdfDataSource));

        nsCOMPtr<nsIRDFResource> sRoot ;
        nsCString rootString(NSROOTURI.get());
        rootString.AppendLiteral("root");
        rdfService->GetResource(rootString,getter_AddRefs(sRoot));

        nsCOMPtr<nsIRDFResource> sModel;
        rdfService->GetResource(NS_LITERAL_CSTRING("http://www.w3.org/
1999/02/22-rdf-syntax-ns#instanceOf"),getter_AddRefs(sModel));

        nsCOMPtr<nsIRDFNode> target;
        rv = rdfDataSource->GetTarget(sRoot,sModel,true,getter_AddRefs
(target));

        if(nsnull == target)
        //if(NS_FAILED(rv))
        {
                ProRDF();

                rv = rdfService->UnregisterDataSource(rdfDataSource);

                rv = rdfService->GetDataSourceBlocking(cRdfFilePath.get
(),getter_AddRefs(rdfDataSource));

                rv = rdfDataSource->GetTarget(sRoot,sModel,true,getter_AddRefs
(target));
        }
        else  if(nsnull != target) //if(NS_SUCCEEDED(rv))
        {
        }


the results are different.
if the cerdfdatasource.rdf file is not exist.in js code, first, the
target variable is null,after generate the file and reload
rdfdatasource,target is not null
but in c++ code,the target variable always is null,even after
cerdfdatasource.rdf is generate,and reload the rdfdatasource.and i
restart the app,it runs good! it seem that the rdfdatasource cache is
not refresh in C++!
what is wrong in my code?
_______________________________________________
dev-tech-rdf mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-rdf