nsCOMPtr<nsISupportsArray> elements; rv = NS_NewISupportsArray(getter_AddRefs(elements)); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create new ISupportsArray"); if (NS_FAILED(rv)) return rv;
if (mCache) { mCache->Assert(aSource, aProperty, aTarget, PR_TRUE ); }
RDFGenericBuilderImpl::OnAssert(nsIRDFResource* aSource,                                nsIRDFResource* aProperty,                                nsIRDFNode* aTarget){	// Just silently fail, because this can happen "normally" as part	// of tear-down code. (Bug 9098)    if (! mDocument)        return NS_OK;    nsresult rv;    nsCOMPtr<nsISupportsArray> elements;    rv = NS_NewISupportsArray(getter_AddRefs(elements));	NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create new ISupportsArray");	if (NS_FAILED(rv)) return rv;    // Find all the elements in the content model that correspond to    // aSource: for each, we'll try to build XUL children if    // appropriate.    rv = mDocument->GetElementsForResource(aSource, elements);	NS_ASSERTION(NS_SUCCEEDED(rv), "unable to retrieve elements from resource");	if (NS_FAILED(rv)) return rv;    PRUint32 cnt;    rv = elements->Count(&cnt);    if (NS_FAILED(rv)) return rv;    for (PRInt32 i = PRInt32(cnt) - 1; i >= 0; --i) {		nsISupports* isupports = elements->ElementAt(i);		nsCOMPtr<nsIContent> element( do_QueryInterface(isupports) );		NS_IF_RELEASE(isupports);        // XXX somehow figure out if building XUL kids on this        // particular element makes any sense whatsoever.        // We'll start by making sure that the element at least has        // the same parent has the content model builder's root        if (!IsElementInWidget(element))            continue;                nsCOMPtr<nsIRDFResource> resource = do_QueryInterface(aTarget);        if (resource && IsContainmentProperty(element, aProperty)) {            // Okay, the target  _is_ a resource, and the property is            // a containment property. So this'll be a new item in the widget            // control.            // But if the contents of aElement _haven't_ yet been            // generated, then just ignore the assertion. We do this            // because we know that _eventually_ the contents will be            // generated (via CreateContents()) when somebody asks for            // them later.            nsAutoString contentsGenerated;            rv = element->GetAttribute(kNameSpaceID_None,                                       kContainerContentsGeneratedAtom,                                       contentsGenerated);			if (NS_FAILED(rv)) return rv;            if ((rv != NS_CONTENT_ATTR_HAS_VALUE) || !contentsGenerated.EqualsIgnoreCase("true"))                return NS_OK;            // Okay, it's a "live" element, so go ahead and append the new            // child to this node.            // XXX Bug 10818.            PRBool notify;            if (IsTreeWidgetItem(element) && !IsReflowScheduled()) {                notify = PR_TRUE;                rv = ScheduleReflow();                if (NS_FAILED(rv)) return rv;            }            else {                notify = PR_FALSE;            }            rv = CreateWidgetItem(element, aProperty, resource, 0, notify);            NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create widget item");            if (NS_FAILED(rv)) return rv;                        rv = element->SetAttribute(kNameSpaceID_None, kEmptyAtom, "false", PR_TRUE);            if (NS_FAILED(rv)) return rv;        }        else {            // Either the target of the assertion is not a resource,            // or the object is a resource and the predicate is not a            // containment property. So this won't be a new item in            // the widget. See if we can use it to set a some            // substructure on the current element.            nsAutoString templateID;            rv = element->GetAttribute(kNameSpaceID_None,                                       kTemplateAtom,                                       templateID);            if (NS_FAILED(rv)) return rv;            if (rv == NS_CONTENT_ATTR_HAS_VALUE) {                nsCOMPtr<nsIDOMXULDocument>	xulDoc;                xulDoc = do_QueryInterface(mDocument);                if (! xulDoc)                    return NS_ERROR_UNEXPECTED;                nsCOMPtr<nsIDOMElement>	domElement;                rv = xulDoc->GetElementById(templateID, getter_AddRefs(domElement));                NS_ASSERTION(NS_SUCCEEDED(rv), "unable to find template node");                if (NS_FAILED(rv)) return rv;                nsCOMPtr<nsIContent> templateNode = do_QueryInterface(domElement);                if (! templateNode)                    return NS_ERROR_UNEXPECTED;                // this node was created by a XUL template, so update it accordingly                rv = SynchronizeUsingTemplate(templateNode, element, eSet, aProperty, aTarget);                if (NS_FAILED(rv)) return rv;            	PersistProperty(element, aProperty, aTarget, eSet);            }        }    }    return NS_OK;}