RDF:DataSource

From MozillaWiki
Jump to: navigation, search

rdfIDataSource

For the moment, I am leaving off negative triples. Datasources are read-only. Modifications are handled by rdfIDataTarget. Datasources are *not* named: untrusted script can implement a datasource, and we can't trust the name it gives. All named-datasource handling is managed by the rdfILoader.

interface rdfIDataSource : nsISupports
{
    /**
     * Check if a triple exists.
     */
    boolean hasTriple(in rdfIResource aSubject,
                      in rdfIResource aPredicate,
                      in rdfIResource aObject);

    /**
     * Get the object of a subject->predicate arc.
     * If there is more than one arc, the object returned is undefined.
     * Returns a null object if the arc doesn't exist.
     * @note The not-exists behavior doesn't throw an exception, which is a change
     *       of behavior from nsIRDFDataSource.
     */
    rdfINode getObject(in rdfIResource aSubject,
                       in rdfIResource aPredicate);

    /**
     * Get all the objects from a particular subject->predicate arc.
     * The order is indeterminate and may change from one invocation to the next.
     */
    void getObjects(in rdfIResource      aSubject,
                    in rdfIResource      aPredicate,
                    in rdfITripleVisitor aVisitor);


    /**
     * Get the number of ordinal arcs from the subject.
     */
    long getOrdinalCount(in rdfIResource aSubject);

    /**
     * Visit the ordinal arcs from the subject.
     */
    void getOrdinals(in rdfIResource      aSubject,
                     in rdfITripleVisitor aVisitor);

    /**
     * Visit all the arcs from a subject. This includes ordinal arcs.
     * The order is indeterminate and may change from one invocation to the next.
     */
    void getTriplesOut(in rdfIResource      aSubject,
                       in rdfITripleVisitor aVisitor);

    /**
     * Get the subject of a predicate->object arc.
     * If there is more than one arc, the object returned is undefined.
     * Returns a null object if the arc doesn't exist.
     * @note The not-exists behavior doesn't throw an exception, which is a change
     *       of behavior from nsIRDFDataSource.
     * @note Implementations are not required to implement this method, and may throw
     *       NS_ERROR_NOT_IMPLEMENTED.
     */
    rdfIResource getSubject(in rdfINode     aObject,
                            in rdfIResource aPredicate);

    /**
     * Get all the subjects from a particular predicate->object arc.
     * The order is indeterminate and may change from one invocation to the next.
     * @note Implementations are not required to implement this method, and may throw
     *       NS_ERROR_NOT_IMPLEMENTED.
     */
    void getSubjects(in rdfIResource      aPredicate,
                     in rdfIResource      aObject,
                     in rdfITripleVisitor aVisitor);

    /**
     * Visit all the arcs to an object.
     * The order is indeterminate and may change from one invocation to the next.
     * @note Implementations are not required to implement this method, and may throw
     *       NS_ERROR_NOT_IMPLEMENTED.
     */
    void getTriplesIn(rdfIResource      aObject,
                      rdfITripleVisitor aVisitor);

    void addObserver(rdfIObserver aObserver);
    void removeObserver(rdfIObserver aObserver);

    /**
     * Visit all the subject resources in the document. The order is intederminate and may
     * change from one invocation to the next.
     * @note Implementations are not required to implement this method, and may throw
     *       NS_ERROR_NOT_IMPLEMENTED.
     */
    void getAllSubjects(in rdfITripleVisitor aVisitor);
};

rdfIDataTarget

Ordinal arcs should automatically update when lower ordinal arcs are removed. For example, if there is a resource with arcs out rdf:_1/_2/_3 and you unset _2, the _3 will automatically become _2.

interface rdfIDataTarget : rdfIDataSource
{
    void set(rdfIResource aSubject,
             rdfIResource aPredicate,
             rdfINode     aObject);

    void unset(rdfIResource aSubject,
               rdfIResource aPredicate,
               rdfINode     aObject);

    void reset(rdfIResource aSubject,
               rdfIResource aOldPredicate,
               rdfIResource aNewPredicate,
               rdfINode     aObject);

    void change(rdfIResource aSubject,
                rdfIResource aPredicate,
                rdfINode     aOldObject,
                rdfINode     aNewObject);

    void move(rdfIResource aOldSubject,
              rdfIResource aNewSubject,
              rdfIResource aPredicate,
              rdfINode     aObject);

    void beginUpdate();
    void endUpdate();
};

rdfICommandTarget

interface rdfICommandTarget : nsISupports
{
    readonly attribute nsISimpleEnumerator allCommands;

    boolean canDoCommand(nsISimpleEnumerator aSources,
                         rdfIResource        aCommand,
                         nsIArray            aArguments);

    void doCommand(nsISimpleEnumerator aSources,
                   rdfIResource        aCommand,
                   nsIArray            aArguments);
};

rdfICompositeDataSource

The composite data source implements nsIMutableArray, so that clients can insert and remove datasources in any order.

interface rdfICompositeDataSource : rdfIDataSource
{
    /**
     * When enumerating triples if two triples are exactly the same, don't enumerate both arcs.
     * @note The default value is "false". Setting this to "true" can negatively affect performance.
     */
    attribute boolean removeDuplicateTriples;

    /**
     * Allow later datasources to override matching triples in earlier datasources: i.e. DS1 has triple subjx->arc->"foo"
     * and DS2 has subjx->arc->"bar". If this attribute is false (the default) both triples will be reflected. If true,
     * only the "bar" arc will be reflected. Setting this to true may affect performance and old-style container aggregation.
     */
    attribute boolean allowOverride;
};