RDF:Interfaces: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(introduce blank nodes as separate interface, use a node as subject in iterator, as suggested by Dave Beckett (Redland))
(→‎rdfITripleVisitor: adapt comments)
Line 64: Line 64:


== rdfITripleVisitor ==
== rdfITripleVisitor ==
/**
  * Interface used in RDF to enumerate triples.
  * Also used by rdfIDataSource::getAllSubjects, then aPredicate,
  * aObject and aTruthValue are ignored.
  *
  * @status PLASMA
  */


  interface rdfITripleVisitor : nsISupports
  interface rdfITripleVisitor : nsISupports
  {
  {
    /**
      * Callback function for returning query results.
      *
      * @param aSubject, aPredicate, aObject describe the (sub-)arc
      * @return Return Components.returnCode = NS_RDF_STOP_VISIT to
      * successfully stop iterating over the query result. Any
      * error code will stop the iteration as well.
      */
     void visit(in nsIRDFNode aSubject, in nsIRDFResource aPredicate,
     void visit(in nsIRDFNode aSubject, in nsIRDFResource aPredicate,
                 in nsIRDFNode aObject, in boolean aTruthValue);
                 in nsIRDFNode aObject, in boolean aTruthValue);

Revision as of 15:02, 15 June 2005

To prevent namespace conflicts with the existing interfaces, these new interfaces use the rdfI* prefix, instead of nsI* They use interCaps naming, so that there is no confusion in JS between the old and new interfaces. They also use the subject/predicate/object terminology contained in the RDF specification, instead of source/property/target.

The RDF node and service implementations are thread-safe. Each RDF datasource can define its own thread-safety model.

The enumeration methods are replaced almost entirely with visitors. A visitor uses synchronous callbacks to return results in a "snapshot" without expensive intermediate storage allocations.

Support for reading, enumerating, and manipulating rdf:_1/_2 arcs in an ordered way is added as an intrinsic part of a datasource. This has the potential to reduce codesize and increase performance dramatically throughout the tree.

rdfINode

The RDF implementations of these interfaces will support nsIClassInfo, so that JS will automatically flatten the interface. They will also support nsISecurityCheckedComponent (allowing all access, except for rdfIResourceInternal, which we may not need at all).

interface rdfINode : nsISupports
{
    boolean equals(rdfINode aOther);
    readonly unsigned long hashCode;
    /**
     * As a shortcut to QueryInterface, c++ may use these methods to obtain a weak pointer to the
     * resource or literal of this node.
     */
    [noscript, notxpcom] rdfIResource GetResource();
    [noscript, notxpcom] rdfILiteral  GetLiteral();
};

The noscript methods may be a premature optimization. The major drawback is that if we have noscript methods, COM can't proxy or remote this interface.

rdfIResource

Note: we are getting rid of resource factories, so nobody is allowed to implement RDF resources except the internal RDF service implementations.

interface rdfIResource : rdfINode
{
    readonly attribute AUTF8String value;
    readonly attribute boolean isAnonymous;
    /**
     * The numeric value of an RDF ordinal predicate (rdf:_1)
     * Throws NS_RDF_NO_VALUE if the resource is not an ordinal.
     */
    readonly attribute long ordinal;
};
/* This functionality was originally provided by resource factories, which
   are a security problem. However, I don't see why a hashtable mapping
   resources->whatever wouldn't be just as good. Can we just drop this 
   altogether?
   This will *not* be available from untrusted content. */
interface rdfIResourceInternal : rdfIResource
{
    getDelegate(in AUTF8String aKey, in nsIIDRef aIID,
                [iid_is(aIID),retval] out nsQIResult aResult);
    releaseDelegate(in AUTF8String aKey);
};

rdfIBlankNode

Blank nodes don't have URIs, but only a blank node identifier

interface rdfIResource : rdfINode
{
    readonly attribute AUTF8String identifier;
};

rdfITripleVisitor

/**
 * Interface used in RDF to enumerate triples.
 * Also used by rdfIDataSource::getAllSubjects, then aPredicate,
 * aObject and aTruthValue are ignored.
 *
 * @status PLASMA
 */
interface rdfITripleVisitor : nsISupports
{
    /**
     * Callback function for returning query results.
     *
     * @param aSubject, aPredicate, aObject describe the (sub-)arc
     * @return Return Components.returnCode = NS_RDF_STOP_VISIT to
     * successfully stop iterating over the query result. Any 
     * error code will stop the iteration as well.
     */
    void visit(in nsIRDFNode aSubject, in nsIRDFResource aPredicate,
               in nsIRDFNode aObject, in boolean aTruthValue);
};


RdfLiterals

rdfIDataSource

interface rdfIDataSource : nsISupports
{
    /**
     * Visit all the subject resources in the datasource. The order is
     * intederminate and may change from one invocation to the next.
     * The subjects will be in the aSubject argument in calls into
     * aVisitor, aPredicate and aObject will be null.
     * @note Implementations may throw NS_ERROR_NOT_IMPLEMENTED for
     * this method, but in this case RDF serializations of this
     * datasource will not be possible.
     */
    void visitAllSubjects(in rdfITripleVisitor aVisitor);
    /**
     * Visit all the triples in the datasource. The order is
     * intederminate and may change from one invocation to the next.
     * @note Implementations may throw NS_ERROR_NOT_IMPLEMENTED for
     * this method, but in this case RDF serializations of this
     * datasource will not be possible.
     */
    void visitAllTriples(in rdfITripleVisitor aVisitor);
};

RdfService

RdfLoadAndSave

RdfTripleVisitor