NS_PRECONDITION(aResult != nsnull, "null ptr"); if (! aResult) return NS_ERROR_NULL_POINTER;
if (!mDataSource || !mContainer) return NS_ERROR_NOT_INITIALIZED;
RDFContainerImpl::GetNextValue(nsIRDFResource** aResult){    NS_PRECONDITION(aResult != nsnull, "null ptr");    if (! aResult)        return NS_ERROR_NULL_POINTER;    nsresult rv;    // Get the next value, which hangs off of the bag via the    // RDF:nextVal property.    nsCOMPtr<nsIRDFNode> nextValNode;    rv = mDataSource->GetTarget(mContainer, kRDF_nextVal, PR_TRUE, getter_AddRefs(nextValNode));    if (NS_FAILED(rv)) return rv;    if (rv == NS_RDF_NO_VALUE)        return NS_ERROR_UNEXPECTED;    nsCOMPtr<nsIRDFLiteral> nextValLiteral;    rv = nextValNode->QueryInterface(NS_GET_IID(nsIRDFLiteral), getter_AddRefs(nextValLiteral));    if (NS_FAILED(rv)) return rv;    const PRUnichar* s;    rv = nextValLiteral->GetValueConst(&s);    if (NS_FAILED(rv)) return rv;    PRInt32 nextVal = 0;    {        for (const PRUnichar* p = s; *p != 0; ++p) {            NS_ASSERTION(*p >= '0' && *p <= '9', "not a digit");            if (*p < '0' || *p > '9')                break;            nextVal *= 10;            nextVal += *p - '0';        }    }    char buf[sizeof(kRDFNameSpaceURI) + 16];    nsCAutoString nextValStr(CBufDescriptor(buf, PR_TRUE, sizeof(buf), 0));    nextValStr = kRDFNameSpaceURI;    nextValStr.Append("_");    nextValStr.AppendInt(nextVal, 10);    rv = gRDFService->GetResource(nextValStr.get(), aResult);    if (NS_FAILED(rv)) return rv;    // Now increment the RDF:nextVal property.    rv = mDataSource->Unassert(mContainer, kRDF_nextVal, nextValLiteral);    if (NS_FAILED(rv)) return rv;    ++nextVal;    nextValStr.Truncate();    nextValStr.AppendInt(nextVal, 10);    rv = gRDFService->GetLiteral(NS_ConvertASCIItoUCS2(nextValStr).get(), getter_AddRefs(nextValLiteral));    if (NS_FAILED(rv)) return rv;    rv = mDataSource->Assert(mContainer, kRDF_nextVal, nextValLiteral, PR_TRUE);    if (NS_FAILED(rv)) return rv;    if (RDF_SEQ_LIST_LIMIT == nextVal)    {        // focal point for RDF container mutation;        // basically, provide a hint to allow for fast access        nsCOMPtr<nsIRDFInMemoryDataSource> inMem = do_QueryInterface(mDataSource);        if (inMem)        {            // ignore error; failure just means slower access            (void)inMem->EnsureFastContainment(mContainer);        }    }    return NS_OK;}