Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Protected Attributes
nsRDFPropertyTestNode Class Reference

#include <nsRDFPropertyTestNode.h>

Inheritance diagram for nsRDFPropertyTestNode:
Inheritance graph
[legend]
Collaboration diagram for nsRDFPropertyTestNode:
Collaboration graph
[legend]

List of all members.

Classes

class  Element

Public Member Functions

 nsRDFPropertyTestNode (InnerNode *aParent, nsConflictSet &aConflictSet, nsIRDFDataSource *aDataSource, PRInt32 aSourceVariable, nsIRDFResource *aProperty, PRInt32 aTargetVariable)
 Both source and target unbound (?source ^property ?target)
 nsRDFPropertyTestNode (InnerNode *aParent, nsConflictSet &aConflictSet, nsIRDFDataSource *aDataSource, nsIRDFResource *aSource, nsIRDFResource *aProperty, PRInt32 aTargetVariable)
 Source bound, target unbound (source ^property ?target)
 nsRDFPropertyTestNode (InnerNode *aParent, nsConflictSet &aConflictSet, nsIRDFDataSource *aDataSource, PRInt32 aSourceVariable, nsIRDFResource *aProperty, nsIRDFNode *aTarget)
 Source unbound, target bound (?source ^property target)
virtual nsresult FilterInstantiations (InstantiationSet &aInstantiations, void *aClosure) const
 Given a set of instantiations, filter out any that are inconsistent with the test node's test, and append variable-to-value assignments and memory element support for those which do pass the test node's test.
virtual nsresult GetAncestorVariables (VariableSet &aVariables) const
 Retrieve the set of variables that are introduced by this node and any of its ancestors.
virtual PRBool CanPropagate (nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, Instantiation &aInitialBindings) const
 Determine wether the node can propagate an assertion with the specified source, property, and target.
virtual void Retract (nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, nsTemplateMatchSet &aFirings, nsTemplateMatchSet &aRetractions) const
 
  

InnerNodeGetParent () const
 Retrieve the test node's parent.
virtual nsresult Propagate (const InstantiationSet &aInstantiations, void *aClosure)
 Calls FilterInstantiations() on the instantiation set, and if the resulting set isn't empty, propagates the new set down to each of the test node's children.
virtual nsresult Constrain (InstantiationSet &aInstantiations, void *aClosure)
 Calls FilterInstantiations() on the instantiation set, and if the resulting set isn't empty, propagates the new set up to the test node's parent.
virtual PRBool HasAncestor (const ReteNode *aNode) const
 Determine if this node has another node as its direct ancestor.
nsresult AddChild (ReteNode *aNode)
 Add another node as a child of this node.
nsresult RemoveAllChildren ()
 Remove all the children of this node.

Protected Attributes

nsConflictSetmConflictSet
nsCOMPtr< nsIRDFDataSourcemDataSource
PRInt32 mSourceVariable
nsCOMPtr< nsIRDFResourcemSource
nsCOMPtr< nsIRDFResourcemProperty
PRInt32 mTargetVariable
nsCOMPtr< nsIRDFNodemTarget
InnerNodemParent
ReteNodeSet mKids

Detailed Description

Definition at line 49 of file nsRDFPropertyTestNode.h.


Constructor & Destructor Documentation

nsRDFPropertyTestNode::nsRDFPropertyTestNode ( InnerNode aParent,
nsConflictSet aConflictSet,
nsIRDFDataSource aDataSource,
PRInt32  aSourceVariable,
nsIRDFResource aProperty,
PRInt32  aTargetVariable 
)

Both source and target unbound (?source ^property ?target)

Definition at line 50 of file nsRDFPropertyTestNode.cpp.

    : nsRDFTestNode(aParent),
      mConflictSet(aConflictSet),
      mDataSource(aDataSource),
      mSourceVariable(aSourceVariable),
      mSource(nsnull),
      mProperty(aProperty),
      mTargetVariable(aTargetVariable),
      mTarget(nsnull)
{
#ifdef PR_LOGGING
    if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) {
        const char* prop = "(null)";
        if (aProperty)
            aProperty->GetValueConst(&prop);

        PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
               ("nsRDFPropertyTestNode[%p]: parent=%p source=%d property=%s target=%d",
                this, aParent, aSourceVariable, prop, aTargetVariable));
    }
#endif
}

Here is the call graph for this function:

nsRDFPropertyTestNode::nsRDFPropertyTestNode ( InnerNode aParent,
nsConflictSet aConflictSet,
nsIRDFDataSource aDataSource,
nsIRDFResource aSource,
nsIRDFResource aProperty,
PRInt32  aTargetVariable 
)

Source bound, target unbound (source ^property ?target)

Definition at line 79 of file nsRDFPropertyTestNode.cpp.

    : nsRDFTestNode(aParent),
      mConflictSet(aConflictSet),
      mDataSource(aDataSource),
      mSourceVariable(0),
      mSource(aSource),
      mProperty(aProperty),
      mTargetVariable(aTargetVariable),
      mTarget(nsnull)
{
#ifdef PR_LOGGING
    if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) {
        const char* source = "(null)";
        if (aSource)
            aSource->GetValueConst(&source);

        const char* prop = "(null)";
        if (aProperty)
            aProperty->GetValueConst(&prop);

        PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
               ("nsRDFPropertyTestNode[%p]: parent=%p source=%s property=%s target=%d",
                this, source, prop, aTargetVariable));
    }
#endif
}

Here is the call graph for this function:

nsRDFPropertyTestNode::nsRDFPropertyTestNode ( InnerNode aParent,
nsConflictSet aConflictSet,
nsIRDFDataSource aDataSource,
PRInt32  aSourceVariable,
nsIRDFResource aProperty,
nsIRDFNode aTarget 
)

Source unbound, target bound (?source ^property target)

Definition at line 112 of file nsRDFPropertyTestNode.cpp.

    : nsRDFTestNode(aParent),
      mConflictSet(aConflictSet),
      mDataSource(aDataSource),
      mSourceVariable(aSourceVariable),
      mSource(nsnull),
      mProperty(aProperty),
      mTargetVariable(0),
      mTarget(aTarget)
{
#ifdef PR_LOGGING
    if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) {
        const char* prop = "(null)";
        if (aProperty)
            aProperty->GetValueConst(&prop);

        nsAutoString target;
        nsXULContentUtils::GetTextForNode(aTarget, target);

        PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
               ("nsRDFPropertyTestNode[%p]: parent=%p source=%s property=%s target=%d",
                this, aSourceVariable, prop, NS_ConvertUCS2toUTF8(target).get()));
    }
#endif
}

Here is the call graph for this function:


Member Function Documentation

nsresult InnerNode::AddChild ( ReteNode aNode) [inline, inherited]

Add another node as a child of this node.

Parameters:
aNodethe node to add.
Returns:
NS_OK if no errors occur.

Definition at line 973 of file nsRuleNetwork.h.

{ return mKids.Add(aNode); }

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsRDFPropertyTestNode::CanPropagate ( nsIRDFResource aSource,
nsIRDFResource aProperty,
nsIRDFNode aTarget,
Instantiation aInitialBindings 
) const [virtual]

Determine wether the node can propagate an assertion with the specified source, property, and target.

If the assertion can be propagated, aInitialBindings will be initialized with appropriate variable-to-value assignments to allow the rule network to start a constrain and propagate search from this node in the network.

Returns:
PR_TRUE if the node can propagate the specified assertion.

Implements nsRDFTestNode.

Definition at line 353 of file nsRDFPropertyTestNode.cpp.

{
    PRBool result;

    if ((mProperty.get() != aProperty) ||
        (mSource && mSource.get() != aSource) ||
        (mTarget && mTarget.get() != aTarget)) {
        result = PR_FALSE;
    }
    else {
        if (mSourceVariable)
            aInitialBindings.AddAssignment(mSourceVariable, Value(aSource));

        if (mTargetVariable)
            aInitialBindings.AddAssignment(mTargetVariable, Value(aTarget));

        result = PR_TRUE;
    }

#ifdef PR_LOGGING
    if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) {
        const char* source;
        aSource->GetValueConst(&source);

        const char* property;
        aProperty->GetValueConst(&property);

        nsAutoString target;
        nsXULContentUtils::GetTextForNode(aTarget, target);

        PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
               ("nsRDFPropertyTestNode[%p]: CanPropagate([%s]==[%s]=>[%s]) => %s",
                this, source, property, NS_ConvertUCS2toUTF8(target).get(),
                result ? "true" : "false"));
    }
#endif

    return result;
}

Here is the call graph for this function:

nsresult TestNode::Constrain ( InstantiationSet aInstantiations,
void aClosure 
) [virtual, inherited]

Calls FilterInstantiations() on the instantiation set, and if the resulting set isn't empty, propagates the new set up to the test node's parent.

Implements InnerNode.

Definition at line 1065 of file nsRuleNetwork.cpp.

{
    nsresult rv;

    PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
           ("TestNode[%p]: Constrain() begin", this));

    rv = FilterInstantiations(aInstantiations, aClosure);
    if (NS_FAILED(rv)) return rv;

    if (! aInstantiations.Empty()) {
        // if we still have instantiations, then ride 'em on up to the
        // parent to narrow them.

        PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
               ("TestNode[%p]: Constrain() passing to parent %p", this, mParent));

        rv = mParent->Constrain(aInstantiations, aClosure);
    }
    else {
        PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
               ("TestNode[%p]: Constrain() failed", this));

        rv = NS_OK;
    }

    PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
           ("TestNode[%p]: Constrain() end", this));

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsRDFPropertyTestNode::FilterInstantiations ( InstantiationSet aInstantiations,
void aClosure 
) const [virtual]

Given a set of instantiations, filter out any that are inconsistent with the test node's test, and append variable-to-value assignments and memory element support for those which do pass the test node's test.

Parameters:
aInstantiationsthe set of instantiations to be filtered
aClosureapplication-specific data that is to be passed through the network.
Returns:
NS_OK if no errors occurred.

Implements TestNode.

Definition at line 145 of file nsRDFPropertyTestNode.cpp.

{
    nsresult rv;

    InstantiationSet::Iterator last = aInstantiations.Last();
    for (InstantiationSet::Iterator inst = aInstantiations.First(); inst != last; ++inst) {
        PRBool hasSourceBinding;
        Value sourceValue;

        if (mSource) {
            hasSourceBinding = PR_TRUE;
            sourceValue = mSource;
        }
        else {
            hasSourceBinding = inst->mAssignments.GetAssignmentFor(mSourceVariable, &sourceValue);
        }

        PRBool hasTargetBinding;
        Value targetValue;

        if (mTarget) {
            hasTargetBinding = PR_TRUE;
            targetValue = mTarget;
        }
        else {
            hasTargetBinding = inst->mAssignments.GetAssignmentFor(mTargetVariable, &targetValue);
        }

#ifdef PR_LOGGING
        if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) {
            const char* source = "(unbound)";
            if (hasSourceBinding)
                VALUE_TO_IRDFRESOURCE(sourceValue)->GetValueConst(&source);

            nsAutoString target(NS_LITERAL_STRING("(unbound)"));
            if (hasTargetBinding)
                nsXULContentUtils::GetTextForNode(VALUE_TO_IRDFNODE(targetValue), target);

            PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
                   ("nsRDFPropertyTestNode[%p]: FilterInstantiations() source=[%s] target=[%s]",
                    this, source, NS_ConvertUCS2toUTF8(target).get()));
        }
#endif

        if (hasSourceBinding && hasTargetBinding) {
            // it's a consistency check. see if we have a assignment that is consistent
            PRBool hasAssertion;
            rv = mDataSource->HasAssertion(VALUE_TO_IRDFRESOURCE(sourceValue),
                                           mProperty,
                                           VALUE_TO_IRDFNODE(targetValue),
                                           PR_TRUE,
                                           &hasAssertion);
            if (NS_FAILED(rv)) return rv;

#ifdef PR_LOGGING
            PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
                   ("    consistency check => %s", hasAssertion ? "passed" : "failed"));
#endif

            if (hasAssertion) {
                // it's consistent.
                Element* element =
                    nsRDFPropertyTestNode::Element::Create(mConflictSet.GetPool(),
                                                           VALUE_TO_IRDFRESOURCE(sourceValue),
                                                           mProperty,
                                                           VALUE_TO_IRDFNODE(targetValue));

                if (! element)
                    return NS_ERROR_OUT_OF_MEMORY;

                inst->AddSupportingElement(element);
            }
            else {
                // it's inconsistent. remove it.
                aInstantiations.Erase(inst--);
            }
        }
        else if ((hasSourceBinding && ! hasTargetBinding) ||
                 (! hasSourceBinding && hasTargetBinding)) {
            // it's an open ended query on the source or
            // target. figure out what matches and add as a
            // cross-product.
            nsCOMPtr<nsISimpleEnumerator> results;
            if (hasSourceBinding) {
                rv = mDataSource->GetTargets(VALUE_TO_IRDFRESOURCE(sourceValue),
                                             mProperty,
                                             PR_TRUE,
                                             getter_AddRefs(results));
            }
            else {
                rv = mDataSource->GetSources(mProperty,
                                             VALUE_TO_IRDFNODE(targetValue),
                                             PR_TRUE,
                                             getter_AddRefs(results));
                if (NS_FAILED(rv)) return rv;
            }

            while (1) {
                PRBool hasMore;
                rv = results->HasMoreElements(&hasMore);
                if (NS_FAILED(rv)) return rv;

                if (! hasMore)
                    break;

                nsCOMPtr<nsISupports> isupports;
                rv = results->GetNext(getter_AddRefs(isupports));
                if (NS_FAILED(rv)) return rv;

                PRInt32 variable;
                Value value;

                if (hasSourceBinding) {
                    variable = mTargetVariable;

                    nsCOMPtr<nsIRDFNode> target = do_QueryInterface(isupports);
                    NS_ASSERTION(target != nsnull, "target is not an nsIRDFNode");

#ifdef PR_LOGGING
                    if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) {
                        nsAutoString s(NS_LITERAL_STRING("(none found)"));
                        if (target)
                            nsXULContentUtils::GetTextForNode(target, s);

                        PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
                               ("    target => %s", NS_ConvertUCS2toUTF8(s).get()));
                    }
#endif

                    if (! target) continue;

                    targetValue = value = target.get();
                }
                else {
                    variable = mSourceVariable;

                    nsCOMPtr<nsIRDFResource> source = do_QueryInterface(isupports);
                    NS_ASSERTION(source != nsnull, "source is not an nsIRDFResource");

#ifdef PR_LOGGING
                    if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) {
                        const char* s = "(none found)";
                        if (source)
                            source->GetValueConst(&s);

                        PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
                               ("    source => %s", s));
                    }
#endif

                    if (! source) continue;

                    sourceValue = value = source.get();
                }

                // Copy the original instantiation, and add it to the
                // instantiation set with the new assignment that we've
                // introduced. Ownership will be transferred to the
                Instantiation newinst = *inst;
                newinst.AddAssignment(variable, value);

                Element* element =
                    nsRDFPropertyTestNode::Element::Create(mConflictSet.GetPool(),
                                                           VALUE_TO_IRDFRESOURCE(sourceValue),
                                                           mProperty,
                                                           VALUE_TO_IRDFNODE(targetValue));

                if (! element)
                    return NS_ERROR_OUT_OF_MEMORY;

                newinst.AddSupportingElement(element);

                aInstantiations.Insert(inst, newinst);
            }

            // finally, remove the "under specified" instantiation.
            aInstantiations.Erase(inst--);
        }
        else {
            // Neither source nor target assignment!
            NS_ERROR("can't do open ended queries like that!");
            return NS_ERROR_UNEXPECTED;
        }
    }

    return NS_OK;
}

Here is the call graph for this function:

Retrieve the set of variables that are introduced by this node and any of its ancestors.

To correctly implement this method, a node must add any variables that it introduces to the variable set, and then recursively call GetAncestorVariables() on its parent (or parents).

Parameters:
aVariablesThe variable set to which the callee will add its variables, and its ancestors variables.
Returns:
NS_OK if no errors occur.

Reimplemented from TestNode.

Definition at line 335 of file nsRDFPropertyTestNode.cpp.

{
    nsresult rv;

    if (mSourceVariable) {
        rv = aVariables.Add(mSourceVariable);
        if (NS_FAILED(rv)) return rv;
    }

    if (mTargetVariable) {
        rv = aVariables.Add(mTargetVariable);
        if (NS_FAILED(rv)) return rv;
    }

    return TestNode::GetAncestorVariables(aVariables);
}

Here is the call graph for this function:

InnerNode* TestNode::GetParent ( ) const [inline, inherited]

Retrieve the test node's parent.

Returns:
the test node's parent

Definition at line 1065 of file nsRuleNetwork.h.

{ return mParent; }

Here is the caller graph for this function:

PRBool TestNode::HasAncestor ( const ReteNode aNode) const [virtual, inherited]

Determine if this node has another node as its direct ancestor.

Parameters:
aNodethe node to look for.
Returns:
PR_TRUE if aNode is a direct ancestor of this node, PR_FALSE otherwise.

Implements InnerNode.

Definition at line 1106 of file nsRuleNetwork.cpp.

{
    return aNode == this ? PR_TRUE : mParent->HasAncestor(aNode);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult TestNode::Propagate ( const InstantiationSet aInstantiations,
void aClosure 
) [virtual, inherited]

Calls FilterInstantiations() on the instantiation set, and if the resulting set isn't empty, propagates the new set down to each of the test node's children.

Implements ReteNode.

Definition at line 1036 of file nsRuleNetwork.cpp.

{
    nsresult rv;

    PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
           ("TestNode[%p]: Propagate() begin", this));

    InstantiationSet instantiations = aInstantiations;
    rv = FilterInstantiations(instantiations, aClosure);
    if (NS_FAILED(rv)) return rv;

    if (! instantiations.Empty()) {
        ReteNodeSet::Iterator last = mKids.Last();
        for (ReteNodeSet::Iterator kid = mKids.First(); kid != last; ++kid) {
            PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
                   ("TestNode[%p]: Propagate() passing to child %p", this, kid.operator->()));

            kid->Propagate(instantiations, aClosure);
        }
    }

    PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
           ("TestNode[%p]: Propagate() end", this));

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InnerNode::RemoveAllChildren ( ) [inline, inherited]

Remove all the children of this node.

Returns:
NS_OK if no errors occur.

Definition at line 979 of file nsRuleNetwork.h.

{ return mKids.Clear(); }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsRDFPropertyTestNode::Retract ( nsIRDFResource aSource,
nsIRDFResource aProperty,
nsIRDFNode aTarget,
nsTemplateMatchSet aFirings,
nsTemplateMatchSet aRetractions 
) const [virtual]

  

Implements nsRDFTestNode.

Definition at line 397 of file nsRDFPropertyTestNode.cpp.

{
    if (aProperty == mProperty.get()) {
#ifdef PR_LOGGING
        if (PR_LOG_TEST(gXULTemplateLog, PR_LOG_DEBUG)) {
            const char* source;
            aSource->GetValueConst(&source);

            const char* property;
            aProperty->GetValueConst(&property);

            nsAutoString target;
            nsXULContentUtils::GetTextForNode(aTarget, target);

            PR_LOG(gXULTemplateLog, PR_LOG_DEBUG,
                   ("nsRDFPropertyTestNode[%p]: Retract([%s]==[%s]=>[%s])",
                    this, source, property, NS_ConvertUCS2toUTF8(target).get()));
        }
#endif

        mConflictSet.Remove(Element(aSource, aProperty, aTarget), aFirings, aRetractions);
    }
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 159 of file nsRDFPropertyTestNode.h.

Definition at line 160 of file nsRDFPropertyTestNode.h.

ReteNodeSet InnerNode::mKids [protected, inherited]

Definition at line 982 of file nsRuleNetwork.h.

InnerNode* TestNode::mParent [protected, inherited]

Definition at line 1100 of file nsRuleNetwork.h.

Definition at line 163 of file nsRDFPropertyTestNode.h.

Definition at line 162 of file nsRDFPropertyTestNode.h.

Definition at line 161 of file nsRDFPropertyTestNode.h.

Definition at line 165 of file nsRDFPropertyTestNode.h.

Definition at line 164 of file nsRDFPropertyTestNode.h.


The documentation for this class was generated from the following files: