![]() |
|
|
rdf: datasource howtoThis document is a cookbook that describes how to create a native, client-side datasource that works with Mozilla's RDF implementation. It supercedes (and borrows from) the original document put together by Robert Churchill.
What is a datasource?[write me!] Deciding on a vocabularyThe vocabulary is the set of properties that you will use to express relationships between elements (resources and literals) in your data model. The first question that you must answer is "should I use an existing vocabulary, or invent my own?" A reasonable answer is, "use an existing vocabulary unless you absolutely must invent your own." This will allow your datasource to be integrated with other datasources with a minimum of effort. There are several existing vocabularies of note, including:
Mapping your data to nodes and arcs[write me!] Implementing the nsIRDFDataSource interfaceYour first chore will be to implement the nsIRDFDataSource interface. There are basically two approaches that you can take in this endeavor:
[More info on what each method needs to do here] RDF Commands
Registering the datasource componentA datasource is an XPCOM component. As such, it must (currently, see [1]) have:
Constructing a DLL for a component is beyond the scope of this document; the reader is referred to the RDF factory as a guideline. Registering an RDF datasource is fairly simple: in the DLL's NSRegisterSelf() method, you simply call the component manager's RegisterComponent() method:
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(nsISupports* aServiceManager, const char* aPath)
{
nsresult rv;
...
// Assume compMgr refers to the component manager
rv = compMgr->RegisterComponent(kMyDataSourceCID,
"My Data Source",
NS_RDF_DATASOURCE_PROGID_PREFIX "my-datasource",
aPath, PR_TRUE, PR_TRUE);
...
}
Replace kMyDataSourceCID with your datasource's CLSID. Replace "My Data Source" with a descriptive string that should appear in the registry. Finally, replace "my-datasource" with a value appropriate for your datasource. This value, when prefixed with "rdf:", is a datasource identifier, and may be used with nsIRDFService::GetDataSource() to retrieve your datasource from the RDF service. For example, the above datasource would be accessable as follows:
nsIRDFService* rdf;
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &rdf);
if (NS_SUCCEEDED(rv)) {
nsIRDFDataSource* myDataSource;
rv = rdf->GetDataSource("rdf:my-datasource",
&myDataSource);
if (NS_SUCCEEDED(rv)) {
// ...do something to myDataSource here...
NS_RELEASE(myDataSource);
}
nsServiceManager::ReleaseService(kRDFServiceCID, rdf);
}
Displaying RDF as contentNow that you've gone through all this pain to expose your information as a datasource, you probably want to see it. Using XUL, you can display the contents of your datasource in a tree control, a menu, or a toolbar. The following XUL fragment illustrates how to instantiate a tree control whose body is "rooted" to a resource (http://foo.bar.com/) that your datasource describes:
<window
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:rdf="http://www.w3.org/TR/WD-rdf-syntax#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<tree datasources="rdf:my-datasource">
<treecol rdf:resource="http://home.netscape.com/NC-rdf#Name" />
<treecol rdf:resource="http://home.netscape.com/NC-rdf#URL" />
<treehead>
<treeitem>
<treecell>Name</treecell>
<treecell>URL</treecell>
</treeitem>
</treehead>
<treebody id="http://foo.bar.com/"
containment="http://www.foo.com/RDF#child" />
</tree>
</window>
The important "magic attributes" have been called out in bold, above:
[example here] 1. As of this writing, it is not currently possible to implement JavaScript XPCOM components; however, it may soon be possible to do so via XPConnect. Last Modified: $Id: datasource-howto.html,v 1.2 1999/04/13 19:06:18 waterson%netscape.com Exp $
|
|||||||
| Copyright © 1998 The Mozilla Organization. | ||||||||