2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-03-23 10:39:31 +03:00
|
|
|
|
|
|
|
#include "nsInstantiationNode.h"
|
|
|
|
#include "nsTemplateRule.h"
|
2006-02-13 19:02:08 +03:00
|
|
|
#include "nsXULTemplateQueryProcessorRDF.h"
|
2001-03-23 10:39:31 +03:00
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2001-03-23 10:39:31 +03:00
|
|
|
extern PRLogModuleInfo* gXULTemplateLog;
|
|
|
|
|
2006-02-13 19:02:08 +03:00
|
|
|
nsInstantiationNode::nsInstantiationNode(nsXULTemplateQueryProcessorRDF* aProcessor,
|
|
|
|
nsRDFQuery* aQuery)
|
|
|
|
: mProcessor(aProcessor),
|
|
|
|
mQuery(aQuery)
|
2001-03-23 10:39:31 +03:00
|
|
|
{
|
2015-06-02 14:05:56 +03:00
|
|
|
MOZ_LOG(gXULTemplateLog, PR_LOG_DEBUG,
|
2006-02-13 19:02:08 +03:00
|
|
|
("nsInstantiationNode[%p] query=%p", this, aQuery));
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(nsInstantiationNode);
|
2001-03-23 10:39:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsInstantiationNode::~nsInstantiationNode()
|
|
|
|
{
|
2006-02-13 19:02:08 +03:00
|
|
|
MOZ_COUNT_DTOR(nsInstantiationNode);
|
2001-03-23 10:39:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2006-02-13 19:02:08 +03:00
|
|
|
nsInstantiationNode::Propagate(InstantiationSet& aInstantiations,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsUpdate, bool& aTakenInstantiations)
|
2001-03-23 10:39:31 +03:00
|
|
|
{
|
2006-02-13 19:02:08 +03:00
|
|
|
// In update mode, iterate through the results and call the template
|
|
|
|
// builder to update them. In non-update mode, cache them in the processor
|
|
|
|
// to be used during processing. The results are cached in the processor
|
|
|
|
// so that the simple rules are only computed once. In this situation, all
|
|
|
|
// data for all queries are calculated at once.
|
|
|
|
nsresult rv = NS_OK;
|
2001-04-04 09:00:08 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
aTakenInstantiations = false;
|
2001-03-23 10:39:31 +03:00
|
|
|
|
2006-02-13 19:02:08 +03:00
|
|
|
if (aIsUpdate) {
|
|
|
|
// Iterate through newly added keys to determine which rules fired.
|
|
|
|
//
|
|
|
|
// XXXwaterson Unfortunately, this could also lead to retractions;
|
|
|
|
// e.g., (container ?a ^empty false) could become "unmatched". How
|
|
|
|
// to track those?
|
|
|
|
nsCOMPtr<nsIDOMNode> querynode;
|
|
|
|
mQuery->GetQueryNode(getter_AddRefs(querynode));
|
2001-04-04 09:00:08 +04:00
|
|
|
|
2006-02-13 19:02:08 +03:00
|
|
|
InstantiationSet::ConstIterator last = aInstantiations.Last();
|
|
|
|
for (InstantiationSet::ConstIterator inst = aInstantiations.First(); inst != last; ++inst) {
|
|
|
|
nsAssignmentSet assignments = inst->mAssignments;
|
2001-03-23 10:39:31 +03:00
|
|
|
|
2006-02-13 19:02:08 +03:00
|
|
|
nsCOMPtr<nsIRDFNode> node;
|
|
|
|
assignments.GetAssignmentFor(mQuery->mMemberVariable,
|
|
|
|
getter_AddRefs(node));
|
|
|
|
if (node) {
|
|
|
|
nsCOMPtr<nsIRDFResource> resource = do_QueryInterface(node);
|
|
|
|
if (resource) {
|
|
|
|
nsRefPtr<nsXULTemplateResultRDF> nextresult =
|
|
|
|
new nsXULTemplateResultRDF(mQuery, *inst, resource);
|
|
|
|
if (! nextresult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2001-03-23 10:39:31 +03:00
|
|
|
|
2006-02-13 19:02:08 +03:00
|
|
|
rv = mProcessor->AddMemoryElements(*inst, nextresult);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-03-23 10:39:31 +03:00
|
|
|
|
2006-02-13 19:02:08 +03:00
|
|
|
mProcessor->GetBuilder()->AddResult(nextresult, querynode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-23 10:39:31 +03:00
|
|
|
}
|
2006-02-13 19:02:08 +03:00
|
|
|
else {
|
|
|
|
nsresult rv = mQuery->SetCachedResults(mProcessor, aInstantiations);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2011-10-17 18:59:28 +04:00
|
|
|
aTakenInstantiations = true;
|
2006-02-13 19:02:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2001-03-23 10:39:31 +03:00
|
|
|
}
|