Hi everybody,

I'm trying to aggregate a RDF in-memory datasource inside a javascript
XPCOM, the same way this article do it with C++:
http://developer.mozilla.org/en/docs/Aggregating_the_In-Memory_Datasource
I took nsSample.js as a based work on my component, and just adds what
is needed to delegate relevant interfaces to the in-memory-datasource.
The component code is below.

In my application, I create an instance of my component like this:
var myComponent = Components.classes['@mozilla.org/rdf/datasource;1?
name=test']
                                       
.createInstance(Components.interfaces.nsIRDFDataSource);
I've got a SegFault.

With that:
var myComponent = Components.classes['@mozilla.org/rdf/datasource;1?
name=test']
                                       
.createInstance(Components.interfaces.nsISupports);
That's fine, but when i then QI nsIRDFDataSource:
myComponent =
myComponent.QueryInterface(Components.interfaces.nsIRDFDataSource);
i've got a NS_NOINTERFACE exception.


Is there sombody that can explain me what's wrong ?
The harder part of my work was to find the relevant parameter for
Components.manager.createInstance().

Thank you in advance for your help



Components code (the factory is the same than the nsSample.js one):

var inMemDsCID =
Components.ID("{BFD0526D-834C-11d2-8EAC-00805F29F370}");

function mySample() { /* big comment for no code, eh? */ }

/* decorate prototype to provide ``class'' methods and property
accessors */
mySample.prototype = {

        datasource : null,

    QueryInterface: function (iid) {
                Console.logStringMessage("QueryInterface is beeing called:" +
Components.interfacesByID[iid]);

                if(iid.equals(Components.interfaces.nsIRDFDataSource) ||
                   iid.equals(Components.interfaces.nsIRDFInMemoryDataSource) ||
                   
iid.equals(Components.interfaces.nsIRDFPropagatableDataSource) ||
                   iid.equals(Components.interfaces.nsIRDFPurgeableDataSource))
                {
                   Console.logStringMessage("QueryInterface will return 
delegate");
                   if(!this.datasource)
                   {
                                try
                                {
                                        this.datasource = 
Components.manager.createInstance(inMemDsCID,
this, Components.interfaces.nsISupports);
                                }
                                catch(e)
                                {
                                        Console.logStringMessage("Unable to 
create datasource:" + e);
                                }
                        }

                        Console.logStringMessage("Going to return delegate:" +
this.datasource);

                        try
                        {
                                var ds = this.datasource.QueryInterface(iid);
                        }
                        catch(e)
                        {
                                Console.logStringMessage("Unable to cast 
delegate to iid:" +
Components.interfacesByID[iid]);
                        }

                        if(ds)
                                return ds;
                        else
                                Console.logStringMessage("There is no ds 
delegate to return:" +
this.datasource );
        }

                Console.logStringMessage("QueryInterface will return object");
                if (iid.equals(Components.interfaces.nsISupports))
            return this;

        Components.returnCode =
Components.results.NS_ERROR_NO_INTERFACE;
        return null;
    }
}

_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to