Make ::Init() barf if the element is not a container, rather than sprinkling around in individual methods.

This commit is contained in:
waterson%netscape.com 1999-09-22 03:28:32 +00:00
Родитель 200dae8918
Коммит b8f5dd60c9
1 изменённых файлов: 17 добавлений и 8 удалений

Просмотреть файл

@ -136,6 +136,23 @@ RDFContainerImpl::Init(nsIRDFDataSource *aDataSource, nsIRDFResource *aContainer
if (! aContainer)
return NS_ERROR_NULL_POINTER;
nsresult rv;
PRBool isContainer;
rv = gRDFContainerUtils->IsContainer(aDataSource, aContainer, &isContainer);
if (NS_FAILED(rv)) return rv;
if (! isContainer) {
#ifdef DEBUG
nsCAutoString msg;
nsXPIDLCString uri;
aContainer->GetValue(getter_Copies(uri));
msg += uri;
msg += " is not an RDF container";
NS_WARNING((const char*) msg);
#endif
return NS_ERROR_UNEXPECTED;
}
NS_IF_RELEASE(mDataSource);
mDataSource = aDataSource;
NS_ADDREF(mDataSource);
@ -209,14 +226,6 @@ RDFContainerImpl::AppendElement(nsIRDFNode *aElement)
nsresult rv;
PRBool isContainer;
rv = gRDFContainerUtils->IsContainer(mDataSource, mContainer, &isContainer);
if (NS_FAILED(rv)) return rv;
NS_PRECONDITION(isContainer, "not a container");
if (! isContainer)
return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIRDFResource> nextVal;
rv = GetNextValue(getter_AddRefs(nextVal));
if (NS_FAILED(rv)) return rv;