7777#include " nsINameSpace.h"
7878#include " nsINameSpaceManager.h"
7979#include " nsIRDFCompositeDataSource.h"
80+ #include " nsIRDFInferDataSource.h"
8081#include " nsIRDFContainerUtils.h"
8182#include " nsIXULDocument.h"
8283#include " nsIXULTemplateBuilder.h"
@@ -149,6 +150,7 @@ PRLogModuleInfo* gXULTemplateLog;
149150
150151nsXULTemplateBuilder::nsXULTemplateBuilder (void )
151152 : mDB(nsnull),
153+ mCompDB(nsnull),
152154 mRoot(nsnull),
153155 mUpdateBatchNest(0 ),
154156 mRulesCompiled(PR_FALSE),
@@ -220,7 +222,7 @@ nsXULTemplateBuilder::GetRoot(nsIDOMElement** aResult)
220222NS_IMETHODIMP
221223nsXULTemplateBuilder::GetDatabase (nsIRDFCompositeDataSource** aResult)
222224{
223- NS_IF_ADDREF (*aResult = mDB .get());
225+ NS_IF_ADDREF (*aResult = mCompDB .get());
224226 return NS_OK;
225227}
226228
@@ -248,7 +250,7 @@ nsXULTemplateBuilder::Refresh()
248250 nsresult rv;
249251
250252 nsCOMPtr<nsISimpleEnumerator> dslist;
251- rv = mDB ->GetDataSources (getter_AddRefs (dslist));
253+ rv = mCompDB ->GetDataSources (getter_AddRefs (dslist));
252254 NS_ENSURE_SUCCESS (rv, rv);
253255
254256 PRBool hasMore;
@@ -350,6 +352,7 @@ nsXULTemplateBuilder::DocumentWillBeDestroyed(nsIDocument *aDocument)
350352 if (mDB ) {
351353 mDB ->RemoveObserver (this );
352354 mDB = nsnull;
355+ mCompDB = nsnull;
353356 }
354357
355358 mRoot = nsnull;
@@ -668,12 +671,15 @@ nsXULTemplateBuilder::LoadDataSources(nsIDocument* doc)
668671
669672 if (mDB ) {
670673 mDB ->RemoveObserver (this );
674+
675+ // we'll set it again later, after we create a new composite ds
676+ mDB = nsnull;
671677 }
672678
673679 // create a database for the builder
674- mDB = do_CreateInstance (NS_RDF_DATASOURCE_CONTRACTID_PREFIX " composite-datasource" );
680+ mCompDB = do_CreateInstance (NS_RDF_DATASOURCE_CONTRACTID_PREFIX " composite-datasource" );
675681
676- if (! mDB ) {
682+ if (! mCompDB ) {
677683 NS_ERROR (" unable to construct new composite data source" );
678684 return NS_ERROR_UNEXPECTED;
679685 }
@@ -682,12 +688,12 @@ nsXULTemplateBuilder::LoadDataSources(nsIDocument* doc)
682688 nsAutoString coalesce;
683689 mRoot ->GetAttr (kNameSpaceID_None , nsXULAtoms::coalesceduplicatearcs, coalesce);
684690 if (coalesce.EqualsLiteral (" false" ))
685- mDB ->SetCoalesceDuplicateArcs (PR_FALSE);
691+ mCompDB ->SetCoalesceDuplicateArcs (PR_FALSE);
686692
687693 nsAutoString allowneg;
688694 mRoot ->GetAttr (kNameSpaceID_None , nsXULAtoms::allownegativeassertions, allowneg);
689695 if (allowneg.EqualsLiteral (" false" ))
690- mDB ->SetAllowNegativeAssertions (PR_FALSE);
696+ mCompDB ->SetAllowNegativeAssertions (PR_FALSE);
691697
692698 // Grab the doc's principal...
693699 nsIPrincipal *docPrincipal = doc->GetPrincipal ();
@@ -706,7 +712,7 @@ nsXULTemplateBuilder::LoadDataSources(nsIDocument* doc)
706712 nsCOMPtr<nsIRDFDataSource> localstore;
707713 rv = gRDFService ->GetDataSource (" rdf:local-store" , getter_AddRefs (localstore));
708714 if (NS_SUCCEEDED(rv)) {
709- rv = mDB ->AddDataSource (localstore);
715+ rv = mCompDB ->AddDataSource (localstore);
710716 NS_ASSERTION (NS_SUCCEEDED(rv), "unable to add local store to db");
711717 if (NS_FAILED(rv)) return rv;
712718 }
@@ -793,9 +799,28 @@ nsXULTemplateBuilder::LoadDataSources(nsIDocument* doc)
793799 continue ;
794800 }
795801
796- mDB ->AddDataSource (ds);
802+ mCompDB ->AddDataSource (ds);
797803 }
798804
805+ // check if we were given an inference engine type
806+ nsAutoString infer;
807+ mRoot ->GetAttr (kNameSpaceID_None , nsXULAtoms::infer, infer);
808+ if (!infer.IsEmpty ()) {
809+ nsCString inferContractID (NS_RDF_INFER_DATASOURCE_CONTRACTID_PREFIX);
810+ AppendUTF16toUTF8 (infer, inferContractID);
811+ nsCOMPtr<nsIRDFInferDataSource> inferDB = do_CreateInstance (inferContractID.get ());
812+
813+ if (inferDB) {
814+ inferDB->SetBaseDataSource (mCompDB );
815+ mDB = do_QueryInterface (inferDB);
816+ } else {
817+ NS_WARNING (" failed to construct inference engine specified on template" );
818+ }
819+ }
820+
821+ if (!mDB )
822+ mDB = mCompDB ;
823+
799824 nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface (doc);
800825 if (xuldoc)
801826 xuldoc->SetTemplateBuilderFor (mRoot , this );
0 commit comments