From 6130e3efda358874ec4c9130fdaef46692546d04 Mon Sep 17 00:00:00 2001 From: "waterson%netscape.com" Date: Tue, 22 Dec 1998 01:12:45 +0000 Subject: [PATCH] Modified cursors to return NS_ERROR_RDF_CURSOR_EMPTY when the cursor is empty, rather than NS_ERROR_UNEXPECTED. Miscellaneous bug fixes related to new cursors. --- rdf/src/nsContainerCursor.cpp | 2 +- rdf/src/nsEmptyCursor.cpp | 6 +++--- rdf/src/nsMemoryDataSource.cpp | 30 ++++++++++++++++++------------ rdf/src/nsRDFDocument.cpp | 7 ++++--- rdf/src/nsRDFTreeDocument.cpp | 8 ++++++++ rdf/src/nsSimpleDataBase.cpp | 14 ++++++++++---- 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/rdf/src/nsContainerCursor.cpp b/rdf/src/nsContainerCursor.cpp index d8cca319dbe4..830e71aa7371 100644 --- a/rdf/src/nsContainerCursor.cpp +++ b/rdf/src/nsContainerCursor.cpp @@ -177,7 +177,7 @@ ContainerCursorImpl::Advance(void) // initialize rv to the case where mCounter has advanced past the // last element - rv = NS_ERROR_UNEXPECTED; + rv = NS_ERROR_RDF_CURSOR_EMPTY; while (mCounter < last) { nsIRDFResource* ordinalProperty = nsnull; diff --git a/rdf/src/nsEmptyCursor.cpp b/rdf/src/nsEmptyCursor.cpp index 29d360f9d322..44579345e8fa 100644 --- a/rdf/src/nsEmptyCursor.cpp +++ b/rdf/src/nsEmptyCursor.cpp @@ -58,7 +58,7 @@ public: // nsIRDFCursor NS_IMETHOD Advance(void) { - return NS_ERROR_UNEXPECTED; + return NS_ERROR_RDF_CURSOR_EMPTY; } // nsIRDFAssertionCursor @@ -124,7 +124,7 @@ public: // nsIRDFCursor NS_IMETHOD Advance(void) { - return NS_ERROR_UNEXPECTED; + return NS_ERROR_RDF_CURSOR_EMPTY; } // nsIRDFArcsOutCursor @@ -186,7 +186,7 @@ public: // nsIRDFCursor NS_IMETHOD Advance(void) { - return NS_ERROR_UNEXPECTED; + return NS_ERROR_RDF_CURSOR_EMPTY; } // nsIRDFArcsInCursor diff --git a/rdf/src/nsMemoryDataSource.cpp b/rdf/src/nsMemoryDataSource.cpp index db69df45d060..338e2fe3ff3c 100644 --- a/rdf/src/nsMemoryDataSource.cpp +++ b/rdf/src/nsMemoryDataSource.cpp @@ -307,7 +307,7 @@ PropertyCursorImpl::PropertyCursorImpl(PropertyListElement* first, nsIRDFResource* predicate, PRBool tv) : mFirst(first), - mNext(first), + mNext(nsnull), mDataSource(ds), mSubject(subject), mPredicate(predicate), @@ -334,20 +334,26 @@ PropertyCursorImpl::Advance(void) { if (! mNext) { mNext = mFirst; + + do { + if (mNext->GetTruthValue() == mTruthValue) + return NS_OK; + + mNext = mNext->GetNext(); + } while (mNext != mFirst); } else { mNext = mNext->GetNext(); + + while (mNext != mFirst) { + if (mNext->GetTruthValue() == mTruthValue) + return NS_OK; + + mNext = mNext->GetNext(); + } } - while (1) { - if (mNext == mFirst) - return NS_ERROR_UNEXPECTED; - - if (mNext->GetTruthValue() == mTruthValue) - return NS_OK; - - mNext = mNext->GetNext(); - } + return NS_ERROR_RDF_CURSOR_EMPTY; } @@ -464,11 +470,11 @@ NS_IMETHODIMP ArcsOutCursorImpl::Advance(void) { if (! mProperties || ! mProperties->Count()) - return NS_ERROR_UNEXPECTED; + return NS_ERROR_RDF_CURSOR_EMPTY; PRInt32 index = mProperties->Count() - 1; if (index < 0) - return NS_ERROR_UNEXPECTED; + return NS_ERROR_RDF_CURSOR_EMPTY; NS_IF_RELEASE(mCurrent); diff --git a/rdf/src/nsRDFDocument.cpp b/rdf/src/nsRDFDocument.cpp index 403a3a20d59a..5d2719a7fc32 100644 --- a/rdf/src/nsRDFDocument.cpp +++ b/rdf/src/nsRDFDocument.cpp @@ -1140,11 +1140,12 @@ nsRDFDocument::CreateChildren(nsIRDFContent* element) NS_RELEASE(assertions); NS_RELEASE(property); - - if (NS_FAILED(rv)) - break; } + if (rv = NS_ERROR_RDF_CURSOR_EMPTY) + // This is a normal return code from nsIRDFCursor::Advance() + rv = NS_OK; + done: NS_IF_RELEASE(resource); NS_IF_RELEASE(properties); diff --git a/rdf/src/nsRDFTreeDocument.cpp b/rdf/src/nsRDFTreeDocument.cpp index e00c3f26c4c6..f179bc2bf55e 100644 --- a/rdf/src/nsRDFTreeDocument.cpp +++ b/rdf/src/nsRDFTreeDocument.cpp @@ -402,6 +402,10 @@ RDFTreeDocumentImpl::AddColumnsFromContainer(nsIContent* parent, break; } + if (rv == NS_ERROR_RDF_CURSOR_EMPTY) + // This is a "normal" return code from nsIRDFCursor::Advance(). + rv = NS_OK; + done: NS_IF_RELEASE(cursor); NS_IF_RELEASE(NC_Title); @@ -473,6 +477,10 @@ RDFTreeDocumentImpl::AddColumnsFromMultiAttributes(nsIContent* parent, break; } + if (rv == NS_ERROR_RDF_CURSOR_EMPTY) + // This is a reasonable return code from nsIRDFCursor::Advance() + rv = NS_OK; + // XXX Now search for an "order" property and apply it to the // above to sort them... diff --git a/rdf/src/nsSimpleDataBase.cpp b/rdf/src/nsSimpleDataBase.cpp index 40d83d92fb07..ddac6fd918cb 100644 --- a/rdf/src/nsSimpleDataBase.cpp +++ b/rdf/src/nsSimpleDataBase.cpp @@ -149,11 +149,16 @@ MultiCursor::AdvanceImpl(void) } do { - // If we can't advance the current cursor, then it's - // depleted. Break out of this loop and advance to the - // next cursor. - if (NS_FAILED(rv = mCurrentCursor->Advance())) + if (NS_FAILED(rv = mCurrentCursor->Advance())) { + // If we can't advance the current cursor, then either + // a catastrophic error occurred, or it's depleted. If + // it's just depleted break out of this loop and + // advance to the next cursor. + if (rv != NS_ERROR_RDF_CURSOR_EMPTY) + return rv; + break; + } // Even if the current cursor has more elements, we still // need to check that the current element isn't masked by @@ -424,6 +429,7 @@ nsresult SimpleDBArcsOutCursorImpl::IsCurrentNegatedBy(nsIRDFDataSource* ds0, PRBool* result) { + *result = PR_FALSE; // XXX always? return NS_OK; }