newinst.AddBinding(variable, value); newinst.AddSupportingElement(new Element(VALUE_TO_IRDFRESOURCE(sourceValue), mProperty, VALUE_TO_IRDFNODE(targetValue)));
newinst.AddBinding(mIdVariable, Value(resource.get())); newinst.AddSupportingElement(new Element(VALUE_TO_ICONTENT(contentValue)));
RDFPropertyTestNode::FilterInstantiations(InstantiationSet& aInstantiations) const{    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->mBindings.GetBindingFor(mSourceVariable, &sourceValue);        }        PRBool hasTargetBinding;        Value targetValue;        if (mTarget) {            hasTargetBinding = PR_TRUE;            targetValue = mTarget;        }        else {            hasTargetBinding = inst->mBindings.GetBindingFor(mTargetVariable, &targetValue);        }        if (hasSourceBinding && hasTargetBinding) {            // it's a consistency check. see if we have a binding 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;            if (hasAssertion) {                // it's consistent.                inst->AddSupportingElement(new Element(VALUE_TO_IRDFRESOURCE(sourceValue),                                                       mProperty,                                                       VALUE_TO_IRDFNODE(targetValue)));            }            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");                    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");                    if (! source) continue;                    sourceValue = value = source.get();                }                // Copy the original instantiation, and add it to the                // instantiation set with the new binding that we've                // introduced. Ownership will be transferred to the                Instantiation newinst = *inst;                newinst.AddBinding(variable, value);                newinst.AddSupportingElement(new Element(VALUE_TO_IRDFRESOURCE(sourceValue),                                                         mProperty,                                                         VALUE_TO_IRDFNODE(targetValue)));                aInstantiations.Insert(inst, newinst);            }            // finally, remove the "under specified" instantiation.            aInstantiations.Erase(inst--);        }        else {            // Neither source nor target binding!            NS_ERROR("can't do open ended queries like that!");            return NS_ERROR_UNEXPECTED;        }    }    return NS_OK;}