Cleaned up data source construction, made more consistent with other NGLayout modules.

This commit is contained in:
waterson%netscape.com 1998-12-08 06:53:49 +00:00
parent 27c65d8512
commit 6995c4fe4a
6 changed files with 187 additions and 143 deletions

View File

@ -20,7 +20,7 @@
#include "nsIRDFNode.h"
#include "nsIRDFResourceManager.h"
#include "nsIServiceManager.h"
#include "nsBookmarkDataSource.h"
#include "nsMemoryDataSource.h"
#include "nsRDFCID.h"
#include "nsString.h"
#include "nsVoidArray.h"
@ -427,12 +427,28 @@ BookmarkParser::Assert(nsIRDFNode* subject,
}
////////////////////////////////////////////////////////////////////////
// nsBookmarkDataSource
// BookmarkDataSourceImpl
class BookmarkDataSourceImpl : public nsMemoryDataSource {
protected:
static const char* kBookmarksFilename;
nsresult ReadBookmarks(void);
nsresult WriteBookmarks(void);
public:
BookmarkDataSourceImpl(void);
virtual ~BookmarkDataSourceImpl(void);
NS_IMETHOD Flush(void);
};
////////////////////////////////////////////////////////////////////////
// XXX we should get this from prefs.
const char* nsBookmarkDataSource::kBookmarksFilename = "bookmarks.html";
const char* BookmarkDataSourceImpl::kBookmarksFilename = "bookmarks.html";
nsBookmarkDataSource::nsBookmarkDataSource(void)
BookmarkDataSourceImpl::BookmarkDataSourceImpl(void)
{
// XXX rvg there should be only one instance of this class.
// this is actually true of all datasources.
@ -441,7 +457,7 @@ nsBookmarkDataSource::nsBookmarkDataSource(void)
Init(kURI_bookmarks);
}
nsBookmarkDataSource::~nsBookmarkDataSource(void)
BookmarkDataSourceImpl::~BookmarkDataSourceImpl(void)
{
Flush();
}
@ -449,7 +465,7 @@ nsBookmarkDataSource::~nsBookmarkDataSource(void)
NS_IMETHODIMP
nsBookmarkDataSource::Flush(void)
BookmarkDataSourceImpl::Flush(void)
{
return WriteBookmarks();
}
@ -457,7 +473,7 @@ nsBookmarkDataSource::Flush(void)
nsresult
nsBookmarkDataSource::ReadBookmarks(void)
BookmarkDataSourceImpl::ReadBookmarks(void)
{
nsresult rv = NS_ERROR_FAILURE;
@ -474,7 +490,7 @@ nsBookmarkDataSource::ReadBookmarks(void)
nsresult
nsBookmarkDataSource::WriteBookmarks(void)
BookmarkDataSourceImpl::WriteBookmarks(void)
{
//PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
@ -577,3 +593,16 @@ HT_WriteOutAsBookmarks1 (RDF rdf, PRFileDesc *fp, RDF_Resource u, RDF_Resource t
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFBookmarkDataSource(nsIRDFDataSource** result)
{
BookmarkDataSourceImpl* ds = new BookmarkDataSourceImpl();
if (! ds)
return NS_ERROR_NULL_POINTER;
*result = ds;
NS_ADDREF(*result);
return NS_OK;
}

View File

@ -728,3 +728,16 @@ nsMemoryDataSource::Ensure(nsIRDFNode* node)
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFMemoryDataSource(nsIRDFDataSource** result)
{
nsMemoryDataSource* ds = new nsMemoryDataSource();
if (! ds)
return NS_ERROR_OUT_OF_MEMORY;
*result = ds;
NS_ADDREF(*result);
return NS_OK;
}

View File

@ -16,24 +16,28 @@
* Reserved.
*/
// This header file just contains prototypes for the factory methods
// for "builtin" data sources that are included in rdf.dll. Each of
// these data sources is exposed to the external world via its CID in
// ../include/nsRDFCID.h.
#ifndef nsBookmarkDataSource_h__
#define nsBookmarkDataSource_h__
#ifndef nsBuiltinDataSources_h__
#define nsBuiltinDataSources_h__
#include "nsMemoryDataSource.h"
#include "nsError.h"
class nsBookmarkDataSource : public nsMemoryDataSource {
protected:
static const char* kBookmarksFilename;
class nsIRDFDataSource;
class nsIRDFDataBase;
nsresult ReadBookmarks(void);
nsresult WriteBookmarks(void);
// in nsBookmarkDataSource.cpp
nsresult NS_NewRDFBookmarkDataSource(nsIRDFDataSource** result);
public:
nsBookmarkDataSource(void);
virtual ~nsBookmarkDataSource(void);
// in nsMemoryDataSource.cpp
nsresult NS_NewRDFMemoryDataSource(nsIRDFDataSource** result);
// in nsSimpleDataBase.cpp
nsresult NS_NewRDFSimpleDataBase(nsIRDFDataBase** result);
#endif // nsBuiltinDataSources_h__
NS_IMETHOD Flush(void);
};
#endif nsBookmarkDataSource_h__

View File

@ -18,10 +18,8 @@
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsRDFBuiltInDataSources.h"
#include "nsRDFResourceManager.h"
#include "nsMemoryDataSource.h"
#include "nsBookmarkDataSource.h"
#include "nsSimpleDataBase.h"
#include "nsRDFDocument.h"
#include "nsRDFRegistryImpl.h"
#include "nsRDFCID.h"
@ -118,16 +116,25 @@ nsRDFFactory::CreateInstance(nsISupports *aOuter,
inst = NS_STATIC_CAST(nsISupports*, new nsRDFResourceManager());
}
else if (mClassID.Equals(kRDFMemoryDataSourceCID)) {
inst = NS_STATIC_CAST(nsISupports*, new nsMemoryDataSource());
if (NS_FAILED(rv = NS_NewRDFMemoryDataSource((nsIRDFDataSource**) &inst)))
return rv;
wasRefCounted = PR_TRUE;
}
else if (mClassID.Equals(kRDFBookmarkDataSourceCID)) {
inst = NS_STATIC_CAST(nsISupports*, new nsBookmarkDataSource());
if (NS_FAILED(rv = NS_NewRDFBookmarkDataSource((nsIRDFDataSource**) &inst)))
return rv;
wasRefCounted = PR_TRUE;
}
else if (mClassID.Equals(kRDFRegistryCID)) {
inst = NS_STATIC_CAST(nsISupports*, new nsRDFRegistryImpl());
}
else if (mClassID.Equals(kRDFSimpleDataBaseCID)) {
inst = NS_STATIC_CAST(nsISupports*, new nsSimpleDataBase());
if (NS_FAILED(rv = NS_NewRDFSimpleDataBase((nsIRDFDataBase**) &inst)))
return rv;
wasRefCounted = PR_TRUE;
}
else if (mClassID.Equals(kRDFHTMLDocumentCID)) {
if (NS_FAILED(rv = NS_NewRDFHTMLDocument((nsIRDFDocument**) &inst)))

View File

@ -16,12 +16,13 @@
* Reserved.
*/
#include "nsSimpleDataBase.h"
#include "nsIRDFCursor.h"
#include "nsIRDFNode.h"
#include "nsIRDFDataBase.h"
#include "nsISupportsArray.h"
#include "nsRDFCID.h"
#include "nsRepository.h"
#include "nsVoidArray.h"
#include "prlog.h"
/*
@ -336,11 +337,80 @@ dbArcCursorImpl::HasNegation(nsIRDFDataSource* ds0,
////////////////////////////////////////////////////////////////////////
// nsSimpleDataBase
// SimpleDataBaseImpl
// XXX rvg --- shouldn't this take a char** argument indicating the data sources
// we want to aggregate?
nsSimpleDataBase::nsSimpleDataBase(void)
class SimpleDataBaseImpl : public nsIRDFDataBase {
protected:
nsVoidArray mDataSources;
virtual ~SimpleDataBaseImpl(void);
public:
SimpleDataBaseImpl(void);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFDataSource interface
NS_IMETHOD Init(const nsString& uri);
NS_IMETHOD GetSource(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFNode*& source);
NS_IMETHOD GetSources(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor*& sources);
NS_IMETHOD GetTarget(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFNode*& target);
NS_IMETHOD GetTargets(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFCursor*& targets);
NS_IMETHOD Assert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv = PR_TRUE);
NS_IMETHOD Unassert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target);
NS_IMETHOD HasAssertion(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
PRBool& hasAssertion);
NS_IMETHOD AddObserver(nsIRDFObserver* n);
NS_IMETHOD RemoveObserver(nsIRDFObserver* n);
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor*& labels);
NS_IMETHOD ArcLabelsOut(nsIRDFNode* source,
nsIRDFCursor*& labels);
NS_IMETHOD Flush();
// nsIRDFDataBase interface
NS_IMETHOD AddDataSource(nsIRDFDataSource* source);
NS_IMETHOD RemoveDataSource(nsIRDFDataSource* source);
};
////////////////////////////////////////////////////////////////////////
SimpleDataBaseImpl::SimpleDataBaseImpl(void)
{
NS_INIT_REFCNT();
@ -359,7 +429,7 @@ nsSimpleDataBase::nsSimpleDataBase(void)
}
nsSimpleDataBase::~nsSimpleDataBase(void)
SimpleDataBaseImpl::~SimpleDataBaseImpl(void)
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
@ -370,11 +440,11 @@ nsSimpleDataBase::~nsSimpleDataBase(void)
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMPL_ADDREF(nsSimpleDataBase);
NS_IMPL_RELEASE(nsSimpleDataBase);
NS_IMPL_ADDREF(SimpleDataBaseImpl);
NS_IMPL_RELEASE(SimpleDataBaseImpl);
NS_IMETHODIMP
nsSimpleDataBase::QueryInterface(REFNSIID iid, void** result)
SimpleDataBaseImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
@ -396,14 +466,14 @@ nsSimpleDataBase::QueryInterface(REFNSIID iid, void** result)
// nsIRDFDataSource interface
NS_IMETHODIMP
nsSimpleDataBase::Init(const nsString& uri)
SimpleDataBaseImpl::Init(const nsString& uri)
{
PR_ASSERT(0);
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
nsSimpleDataBase::GetSource(nsIRDFNode* property,
SimpleDataBaseImpl::GetSource(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFNode*& source)
@ -431,7 +501,7 @@ nsSimpleDataBase::GetSource(nsIRDFNode* property,
}
NS_IMETHODIMP
nsSimpleDataBase::GetSources(nsIRDFNode* property,
SimpleDataBaseImpl::GetSources(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor*& sources)
@ -441,7 +511,7 @@ nsSimpleDataBase::GetSources(nsIRDFNode* property,
}
NS_IMETHODIMP
nsSimpleDataBase::GetTarget(nsIRDFNode* source,
SimpleDataBaseImpl::GetTarget(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFNode*& target)
@ -469,7 +539,7 @@ nsSimpleDataBase::GetTarget(nsIRDFNode* source,
}
NS_IMETHODIMP
nsSimpleDataBase::GetTargets(nsIRDFNode* source,
SimpleDataBaseImpl::GetTargets(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFCursor*& targets)
@ -483,7 +553,7 @@ nsSimpleDataBase::GetTargets(nsIRDFNode* source,
}
NS_IMETHODIMP
nsSimpleDataBase::Assert(nsIRDFNode* source,
SimpleDataBaseImpl::Assert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv)
@ -522,7 +592,7 @@ nsSimpleDataBase::Assert(nsIRDFNode* source,
}
NS_IMETHODIMP
nsSimpleDataBase::Unassert(nsIRDFNode* source,
SimpleDataBaseImpl::Unassert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target)
{
@ -547,7 +617,7 @@ nsSimpleDataBase::Unassert(nsIRDFNode* source,
}
NS_IMETHODIMP
nsSimpleDataBase::HasAssertion(nsIRDFNode* source,
SimpleDataBaseImpl::HasAssertion(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
@ -584,21 +654,21 @@ nsSimpleDataBase::HasAssertion(nsIRDFNode* source,
}
NS_IMETHODIMP
nsSimpleDataBase::AddObserver(nsIRDFObserver* n)
SimpleDataBaseImpl::AddObserver(nsIRDFObserver* n)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsSimpleDataBase::RemoveObserver(nsIRDFObserver* n)
SimpleDataBaseImpl::RemoveObserver(nsIRDFObserver* n)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsSimpleDataBase::ArcLabelsIn(nsIRDFNode* node,
SimpleDataBaseImpl::ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor*& labels)
{
PR_ASSERT(0);
@ -606,7 +676,7 @@ nsSimpleDataBase::ArcLabelsIn(nsIRDFNode* node,
}
NS_IMETHODIMP
nsSimpleDataBase::ArcLabelsOut(nsIRDFNode* source,
SimpleDataBaseImpl::ArcLabelsOut(nsIRDFNode* source,
nsIRDFCursor*& labels)
{
labels = new dbArcCursorImpl(mDataSources, source);
@ -618,7 +688,7 @@ nsSimpleDataBase::ArcLabelsOut(nsIRDFNode* source,
}
NS_IMETHODIMP
nsSimpleDataBase::Flush()
SimpleDataBaseImpl::Flush()
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
@ -634,7 +704,7 @@ nsSimpleDataBase::Flush()
// fit in. Right now, the new datasource gets stuck at the end.
NS_IMETHODIMP
nsSimpleDataBase::AddDataSource(nsIRDFDataSource* source)
SimpleDataBaseImpl::AddDataSource(nsIRDFDataSource* source)
{
if (! source)
return NS_ERROR_NULL_POINTER;
@ -647,7 +717,7 @@ nsSimpleDataBase::AddDataSource(nsIRDFDataSource* source)
NS_IMETHODIMP
nsSimpleDataBase::RemoveDataSource(nsIRDFDataSource* source)
SimpleDataBaseImpl::RemoveDataSource(nsIRDFDataSource* source)
{
if (! source)
return NS_ERROR_NULL_POINTER;
@ -658,3 +728,17 @@ nsSimpleDataBase::RemoveDataSource(nsIRDFDataSource* source)
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFSimpleDataBase(nsIRDFDataBase** result)
{
SimpleDataBaseImpl* db = new SimpleDataBaseImpl();
if (! db)
return NS_ERROR_OUT_OF_MEMORY;
*result = db;
NS_ADDREF(*result);
return NS_OK;
}

View File

@ -1,93 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsSimpleDataBase_h__
#define nsSimpleDataBase_h__
#include "nsIRDFDataBase.h"
#include "nsVoidArray.h"
class nsSimpleDataBase : public nsIRDFDataBase {
protected:
nsVoidArray mDataSources;
virtual ~nsSimpleDataBase(void);
public:
nsSimpleDataBase(void);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFDataSource interface
NS_IMETHOD Init(const nsString& uri);
NS_IMETHOD GetSource(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFNode*& source);
NS_IMETHOD GetSources(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor*& sources);
NS_IMETHOD GetTarget(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFNode*& target);
NS_IMETHOD GetTargets(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFCursor*& targets);
NS_IMETHOD Assert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv = PR_TRUE);
NS_IMETHOD Unassert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target);
NS_IMETHOD HasAssertion(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
PRBool& hasAssertion);
NS_IMETHOD AddObserver(nsIRDFObserver* n);
NS_IMETHOD RemoveObserver(nsIRDFObserver* n);
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor*& labels);
NS_IMETHOD ArcLabelsOut(nsIRDFNode* source,
nsIRDFCursor*& labels);
NS_IMETHOD Flush();
// nsIRDFDataBase interface
NS_IMETHOD AddDataSource(nsIRDFDataSource* source);
NS_IMETHOD RemoveDataSource(nsIRDFDataSource* source);
};
#endif // nsSimpleDataBase_h__