Added utility routines to create RDF Sequence and Bag objects. Expanded rdf_IsContainer() to accept sequences.

This commit is contained in:
waterson%netscape.com 1998-12-15 07:44:11 +00:00
Родитель e2a3d2fe55
Коммит 1129fb210d
1 изменённых файлов: 79 добавлений и 2 удалений

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

@ -17,6 +17,7 @@
* Netscape Communications Corporation. All Rights Reserved. * Netscape Communications Corporation. All Rights Reserved.
*/ */
#include "nsIRDFCursor.h"
#include "nsIRDFDataBase.h" #include "nsIRDFDataBase.h"
#include "nsIRDFNode.h" #include "nsIRDFNode.h"
#include "nsIRDFResourceManager.h" #include "nsIRDFResourceManager.h"
@ -74,13 +75,14 @@ rdf_IsOrdinalProperty(const nsIRDFNode* property)
PRBool PRBool
rdf_IsContainer(nsIRDFResourceManager* mgr, rdf_IsContainer(nsIRDFResourceManager* mgr,
nsIRDFDataBase* db, nsIRDFDataSource* ds,
nsIRDFNode* resource) nsIRDFNode* resource)
{ {
PRBool result = PR_FALSE; PRBool result = PR_FALSE;
nsIRDFNode* RDF_instanceOf = nsnull; nsIRDFNode* RDF_instanceOf = nsnull;
nsIRDFNode* RDF_Bag = nsnull; nsIRDFNode* RDF_Bag = nsnull;
nsIRDFNode* RDF_Seq = nsnull;
nsresult rv; nsresult rv;
if (NS_FAILED(rv = mgr->GetNode(kURIRDF_instanceOf, RDF_instanceOf))) if (NS_FAILED(rv = mgr->GetNode(kURIRDF_instanceOf, RDF_instanceOf)))
@ -89,9 +91,21 @@ rdf_IsContainer(nsIRDFResourceManager* mgr,
if (NS_FAILED(rv = mgr->GetNode(kURIRDF_Bag, RDF_Bag))) if (NS_FAILED(rv = mgr->GetNode(kURIRDF_Bag, RDF_Bag)))
goto done; goto done;
rv = db->HasAssertion(resource, RDF_instanceOf, RDF_Bag, PR_TRUE, result); if (NS_FAILED(rv = ds->HasAssertion(resource, RDF_instanceOf, RDF_Bag, PR_TRUE, result)))
goto done;
if (result)
goto done;
if (NS_FAILED(rv = mgr->GetNode(kURIRDF_Seq, RDF_Seq)))
goto done;
if (NS_FAILED(rv = ds->HasAssertion(resource, RDF_instanceOf, RDF_Seq, PR_TRUE, result)))
goto done;
done: done:
NS_IF_RELEASE(RDF_Seq);
NS_IF_RELEASE(RDF_Bag); NS_IF_RELEASE(RDF_Bag);
NS_IF_RELEASE(RDF_instanceOf); NS_IF_RELEASE(RDF_instanceOf);
return result; return result;
@ -318,6 +332,68 @@ done:
nsresult nsresult
rdf_CreateSequence(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode*& result)
{
NS_ASSERTION(mgr, "null ptr");
NS_ASSERTION(ds, "null ptr");
nsresult rv;
nsIRDFNode* bag = nsnull;
result = nsnull; // reasonable default
if (NS_FAILED(rv = rdf_CreateAnonymousNode(mgr, bag)))
goto done;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, bag, kURIRDF_instanceOf, kURIRDF_Seq)))
goto done;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, bag, kURIRDF_nextVal, "1")))
goto done;
result = bag;
NS_ADDREF(result);
done:
NS_IF_RELEASE(bag);
return rv;
}
nsresult
rdf_CreateAlternation(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode*& result)
{
NS_ASSERTION(mgr, "null ptr");
NS_ASSERTION(ds, "null ptr");
nsresult rv;
nsIRDFNode* bag = nsnull;
result = nsnull; // reasonable default
if (NS_FAILED(rv = rdf_CreateAnonymousNode(mgr, bag)))
goto done;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, bag, kURIRDF_instanceOf, kURIRDF_Alt)))
goto done;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, bag, kURIRDF_nextVal, "1")))
goto done;
result = bag;
NS_ADDREF(result);
done:
NS_IF_RELEASE(bag);
return rv;
}
static nsresult
rdf_ContainerGetNextValue(nsIRDFResourceManager* mgr, rdf_ContainerGetNextValue(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds, nsIRDFDataSource* ds,
nsIRDFNode* container, nsIRDFNode* container,
@ -442,3 +518,4 @@ done:
NS_IF_RELEASE(that); NS_IF_RELEASE(that);
return result; return result;
} }