Land RDF_19990617_BRANCH. Add Change() and Move() methods to nsIRDFDataSource; add OnChange() and OnMove() methods to nsIRDFObserver. Factor nsIRDFDatasource::Init() and ::Flush() into nsIRDFRemoteDataSource. Change ownership model s.t. a datasource reference counts its observers.

This commit is contained in:
waterson%netscape.com 1999-06-24 00:22:58 +00:00
Родитель eaca9b63b0
Коммит f008503b2f
38 изменённых файлов: 1341 добавлений и 791 удалений

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

@ -20,8 +20,9 @@
#include "nsFileSpec.h"
#include "nsSpecialSystemDirectory.h"
#include "nsIChromeRegistry.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFObserver.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsCRT.h"
#include "rdf.h"
#include "nsIServiceManager.h"
@ -68,7 +69,6 @@ public:
NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURL);
// nsIRDFDataSource methods
NS_IMETHOD Init(const char* uri) ; // Called to init the data source.
NS_IMETHOD GetURI(char** uri);
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
@ -93,6 +93,14 @@ public:
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target) ;
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
@ -105,7 +113,6 @@ public:
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsISimpleEnumerator** labels /* out */) ;
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult) ;
NS_IMETHOD Flush(void) ;
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands) ;
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
@ -344,9 +351,86 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL)
NS_IMETHODIMP
nsChromeRegistry::InitRegistry()
{
if (mInner == nsnull)
return Init("rdf:chrome");
else return NS_OK;
gRefCnt++;
if (gRefCnt == 1) {
nsresult rv;
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**)&gRDFService);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");
if (NS_FAILED(rv)) return rv;
// get all the properties we'll need:
rv = gRDFService->GetResource(kURICHROME_chrome, &kCHROME_chrome);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_skin, &kCHROME_skin);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_content);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_platform);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_locale);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_behavior);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_base, &kCHROME_base);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_main, &kCHROME_main);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_archive, &kCHROME_archive);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_name, &kCHROME_name);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_displayname, &kCHROME_displayname);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID,
nsnull,
nsIRDFDataSource::GetIID(),
(void**) &mInner);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
if (! remote)
return NS_ERROR_UNEXPECTED;
// Retrieve the mInner data source.
nsSpecialSystemDirectory chromeFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
chromeFile += "chrome";
chromeFile += "registry.rdf";
nsFileURL chromeURL(chromeFile);
const char* innerURI = chromeURL.GetAsString();
rv = remote->Init(innerURI);
if (NS_FAILED(rv)) return rv;
// We need to read this synchronously.
rv = remote->Refresh(PR_TRUE);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
@ -433,98 +517,14 @@ NS_NewChromeRegistry(nsIChromeRegistry** aResult)
////////////////////////////////////////////////////////////////////////////////
// nsIRDFDataSource methods
NS_IMETHODIMP
nsChromeRegistry::Init(const char* uri)
{
// We're going to be init'ed with the "rdf:chrome" URI.
// We want to use the location of the registry source instead.
nsresult rv = NS_OK;
gRefCnt++;
if (gRefCnt == 1) {
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**)&gRDFService);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");
if (NS_FAILED(rv)) return rv;
// get all the properties we'll need:
rv = gRDFService->GetResource(kURICHROME_chrome, &kCHROME_chrome);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_skin, &kCHROME_skin);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_content);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_platform);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_locale);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_behavior);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_base, &kCHROME_base);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_main, &kCHROME_main);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_archive, &kCHROME_archive);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_name, &kCHROME_name);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_displayname, &kCHROME_displayname);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID,
nsnull,
nsIRDFXMLDataSource::GetIID(),
(void**) &mInner);
if (NS_FAILED(rv)) return rv;
// Retrieve the mInner data source.
nsSpecialSystemDirectory chromeFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
chromeFile += "chrome";
chromeFile += "registry.rdf";
nsFileURL chromeURL(chromeFile);
const char* innerURI = chromeURL.GetAsString();
rv = mInner->Init(innerURI);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFXMLDataSource> xmlds = do_QueryInterface(mInner);
if (! xmlds)
return NS_ERROR_FAILURE;
// We need to read this synchronously.
rv = xmlds->Open(PR_TRUE);
}
return rv;
}
NS_IMETHODIMP
nsChromeRegistry::GetURI(char** uri)
{
return mInner->GetURI(uri);
*uri = nsXPIDLCString::Copy("rdf:chrome");
if (! *uri)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
@ -581,6 +581,24 @@ nsChromeRegistry::Unassert(nsIRDFResource* source,
return mInner->Unassert(source, property, target);
}
NS_IMETHODIMP
nsChromeRegistry::Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
return mInner->Change(aSource, aProperty, aOldTarget, aNewTarget);
}
NS_IMETHODIMP
nsChromeRegistry::Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
return mInner->Move(aOldSource, aNewSource, aProperty, aTarget);
}
NS_IMETHODIMP
nsChromeRegistry::HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
@ -618,12 +636,6 @@ NS_IMETHODIMP nsChromeRegistry::GetAllResources(nsISimpleEnumerator** aCursor)
return mInner->GetAllResources(aCursor);
}
NS_IMETHODIMP
nsChromeRegistry::Flush(void)
{
return mInner->Flush();
}
NS_IMETHODIMP
nsChromeRegistry::GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands)

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

@ -175,7 +175,6 @@ static NS_DEFINE_CID(kRangeListCID, NS_RANGELIST_CID);
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
static NS_DEFINE_CID(kXULDataSourceCID, NS_XULDATASOURCE_CID);
static NS_DEFINE_CID(kXULFocusTrackerCID, NS_XULFOCUSTRACKER_CID);
static NS_DEFINE_IID(kIXULFocusTrackerIID, NS_IXULFOCUSTRACKER_IID);
@ -1189,13 +1188,6 @@ XULDocumentImpl::PrepareToLoad( nsCOMPtr<nsIParser>* created_parser,
if (NS_FAILED(rv = db->AddDataSource(mDocumentDataSource))) {
NS_ERROR("unable to add XUL datasource to db");
return rv;
}
const char* seedCString = 0;
syntheticURL->GetSpec(&seedCString);
if (NS_FAILED(rv = mDocumentDataSource->Init(seedCString))) {
NS_ERROR("unable to initialize XUL data source");
return rv;
}
}

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

@ -1616,6 +1616,29 @@ RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSubject,
return NS_OK;
}
NS_IMETHODIMP
RDFGenericBuilderImpl::OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RDFGenericBuilderImpl::OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMNodeObserver interface
//

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

@ -6,8 +6,9 @@ nsIRDFLiteral.idl
nsIRDFNode.idl
nsIRDFObserver.idl
nsIRDFPurgeableDataSource.idl
nsIRDFRemoteDataSource.idl
nsIRDFResource.idl
nsIRDFService.idl
nsIRDFXMLDataSource.idl
nsIRDFXMLSink.idl
nsIRDFXMLSource.idl
xulstubs.idl

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

@ -32,11 +32,12 @@ XPIDLSRCS = \
nsIRDFNode.idl \
nsIRDFObserver.idl \
nsIRDFPurgeableDataSource.idl \
nsIRDFRemoteDataSource.idl \
nsIRDFResource.idl \
nsIRDFService.idl \
nsIRDFXMLDataSource.idl \
nsIRDFXMLSink.idl \
nsIRDFXMLSource.idl \
nsIController.idl \
nsIController.idl \
nsIGenericCommandSet.idl \
xulstubs.idl \
$(NULL)

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

@ -28,11 +28,12 @@ XPIDLSRCS= .\nsIRDFNode.idl \
.\nsIRDFContainer.idl \
.\nsIRDFContainerUtils.idl \
.\nsIRDFPurgeableDataSource.idl \
.\nsIRDFXMLDataSource.idl \
.\nsIRDFRemoteDataSource.idl \
.\nsIRDFXMLSink.idl \
.\nsIRDFXMLSource.idl \
.\nsIController.idl \
.\nsIGenericCommandSet.idl \
.\xulstubs.idl \
.\nsIController.idl \
.\nsIGenericCommandSet.idl \
.\xulstubs.idl \
$(NULL)
include <$(DEPTH)\config\rules.mak>

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

@ -20,7 +20,6 @@
#include "nsIRDFResource.idl"
#include "nsIRDFNode.idl"
#include "nsIEnumerator.idl"
#include "nsIEnumerator.idl"
#include "nsIRDFObserver.idl"
// XXX Because this isn't really and interface :(
@ -32,107 +31,159 @@
[scriptable, uuid(0F78DA58-8321-11d2-8EAC-00805F29F370)]
interface nsIRDFDataSource : nsISupports
{
// Specify the URI for the data source: this is the prefix
// that will be used to register the data source in the
// data source registry.
void Init(in string uri);
// The URI of the data source.
/** The "URI" of the data source. This used by the RDF service's
* |GetDataSource()| method to cache datasources.
*/
readonly attribute string URI;
// Find an RDF resource that points to a given node over the
// specified arc & truth value
//
// @return NS_RDF_NO_VALUE if there is no source that leads
// to the target with the specified property.
/** Find an RDF resource that points to a given node over the
* specified arc & truth value
*
* @return NS_RDF_NO_VALUE if there is no source that leads
* to the target with the specified property.
*/
nsIRDFResource GetSource(in nsIRDFResource aProperty,
in nsIRDFNode aTarget,
in boolean aTruthValue);
// Find all RDF resources that point to a given node over the
// specified arc & truth value
//
// @return NS_OK unless a catastrophic error occurs. If the
// method returns NS_OK, you may assume that nsISimpleEnumerator points
// to a valid (but possibly empty) cursor.
/**
* Find all RDF resources that point to a given node over the
* specified arc & truth value
*
* @return NS_OK unless a catastrophic error occurs. If the
* method returns NS_OK, you may assume that nsISimpleEnumerator points
* to a valid (but possibly empty) cursor.
*/
nsISimpleEnumerator GetSources(in nsIRDFResource aProperty,
in nsIRDFNode aTarget,
in boolean aTruthValue);
// Find a child of that is related to the source by the given arc
// arc and truth value
//
// @return NS_RDF_NO_VALUE if there is no target accessable from the
// source via the specified property.
/**
* Find a child of that is related to the source by the given arc
* arc and truth value
*
* @return NS_RDF_NO_VALUE if there is no target accessable from the
* source via the specified property.
*/
nsIRDFNode GetTarget(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in boolean aTruthValue);
// Find all children of that are related to the source by the given arc
// arc and truth value.
//
// @return NS_OK unless a catastrophic error occurs. If the
// method returns NS_OK, you may assume that nsISimpleEnumerator points
// to a valid (but possibly empty) cursor.
/**
* Find all children of that are related to the source by the given arc
* arc and truth value.
*
* @return NS_OK unless a catastrophic error occurs. If the
* method returns NS_OK, you may assume that nsISimpleEnumerator points
* to a valid (but possibly empty) cursor.
*/
nsISimpleEnumerator GetTargets(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in boolean aTruthValue);
// Add an assertion to the graph.
/**
* Add an assertion to the graph.
*/
void Assert(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget,
in boolean aTruthValue);
// Remove an assertion from the graph.
/**
* Remove an assertion from the graph.
*/
void Unassert(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget);
// Query whether an assertion exists in this graph.
/**
* Change an assertion from
*
* [aSource]--[aProperty]-->[aOldTarget]
*
* to
*
* [aSource]--[aProperty]-->[aNewTarget]
*/
void Change(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aOldTarget,
in nsIRDFNode aNewTarget);
/**
* 'Move' an assertion from
*
* [aOldSource]--[aProperty]-->[aTarget]
*
* to
*
* [aNewSource]--[aProperty]-->[aTarget]
*/
void Move(in nsIRDFResource aOldSource,
in nsIRDFResource aNewSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget);
/**
* Query whether an assertion exists in this graph.
*/
boolean HasAssertion(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget,
in boolean aTruthValue);
// Add an observer to this data source.
/**
* Add an observer to this data source. If the datasource
* supports observers, the datasource source should hold a strong
* reference to the observer.
*/
void AddObserver(in nsIRDFObserver aObserver);
// Remove an observer from this data source
/**
* Remove an observer from this data source.
*/
void RemoveObserver(in nsIRDFObserver aObserver);
// Get a cursor to iterate over all the arcs that point into a node.
//
// @return NS_OK unless a catastrophic error occurs. If the method
// returns NS_OK, you may assume that labels points to a valid (but
// possible empty) nsISimpleEnumerator object.
/**
* Get a cursor to iterate over all the arcs that point into a node.
*
* @return NS_OK unless a catastrophic error occurs. If the method
* returns NS_OK, you may assume that labels points to a valid (but
* possible empty) nsISimpleEnumerator object.
*/
nsISimpleEnumerator ArcLabelsIn(in nsIRDFNode aNode);
// Get a cursor to iterate over all the arcs that originate in
// a resource.
//
// @return NS_OK unless a catastrophic error occurs. If the method
// returns NS_OK, you may assume that labels points to a valid (but
// possible empty) nsISimpleEnumerator object.
/**
* Get a cursor to iterate over all the arcs that originate in
* a resource.
*
* @return NS_OK unless a catastrophic error occurs. If the method
* returns NS_OK, you may assume that labels points to a valid (but
* possible empty) nsISimpleEnumerator object.
*/
nsISimpleEnumerator ArcLabelsOut(in nsIRDFResource aSource);
// Retrieve all of the resources that the data source currently
// refers to.
/**
* Retrieve all of the resources that the data source currently
* refers to.
*/
nsISimpleEnumerator GetAllResources();
// Request that a data source write it's contents out to
// permanent storage if applicable.
void Flush();
// Returns the set of all commands defined for a given source.
/**
* Returns the set of all commands defined for a given source.
*/
nsIEnumerator GetAllCommands(in nsIRDFResource aSource);
// Returns whether a given command is enabled for a set of sources.
/**
* Returns whether a given command is enabled for a set of sources.
*/
boolean IsCommandEnabled(in nsISupportsArray aSources,
in nsIRDFResource aCommand,
in nsISupportsArray aArguments);
// Perform the specified command on set of sources.
/**
* Perform the specified command on set of sources.
*/
void DoCommand(in nsISupportsArray aSources,
in nsIRDFResource aCommand,
in nsISupportsArray aArguments);

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

@ -27,14 +27,24 @@ interface nsIRDFObserver : nsISupports {
// This method is called whenever a new assertion is made
// in the data source
void OnAssert(in nsIRDFResource aSource,
in nsIRDFResource aLabel,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget);
// This method is called whenever an assertion is removed
// from the data source
void OnUnassert(in nsIRDFResource aSource,
in nsIRDFResource aLabel,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget);
void OnChange(in nsIRDFResource aSource,
in nsIRDFResource aProperty,
in nsIRDFNode aOldTarget,
in nsIRDFNode aNewTarget);
void OnMove(in nsIRDFResource aOldSource,
in nsIRDFResource aNewSource,
in nsIRDFResource aProperty,
in nsIRDFNode aTarget);
};

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

@ -0,0 +1,34 @@
/* -*- 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.
*/
#include "nsISupports.idl"
[scriptable, uuid(1D297320-27F7-11d3-BE01-000064657374)]
interface nsIRDFRemoteDataSource : nsISupports
{
// Specify the URI for the data source: this is the prefix
// that will be used to register the data source in the
// data source registry.
void Init(in string uri);
void Refresh(in boolean aBlocking);
// Request that a data source write it's contents out to
// permanent storage if applicable.
void Flush();
};

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

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

@ -0,0 +1,57 @@
/* -*- 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.
*/
#include "nsISupports.idl"
// XXX Until these get scriptable. See nsIRDFXMLSink::AddNameSpace()
[ptr] native nsIAtomPtr(nsIAtom);
[ref] native nsStringRef(nsString);
%{C++
class nsIAtom;
class nsString;
%}
interface nsIRDFXMLSink;
[scriptable, uuid(EB1A5D30-AB33-11D2-8EC6-00805F29F370)]
interface nsIRDFXMLSinkObserver : nsISupports
{
void OnBeginLoad(in nsIRDFXMLSink aSink);
void OnInterrupt(in nsIRDFXMLSink aSink);
void OnResume(in nsIRDFXMLSink aSink);
void OnEndLoad(in nsIRDFXMLSink aSink);
};
[scriptable, uuid(EB1A5D31-AB33-11D2-8EC6-00805F29F370)]
interface nsIRDFXMLSink : nsISupports
{
attribute boolean ReadOnly;
void BeginLoad();
void Interrupt();
void Resume();
void EndLoad();
void AddNameSpace(in nsIAtomPtr aPrefix, [const] in nsStringRef aURI);
void AddXMLSinkObserver(in nsIRDFXMLSinkObserver aObserver);
void RemoveXMLSinkObserver(in nsIRDFXMLSinkObserver aObserver);
};

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

@ -29,7 +29,7 @@
#include "nsIXMLContentSink.h"
class nsIDocument;
class nsIRDFXMLDataSource;
class nsIRDFDataSource;
class nsINameSpaceManager;
class nsIURI;
@ -53,12 +53,12 @@ public:
/**
* Set the content sink's RDF Data source
*/
NS_IMETHOD SetDataSource(nsIRDFXMLDataSource* aDataSource) = 0;
NS_IMETHOD SetDataSource(nsIRDFDataSource* aDataSource) = 0;
/**
* Retrieve the content sink's RDF data source.
*/
NS_IMETHOD GetDataSource(nsIRDFXMLDataSource*& rDataSource) = 0;
NS_IMETHOD GetDataSource(nsIRDFDataSource*& rDataSource) = 0;
};

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

@ -45,6 +45,7 @@
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFObserver.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h"
#include "rdf.h"
@ -74,8 +75,6 @@ public:
NS_DECL_ISUPPORTS
// nsIRDFDataSource interface
NS_IMETHOD Init(const char* uri);
NS_IMETHOD GetURI(char* *uri);
NS_IMETHOD GetSource(nsIRDFResource* property,
@ -107,15 +106,25 @@ public:
nsIRDFResource* property,
nsIRDFNode* target);
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion);
NS_IMETHOD AddObserver(nsIRDFObserver* n);
NS_IMETHOD AddObserver(nsIRDFObserver* aObserver);
NS_IMETHOD RemoveObserver(nsIRDFObserver* n);
NS_IMETHOD RemoveObserver(nsIRDFObserver* aObserver);
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsISimpleEnumerator** labels);
@ -152,13 +161,23 @@ public:
nsIRDFResource* predicate,
nsIRDFNode* object);
NS_IMETHOD OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
// Implementation methods
PRBool HasAssertionN(int n, nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv);
protected:
nsVoidArray* mObservers;
nsCOMPtr<nsISupportsArray> mObservers;
virtual ~CompositeDataSourceImpl(void);
};
@ -545,7 +564,6 @@ NS_NewRDFCompositeDataSource(nsIRDFCompositeDataSource** result)
CompositeDataSourceImpl::CompositeDataSourceImpl(void)
: mObservers(nsnull)
{
NS_INIT_REFCNT();
@ -558,19 +576,42 @@ CompositeDataSourceImpl::CompositeDataSourceImpl(void)
CompositeDataSourceImpl::~CompositeDataSourceImpl(void)
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
ds->RemoveObserver(this);
NS_IF_RELEASE(ds);
}
delete mObservers;
}
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMPL_ADDREF(CompositeDataSourceImpl);
NS_IMPL_RELEASE(CompositeDataSourceImpl);
NS_IMETHODIMP_(nsrefcnt)
CompositeDataSourceImpl::Release()
{
// We need a special implementation of Release() because the
// composite datasource holds a reference to each datasource that
// it "composes", and each database that the composite datasource
// observes holds a reference _back_ to the composite datasource.
NS_PRECONDITION(PRInt32(mRefCnt) > 0, "duplicate release");
--mRefCnt;
// When the number of references == the number of datasources,
// then we know that all that remains are the circular
// references from those datasources back to us. Release them.
if (PRInt32(mRefCnt) == mDataSources.Count()) {
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
ds->RemoveObserver(this);
NS_RELEASE(ds);
}
return 0;
}
else if (mRefCnt == 0) {
delete this;
return 0;
}
else {
return mRefCnt;
}
}
NS_IMETHODIMP
CompositeDataSourceImpl::QueryInterface(REFNSIID iid, void** result)
@ -601,18 +642,11 @@ CompositeDataSourceImpl::QueryInterface(REFNSIID iid, void** result)
////////////////////////////////////////////////////////////////////////
// nsIRDFDataSource interface
NS_IMETHODIMP
CompositeDataSourceImpl::Init(const char* uri)
{
NS_NOTREACHED("CompositeDataSourceImpl::Init");
return NS_ERROR_UNEXPECTED; // XXX CompositeDataSourceImpl doesn't have a URI?
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetURI(char* *uri)
{
NS_NOTREACHED("CompositeDataSourceImpl::GetURI");
return NS_ERROR_UNEXPECTED; // XXX CompositeDataSourceImpl doesn't have a URI?
*uri = nsnull;
return NS_OK;
}
NS_IMETHODIMP
@ -871,6 +905,27 @@ CompositeDataSourceImpl::Unassert(nsIRDFResource* aSource,
return NS_RDF_ASSERTION_REJECTED;
}
NS_IMETHODIMP
CompositeDataSourceImpl::Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
CompositeDataSourceImpl::Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
CompositeDataSourceImpl::HasAssertion(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
@ -926,8 +981,9 @@ CompositeDataSourceImpl::AddObserver(nsIRDFObserver* aObserver)
return NS_ERROR_NULL_POINTER;
if (!mObservers) {
if ((mObservers = new nsVoidArray()) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
rv = NS_NewISupportsArray(getter_AddRefs(mObservers));
if (NS_FAILED(rv)) return rv;
}
// XXX ensure uniqueness?
@ -1007,7 +1063,9 @@ CompositeDataSourceImpl::Flush()
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
ds->Flush();
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(ds);
if (remote)
remote->Flush();
}
return NS_OK;
}
@ -1162,9 +1220,14 @@ CompositeDataSourceImpl::OnAssert(nsIRDFResource* aSource,
return NS_OK;
if (mObservers) {
for (PRInt32 i = mObservers->Count() - 1; i >= 0; --i) {
PRUint32 count;
rv = mObservers->Count(&count);
if (NS_FAILED(rv)) return rv;
for (PRInt32 i = PRInt32(count) - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnAssert(aSource, aProperty, aTarget);
NS_RELEASE(obs);
// XXX ignore return value?
}
}
@ -1183,8 +1246,6 @@ CompositeDataSourceImpl::OnUnassert(nsIRDFResource* aSource,
// datasource actually served up the OnAssert(): we could use
// HasAssertionN() to only search datasources _before_ the
// datasource that coughed up the assertion.
//
// XXX What if the unassertion
nsresult rv;
PRBool hasAssertion;
rv = HasAssertion(aSource, aProperty, aTarget, PR_TRUE, &hasAssertion);
@ -1194,9 +1255,70 @@ CompositeDataSourceImpl::OnUnassert(nsIRDFResource* aSource,
return NS_OK;
if (mObservers) {
for (PRInt32 i = mObservers->Count() - 1; i >= 0; --i) {
PRUint32 count;
rv = mObservers->Count(&count);
if (NS_FAILED(rv)) return rv;
for (PRInt32 i = PRInt32(count) - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnUnassert(aSource, aProperty, aTarget);
NS_RELEASE(obs);
// XXX ignore return value?
}
}
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
// Make sure that the change is actually visible, and not hidden
// by an assertion in a different datasource.
//
// XXX Because of aggregation, this could actually mutate into a
// variety of OnAssert or OnChange notifications, which we'll
// ignore for now :-/.
if (mObservers) {
PRUint32 count;
nsresult rv = mObservers->Count(&count);
if (NS_FAILED(rv)) return rv;
for (PRInt32 i = PRInt32(count) - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnChange(aSource, aProperty, aOldTarget, aNewTarget);
NS_RELEASE(obs);
// XXX ignore return value?
}
}
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
// Make sure that the move is actually visible, and not hidden
// by an assertion in a different datasource.
//
// XXX Because of aggregation, this could actually mutate into a
// variety of OnAssert or OnMove notifications, which we'll
// ignore for now :-/.
if (mObservers) {
PRUint32 count;
nsresult rv = mObservers->Count(&count);
if (NS_FAILED(rv)) return rv;
for (PRInt32 i = PRInt32(count) - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnMove(aOldSource, aNewSource, aProperty, aTarget);
NS_RELEASE(obs);
// XXX ignore return value?
}
}
@ -1205,3 +1327,6 @@ CompositeDataSourceImpl::OnUnassert(nsIRDFResource* aSource,

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

@ -49,6 +49,7 @@
#include "nsEnumeratorUtils.h"
#include "nsVoidArray.h" // XXX introduces dependency on raptorbase
#include "nsRDFCID.h"
#include "nsRDFBaseDataSources.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "rdfutil.h"
@ -155,8 +156,6 @@ class InMemoryDataSource : public nsIRDFDataSource,
public nsIRDFPurgeableDataSource
{
protected:
char* mURL;
// These hash tables are keyed on pointers to nsIRDFResource
// objects (the nsIRDFService ensures that there is only ever one
// nsIRDFResource object per unique URI). The value of an entry is
@ -165,7 +164,7 @@ protected:
PLHashTable* mForwardArcs;
PLHashTable* mReverseArcs;
nsVoidArray* mObservers;
nsCOMPtr<nsISupportsArray> mObservers;
static const PRInt32 kInitialTableSize;
@ -200,8 +199,6 @@ public:
NS_DECL_ISUPPORTS
// nsIRDFDataSource methods
NS_IMETHOD Init(const char* uri);
NS_IMETHOD GetURI(char* *uri);
NS_IMETHOD GetSource(nsIRDFResource* property,
@ -233,6 +230,16 @@ public:
nsIRDFResource* property,
nsIRDFNode* target);
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
@ -604,12 +611,10 @@ NS_NewRDFInMemoryDataSource(nsISupports* aOuter, const nsIID& aIID, void** aResu
InMemoryDataSource::InMemoryDataSource(nsISupports* aOuter)
: mURL(nsnull),
mForwardArcs(nsnull),
: mForwardArcs(nsnull),
mReverseArcs(nsnull),
mObservers(nsnull),
mLock(nsnull),
mOuter(aOuter)
mOuter(aOuter),
mLock(nsnull)
{
NS_INIT_REFCNT();
}
@ -668,12 +673,9 @@ InMemoryDataSource::~InMemoryDataSource()
mReverseArcs = nsnull;
}
delete mObservers; // we only hold a weak ref to each observer
PR_LOG(gLog, PR_LOG_ALWAYS,
("InMemoryDataSource(%s): destroyed.", mURL));
("InMemoryDataSource(%p): destroyed.", this));
if (mURL) PL_strfree(mURL);
PR_DestroyLock(mLock);
}
@ -806,7 +808,7 @@ InMemoryDataSource::LogOperation(const char* aOperation,
nsXPIDLCString uri;
aSource->GetValue(getter_Copies(uri));
PR_LOG(gLog, PR_LOG_ALWAYS,
("InMemoryDataSource(%s): %s", mURL, aOperation));
("InMemoryDataSource(%p): %s", this, aOperation));
PR_LOG(gLog, PR_LOG_ALWAYS,
(" [(%p)%s]--", aSource, (const char*) uri));
@ -844,18 +846,6 @@ InMemoryDataSource::LogOperation(const char* aOperation,
#endif
NS_IMETHODIMP
InMemoryDataSource::Init(const char* uri)
{
if ((mURL = PL_strdup(uri)) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
PR_LOG(gLog, PR_LOG_ALWAYS,
("InMemoryDataSource(%s): initialized.", mURL));
return NS_OK;
}
NS_IMETHODIMP
InMemoryDataSource::GetURI(char* *uri)
{
@ -863,10 +853,8 @@ InMemoryDataSource::GetURI(char* *uri)
if (! uri)
return NS_ERROR_NULL_POINTER;
if ((*uri = nsXPIDLCString::Copy(mURL)) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
else
return NS_OK;
*uri = nsnull;
return NS_OK;
}
NS_IMETHODIMP
@ -1126,9 +1114,14 @@ InMemoryDataSource::Assert(nsIRDFResource* source,
// notify observers
if (mObservers) {
for (PRInt32 i = mObservers->Count() - 1; i >= 0; --i) {
PRUint32 count;
rv = mObservers->Count(&count);
if (NS_FAILED(rv)) return rv;
for (PRInt32 i = PRInt32(count) - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnAssert(source, property, target);
NS_RELEASE(obs);
// XXX ignore return value?
}
}
@ -1221,9 +1214,14 @@ InMemoryDataSource::Unassert(nsIRDFResource* source,
// Notify the world
if (mObservers) {
for (PRInt32 i = mObservers->Count() - 1; i >= 0; --i) {
PRUint32 count;
rv = mObservers->Count(&count);
if (NS_FAILED(rv)) return rv;
for (PRInt32 i = PRInt32(count) - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnUnassert(source, property, target);
NS_RELEASE(obs);
// XXX ignore return value?
}
}
@ -1232,6 +1230,28 @@ InMemoryDataSource::Unassert(nsIRDFResource* source,
}
NS_IMETHODIMP
InMemoryDataSource::Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
InMemoryDataSource::Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
InMemoryDataSource::AddObserver(nsIRDFObserver* observer)
{
@ -1242,8 +1262,9 @@ InMemoryDataSource::AddObserver(nsIRDFObserver* observer)
NS_AUTOLOCK(mLock);
if (! mObservers) {
if ((mObservers = new nsVoidArray()) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
rv = NS_NewISupportsArray(getter_AddRefs(mObservers));
if (NS_FAILED(rv)) return rv;
}
mObservers->AppendElement(observer);
@ -1468,10 +1489,15 @@ InMemoryDataSource::Sweep()
#endif
if (mObservers) {
for (PRInt32 i = mObservers->Count() - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnUnassert(as->mSource, as->mProperty, as->mTarget);
// XXX ignore return value?
nsresult rv;
PRUint32 count;
rv = mObservers->Count(&count);
if (NS_SUCCEEDED(rv)) {
for (PRInt32 i = PRInt32(count) - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnUnassert(as->mSource, as->mProperty, as->mTarget);
// XXX ignore return value?
}
}
}

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

@ -36,6 +36,10 @@ class nsIRDFDataSource;
NS_IMETHODIMP
NS_NewRDFInMemoryDataSource(nsISupports* aOuter, const nsIID& aIID, void** aResult);
// in nsRDFXMLDataSource.cpp
extern nsresult
NS_NewRDFXMLDataSource(nsIRDFDataSource** aResult);
#endif // nsBaseDataSources_h__

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

@ -61,7 +61,7 @@
#include "nsIRDFContentSink.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIRDFXMLSink.h"
#include "nsIServiceManager.h"
#include "nsIURL.h"
#include "nsIXMLContentSink.h"
@ -173,8 +173,8 @@ public:
// nsIRDFContentSink
NS_IMETHOD Init(nsIURI* aURL, nsINameSpaceManager* aNameSpaceManager);
NS_IMETHOD SetDataSource(nsIRDFXMLDataSource* ds);
NS_IMETHOD GetDataSource(nsIRDFXMLDataSource*& ds);
NS_IMETHOD SetDataSource(nsIRDFDataSource* aDataSource);
NS_IMETHOD GetDataSource(nsIRDFDataSource*& aDataSource);
protected:
// pseudo constants
@ -239,9 +239,11 @@ protected:
virtual nsresult OpenMember(const nsIParserNode& aNode);
virtual nsresult OpenValue(const nsIParserNode& aNode);
// Miscellaneous RDF junk
nsIRDFXMLDataSource* mDataSource;
RDFContentSinkState mState;
// The datasource in which we're assigning assertions
nsCOMPtr<nsIRDFDataSource> mDataSource;
// The current state of the content sink
RDFContentSinkState mState;
// content stack management
PRInt32 PushContext(nsIRDFResource *aContext, RDFContentSinkState aState);
@ -326,8 +328,6 @@ RDFContentSinkImpl::~RDFContentSinkImpl()
{
NS_IF_RELEASE(mDocumentURL);
NS_IF_RELEASE(mDataSource);
NS_IF_RELEASE(mNameSpaceManager);
if (mNameSpaceStack) {
// There shouldn't be any here except in an error condition
@ -431,25 +431,45 @@ RDFContentSinkImpl::QueryInterface(REFNSIID iid, void** result)
NS_IMETHODIMP
RDFContentSinkImpl::WillBuildModel(void)
{
return (mDataSource != nsnull) ? mDataSource->BeginLoad() : NS_OK;
if (mDataSource) {
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource);
if (sink)
return sink->BeginLoad();
}
return NS_OK;
}
NS_IMETHODIMP
RDFContentSinkImpl::DidBuildModel(PRInt32 aQualityLevel)
{
return (mDataSource != nsnull) ? mDataSource->EndLoad() : NS_OK;
if (mDataSource) {
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource);
if (sink)
return sink->EndLoad();
}
return NS_OK;
}
NS_IMETHODIMP
RDFContentSinkImpl::WillInterrupt(void)
{
return (mDataSource != nsnull) ? mDataSource->Interrupt() : NS_OK;
if (mDataSource) {
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource);
if (sink)
return sink->Interrupt();
}
return NS_OK;
}
NS_IMETHODIMP
RDFContentSinkImpl::WillResume(void)
{
return (mDataSource != nsnull) ? mDataSource->Resume() : NS_OK;
if (mDataSource) {
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource);
if (sink)
return sink->Resume();
}
return NS_OK;
}
NS_IMETHODIMP
@ -730,20 +750,18 @@ RDFContentSinkImpl::Init(nsIURI* aURL, nsINameSpaceManager* aNameSpaceManager)
}
NS_IMETHODIMP
RDFContentSinkImpl::SetDataSource(nsIRDFXMLDataSource* ds)
RDFContentSinkImpl::SetDataSource(nsIRDFDataSource* aDataSource)
{
NS_IF_RELEASE(mDataSource);
mDataSource = ds;
NS_IF_ADDREF(mDataSource);
mDataSource = dont_QueryInterface(aDataSource);
return NS_OK;
}
NS_IMETHODIMP
RDFContentSinkImpl::GetDataSource(nsIRDFXMLDataSource*& ds)
RDFContentSinkImpl::GetDataSource(nsIRDFDataSource*& aDataSource)
{
ds = mDataSource;
NS_IF_ADDREF(mDataSource);
aDataSource = mDataSource;
NS_IF_ADDREF(aDataSource);
return NS_OK;
}
@ -1457,7 +1475,9 @@ RDFContentSinkImpl::PushNameSpacesFrom(const nsIParserNode& aNode)
}
// Add it to the set of namespaces used in the RDF/XML document.
mDataSource->AddNameSpace(prefixAtom, uri);
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource);
if (sink)
sink->AddNameSpace(prefixAtom, uri);
NS_IF_RELEASE(prefixAtom);
}

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

@ -35,7 +35,7 @@
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "nsString.h"
@ -48,7 +48,7 @@
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
@ -844,6 +844,8 @@ ServiceImpl::UnregisterDataSource(nsIRDFDataSource* aDataSource)
NS_IMETHODIMP
ServiceImpl::GetDataSource(const char* uri, nsIRDFDataSource** aDataSource)
{
nsresult rv;
// First, check the cache to see if we already have this
// datasource loaded and initialized.
{
@ -851,6 +853,12 @@ ServiceImpl::GetDataSource(const char* uri, nsIRDFDataSource** aDataSource)
NS_STATIC_CAST(nsIRDFDataSource*, PL_HashTableLookup(mNamedDataSources, uri));
if (cached) {
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(cached);
if (remote) {
rv = remote->Refresh(PR_FALSE);
if (NS_FAILED(rv)) return rv;
}
NS_ADDREF(cached);
*aDataSource = cached;
return NS_OK;
@ -858,7 +866,6 @@ ServiceImpl::GetDataSource(const char* uri, nsIRDFDataSource** aDataSource)
}
// Nope. So go to the repository to try to create it.
nsresult rv;
nsCOMPtr<nsIRDFDataSource> ds;
nsAutoString rdfName(uri);
static const char kRDFPrefix[] = "rdf:";
@ -898,8 +905,11 @@ ServiceImpl::GetDataSource(const char* uri, nsIRDFDataSource** aDataSource)
ds = do_QueryInterface(isupports, &rv);
if (NS_FAILED(rv)) return rv;
rv = ds->Init(uri);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(ds);
if (remote) {
rv = remote->Init(uri);
if (NS_FAILED(rv)) return rv;
}
}
else {
// Try to load this as an RDF/XML data source
@ -910,17 +920,17 @@ ServiceImpl::GetDataSource(const char* uri, nsIRDFDataSource** aDataSource)
if (NS_FAILED(rv)) return rv;
rv = ds->Init(uri);
if (NS_FAILED(rv)) return rv;
// Start the datasource load asynchronously. If you wanted it
// loaded synchronously, then you should've tried to do it
// yourself.
nsCOMPtr<nsIRDFXMLDataSource> rdfxmlDataSource(do_QueryInterface(ds));
NS_ASSERTION(rdfxmlDataSource, "not an RDF/XML data source!");
if (! rdfxmlDataSource) return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(ds));
NS_ASSERTION(remote, "not a remote RDF/XML data source!");
if (! remote) return NS_ERROR_UNEXPECTED;
rv = rdfxmlDataSource->Open(PR_FALSE);
rv = remote->Init(uri);
if (NS_FAILED(rv)) return rv;
rv = remote->Refresh(PR_FALSE);
if (NS_FAILED(rv)) return rv;
}

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

@ -71,8 +71,9 @@
#include "nsIRDFContainerUtils.h"
#include "nsIRDFContentSink.h"
#include "nsIRDFNode.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIRDFXMLSink.h"
#include "nsIRDFXMLSource.h"
#include "nsIServiceManager.h"
#include "nsIStreamListener.h"
@ -85,6 +86,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
#include "nsLayoutCID.h" // for NS_NAMESPACEMANAGER_CID.
#include "nsParserCIID.h"
#include "nsRDFCID.h"
#include "nsRDFBaseDataSources.h"
#include "nsVoidArray.h"
#include "nsXPIDLString.h"
#include "plstr.h"
@ -100,13 +102,6 @@ static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
static NS_DEFINE_IID(kIInputStreamIID, NS_IINPUTSTREAM_IID);
static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kIRDFContentSinkIID, NS_IRDFCONTENTSINK_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kIRDFXMLDataSourceIID, NS_IRDFXMLDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFXMLSourceIID, NS_IRDFXMLSOURCE_IID);
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@ -176,7 +171,9 @@ NS_IMPL_ISUPPORTS(ProxyStream, kIInputStreamIID);
////////////////////////////////////////////////////////////////////////
// RDFXMLDataSourceImpl
class RDFXMLDataSourceImpl : public nsIRDFXMLDataSource,
class RDFXMLDataSourceImpl : public nsIRDFDataSource,
public nsIRDFRemoteDataSource,
public nsIRDFXMLSink,
public nsIRDFXMLSource
{
protected:
@ -193,6 +190,7 @@ protected:
PRBool mIsLoading; // true while the document is loading
NameSpaceMap* mNameSpaces;
nsCOMPtr<nsIURI> mURL;
char* mURLSpec;
// pseudo-constants
static PRInt32 gRefCnt;
@ -208,18 +206,14 @@ protected:
virtual ~RDFXMLDataSourceImpl(void);
friend nsresult
NS_NewRDFXMLDataSource(nsIRDFXMLDataSource** aResult);
NS_NewRDFXMLDataSource(nsIRDFDataSource** aResult);
public:
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFDataSource
NS_IMETHOD Init(const char* uri);
NS_IMETHOD GetURI(char* *uri) {
return mInner->GetURI(uri);
}
NS_IMETHOD GetURI(char* *uri);
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
@ -258,6 +252,16 @@ public:
nsIRDFResource* property,
nsIRDFNode* target);
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
@ -288,8 +292,6 @@ public:
return mInner->GetAllResources(aResult);
}
NS_IMETHOD Flush(void);
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands) {
return mInner->GetAllCommands(source, commands);
@ -310,17 +312,21 @@ public:
return mInner->DoCommand(aSources, aCommand, aArguments);
}
// nsIRDFXMLDataSource interface
// nsIRDFRemoteDataSource interface
NS_IMETHOD Init(const char* uri);
NS_IMETHOD Refresh(PRBool aBlocking);
NS_IMETHOD Flush(void);
// nsIRDFXMLSink interface
NS_IMETHOD GetReadOnly(PRBool* aIsReadOnly);
NS_IMETHOD SetReadOnly(PRBool aIsReadOnly);
NS_IMETHOD Open(PRBool aBlocking);
NS_IMETHOD BeginLoad(void);
NS_IMETHOD Interrupt(void);
NS_IMETHOD Resume(void);
NS_IMETHOD EndLoad(void);
NS_IMETHOD AddNameSpace(nsIAtom* aPrefix, const nsString& aURI);
NS_IMETHOD AddXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver);
NS_IMETHOD RemoveXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver);
NS_IMETHOD AddXMLSinkObserver(nsIRDFXMLSinkObserver* aObserver);
NS_IMETHOD RemoveXMLSinkObserver(nsIRDFXMLSinkObserver* aObserver);
// nsIRDFXMLSource interface
NS_IMETHOD Serialize(nsIOutputStream* aStream);
@ -377,7 +383,7 @@ nsIRDFResource* RDFXMLDataSourceImpl::kRDF_Alt;
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFXMLDataSource(nsIRDFXMLDataSource** aResult)
NS_NewRDFXMLDataSource(nsIRDFDataSource** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
@ -406,7 +412,8 @@ RDFXMLDataSourceImpl::RDFXMLDataSourceImpl(void)
mIsWritable(PR_TRUE),
mIsDirty(PR_FALSE),
mIsLoading(PR_FALSE),
mNameSpaces(nsnull)
mNameSpaces(nsnull),
mURLSpec(nsnull)
{
NS_INIT_REFCNT();
}
@ -418,7 +425,7 @@ RDFXMLDataSourceImpl::Init()
nsresult rv;
rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
nsIRDFDataSource::GetIID(),
(void**) &mInner);
if (NS_FAILED(rv)) return rv;
@ -462,6 +469,8 @@ RDFXMLDataSourceImpl::~RDFXMLDataSourceImpl(void)
rdf->UnregisterDataSource(this);
}
if (mURLSpec) PL_strfree(mURLSpec);
Flush();
while (mNameSpaces) {
@ -491,27 +500,32 @@ NS_IMPL_ADDREF(RDFXMLDataSourceImpl);
NS_IMPL_RELEASE(RDFXMLDataSourceImpl);
NS_IMETHODIMP
RDFXMLDataSourceImpl::QueryInterface(REFNSIID iid, void** result)
RDFXMLDataSourceImpl::QueryInterface(REFNSIID aIID, void** aResult)
{
if (! result)
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kISupportsIID) ||
iid.Equals(kIRDFDataSourceIID) ||
iid.Equals(kIRDFXMLDataSourceIID)) {
*result = NS_STATIC_CAST(nsIRDFDataSource*, this);
NS_ADDREF(this);
return NS_OK;
if (aIID.Equals(kISupportsIID) ||
aIID.Equals(nsIRDFDataSource::GetIID())) {
*aResult = NS_STATIC_CAST(nsIRDFDataSource*, this);
}
else if (iid.Equals(kIRDFXMLSourceIID)) {
*result = NS_STATIC_CAST(nsIRDFXMLSource*, this);
NS_ADDREF(this);
return NS_OK;
else if (aIID.Equals(nsIRDFRemoteDataSource::GetIID())) {
*aResult = NS_STATIC_CAST(nsIRDFRemoteDataSource*, this);
}
else if (aIID.Equals(nsIRDFXMLSink::GetIID())) {
*aResult = NS_STATIC_CAST(nsIRDFXMLSink*, this);
}
else if (aIID.Equals(nsIRDFXMLSource::GetIID())) {
*aResult = NS_STATIC_CAST(nsIRDFXMLSource*, this);
}
else {
*result = nsnull;
*aResult = nsnull;
return NS_NOINTERFACE;
}
NS_ADDREF(this);
return NS_OK;
}
@ -604,8 +618,12 @@ static const char kResourceURIPrefix[] = "resource:";
mIsWritable = PR_FALSE;
}
rv = mInner->Init(realURL);
if (NS_FAILED(rv)) return rv;
// XXX Keep a 'cached' copy of the URL; opening it may cause the
// spec to be re-written.
if (mURLSpec)
PL_strfree(mURLSpec);
mURLSpec = PL_strdup(realURL);
NS_WITH_SERVICE(nsIRDFService, rdf, kRDFServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
@ -617,6 +635,20 @@ static const char kResourceURIPrefix[] = "resource:";
}
NS_IMETHODIMP
RDFXMLDataSourceImpl::GetURI(char* *aURI)
{
*aURI = nsnull;
if (mURLSpec) {
// XXX We don't use the mURL, because it might get re-written
// when it's actually opened.
*aURI = nsXPIDLCString::Copy(mURLSpec);
if (! *aURI)
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
NS_IMETHODIMP
RDFXMLDataSourceImpl::Assert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
@ -687,6 +719,54 @@ RDFXMLDataSourceImpl::Unassert(nsIRDFResource* source,
return rv;
}
NS_IMETHODIMP
RDFXMLDataSourceImpl::Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
nsresult rv;
if (mIsLoading) {
NS_NOTYETIMPLEMENTED("hmm, why is this being called?");
return NS_ERROR_NOT_IMPLEMENTED;
}
else if (mIsWritable) {
rv = mInner->Change(aSource, aProperty, aOldTarget, aNewTarget);
if (rv == NS_RDF_ASSERTION_ACCEPTED)
mIsDirty = PR_TRUE;
return rv;
}
else {
return NS_RDF_ASSERTION_REJECTED;
}
}
NS_IMETHODIMP
RDFXMLDataSourceImpl::Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
nsresult rv;
if (mIsLoading) {
NS_NOTYETIMPLEMENTED("hmm, why is this being called?");
return NS_ERROR_NOT_IMPLEMENTED;
}
else if (mIsWritable) {
rv = mInner->Move(aOldSource, aNewSource, aProperty, aTarget);
if (rv == NS_RDF_ASSERTION_ACCEPTED)
mIsDirty = PR_TRUE;
return rv;
}
else {
return NS_RDF_ASSERTION_REJECTED;
}
}
NS_IMETHODIMP
RDFXMLDataSourceImpl::Flush(void)
@ -738,7 +818,7 @@ RDFXMLDataSourceImpl::SetReadOnly(PRBool aIsReadOnly)
}
NS_IMETHODIMP
RDFXMLDataSourceImpl::Open(PRBool aBlocking)
RDFXMLDataSourceImpl::Refresh(PRBool aBlocking)
{
nsresult rv;
@ -753,7 +833,7 @@ RDFXMLDataSourceImpl::Open(PRBool aBlocking)
nsCOMPtr<nsIRDFContentSink> sink;
rv = nsComponentManager::CreateInstance(kRDFContentSinkCID,
nsnull,
kIRDFContentSinkIID,
nsIRDFContentSink::GetIID(),
getter_AddRefs(sink));
if (NS_FAILED(rv)) return rv;
@ -812,7 +892,7 @@ RDFXMLDataSourceImpl::BeginLoad(void)
{
mIsLoading = PR_TRUE;
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
nsIRDFXMLSinkObserver* obs = (nsIRDFXMLSinkObserver*) mObservers[i];
obs->OnBeginLoad(this);
}
return NS_OK;
@ -822,7 +902,7 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::Interrupt(void)
{
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
nsIRDFXMLSinkObserver* obs = (nsIRDFXMLSinkObserver*) mObservers[i];
obs->OnInterrupt(this);
}
return NS_OK;
@ -832,7 +912,7 @@ NS_IMETHODIMP
RDFXMLDataSourceImpl::Resume(void)
{
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
nsIRDFXMLSinkObserver* obs = (nsIRDFXMLSinkObserver*) mObservers[i];
obs->OnResume(this);
}
return NS_OK;
@ -848,7 +928,7 @@ RDFXMLDataSourceImpl::EndLoad(void)
}
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
nsIRDFXMLSinkObserver* obs = (nsIRDFXMLSinkObserver*) mObservers[i];
obs->OnEndLoad(this);
}
return NS_OK;
@ -880,14 +960,14 @@ RDFXMLDataSourceImpl::AddNameSpace(nsIAtom* aPrefix, const nsString& aURI)
NS_IMETHODIMP
RDFXMLDataSourceImpl::AddXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver)
RDFXMLDataSourceImpl::AddXMLSinkObserver(nsIRDFXMLSinkObserver* aObserver)
{
mObservers.AppendElement(aObserver);
return NS_OK;
}
NS_IMETHODIMP
RDFXMLDataSourceImpl::RemoveXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver)
RDFXMLDataSourceImpl::RemoveXMLSinkObserver(nsIRDFXMLSinkObserver* aObserver)
{
mObservers.RemoveElement(aObserver);
return NS_OK;
@ -922,7 +1002,7 @@ rdf_BlockingWrite(nsIOutputStream* stream, const nsString& s)
char buf[256];
char* p = buf;
if (s.Length() >= sizeof(buf))
if (s.Length() >= PRInt32(sizeof buf))
p = new char[s.Length() + 1];
nsresult rv = rdf_BlockingWrite(stream, s.ToCString(p, s.Length() + 1), s.Length());
@ -963,10 +1043,10 @@ RDFXMLDataSourceImpl::MakeQName(nsIRDFResource* resource,
}
// Okay, so we don't have it in our map. Try to make one up.
PRInt32 index = uri.RFind('#'); // first try a '#'
if (index == -1) {
index = uri.RFind('/');
if (index == -1) {
PRInt32 i = uri.RFind('#'); // first try a '#'
if (i == -1) {
i = uri.RFind('/');
if (i == -1) {
// Okay, just punt and assume there is _no_ namespace on
// this thing...
//NS_ASSERTION(PR_FALSE, "couldn't find reasonable namespace prefix");
@ -980,12 +1060,12 @@ RDFXMLDataSourceImpl::MakeQName(nsIRDFResource* resource,
// Take whatever is to the right of the '#' and call it the
// property.
property.Truncate();
nameSpaceURI.Right(property, uri.Length() - (index + 1));
nameSpaceURI.Right(property, uri.Length() - (i + 1));
// Truncate the namespace URI down to the string up to and
// including the '#'.
nameSpaceURI = uri;
nameSpaceURI.Truncate(index + 1);
nameSpaceURI.Truncate(i + 1);
// Just generate a random prefix
static PRInt32 gPrefixID = 0;
@ -1019,26 +1099,26 @@ RDFXMLDataSourceImpl::IsContainerProperty(nsIRDFResource* aProperty)
static void
rdf_EscapeAngleBrackets(nsString& s)
{
PRInt32 index;
while ((index = s.Find('<')) != -1) {
s.SetCharAt('&',index);
s.Insert(nsAutoString("lt;"), index + 1);
PRInt32 i;
while ((i = s.Find('<')) != -1) {
s.SetCharAt('&', i);
s.Insert(nsAutoString("lt;"), i + 1);
}
while ((index = s.Find('>')) != -1) {
s.SetCharAt('&',index);
s.Insert(nsAutoString("gt;"), index + 1);
while ((i = s.Find('>')) != -1) {
s.SetCharAt('&', i);
s.Insert(nsAutoString("gt;"), i + 1);
}
}
static void
rdf_EscapeAmpersands(nsString& s)
{
PRInt32 index = 0;
while ((index = s.Find('&', index)) != -1) {
s.SetCharAt('&',index);
s.Insert(nsAutoString("amp;"), index + 1);
index += 4;
PRInt32 i = 0;
while ((i = s.Find('&', i)) != -1) {
s.SetCharAt('&', i);
s.Insert(nsAutoString("amp;"), i + 1);
i += 4;
}
}
@ -1074,7 +1154,7 @@ RDFXMLDataSourceImpl::SerializeAssertion(nsIOutputStream* aStream,
nsIRDFResource* resource;
nsIRDFLiteral* literal;
if (NS_SUCCEEDED(aValue->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
if (NS_SUCCEEDED(aValue->QueryInterface(nsIRDFResource::GetIID(), (void**) &resource))) {
nsXPIDLCString s;
resource->GetValue(getter_Copies(s));
@ -1093,7 +1173,7 @@ static const char kRDFResource2[] = "\"/>\n";
NS_RELEASE(resource);
}
else if (NS_SUCCEEDED(aValue->QueryInterface(kIRDFLiteralIID, (void**) &literal))) {
else if (NS_SUCCEEDED(aValue->QueryInterface(nsIRDFLiteral::GetIID(), (void**) &literal))) {
nsXPIDLString value;
literal->GetValue(getter_Copies(value));
nsAutoString s((const PRUnichar*) value);
@ -1233,7 +1313,7 @@ RDFXMLDataSourceImpl::SerializeMember(nsIOutputStream* aStream,
nsIRDFResource* resource = nsnull;
nsIRDFLiteral* literal = nsnull;
if (NS_SUCCEEDED(rv = aMember->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
if (NS_SUCCEEDED(rv = aMember->QueryInterface(nsIRDFResource::GetIID(), (void**) &resource))) {
nsXPIDLCString s;
if (NS_SUCCEEDED(rv = resource->GetValue( getter_Copies(s) ))) {
static const char kRDFLIResource1[] = " <RDF:li resource=\"";
@ -1249,7 +1329,7 @@ static const char kRDFLIResource2[] = "\"/>\n";
}
NS_RELEASE(resource);
}
else if (NS_SUCCEEDED(rv = aMember->QueryInterface(kIRDFLiteralIID, (void**) &literal))) {
else if (NS_SUCCEEDED(rv = aMember->QueryInterface(nsIRDFLiteral::GetIID(), (void**) &literal))) {
nsXPIDLString value;
if (NS_SUCCEEDED(rv = literal->GetValue( getter_Copies(value) ))) {
static const char kRDFLILiteral1[] = " <RDF:li>";

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

@ -57,7 +57,9 @@ struct nsCategory {
////////////////////////////////////////////////////////////////////////////////
class nsBrowsingProfile : public nsIBrowsingProfile, public nsIRDFObserver {
class nsBrowsingProfile : public nsIBrowsingProfile,
public nsIRDFObserver
{
public:
NS_DECL_ISUPPORTS
@ -71,12 +73,21 @@ public:
NS_IMETHOD CountPageVisit(const char* url);
// nsIRDFObserver methods:
NS_IMETHOD OnAssert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object);
NS_IMETHOD OnUnassert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object);
NS_IMETHOD OnAssert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD OnUnassert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
// nsBrowsingProfile methods:
nsBrowsingProfile();
@ -587,6 +598,27 @@ nsBrowsingProfile::OnUnassert(nsIRDFResource* subject,
}
NS_IMETHODIMP
nsBrowsingProfile::OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
// XXX Do we care?
return NS_OK;
}
NS_IMETHODIMP
nsBrowsingProfile::OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
// XXX Do we care?
return NS_OK;
}
void
nsBrowsingProfile::Uint8ToHex(PRUint8 aNum, char aBuf[2])
{

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

@ -86,10 +86,6 @@
#define NS_RDFXMLDATASOURCE_CID \
{ 0x7baf62e0, 0x8e61, 0x11d2, { 0x8e, 0xb1, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {6791B601-B9FE-11d2-BF86-00105A1B0627}
#define NS_XULDATASOURCE_CID \
{ 0x6791b601, 0xb9fe, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {0958B101-9ADA-11d2-8EBC-00805F29F370}
#define NS_RDFCONTENTSINK_CID \
{ 0x958b101, 0x9ada, 0x11d2, { 0x8e, 0xbc, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }

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

@ -32,7 +32,6 @@
#include "nsIRDFContentSink.h"
#include "nsIRDFDocument.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIXULContentSink.h"
#include "nsISupports.h"
#include "nsRDFBaseDataSources.h"
@ -75,7 +74,6 @@ static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID)
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_CID(kRDFXULBuilderCID, NS_RDFXULBUILDER_CID);
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
static NS_DEFINE_CID(kXULDataSourceCID, NS_XULDATASOURCE_CID);
static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID);
static NS_DEFINE_CID(kXULSortServiceCID, NS_XULSORTSERVICE_CID);
static NS_DEFINE_CID(kXULDocumentInfoCID, NS_XULDOCUMENTINFO_CID);
@ -187,7 +185,7 @@ RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
return rv;
}
else if (mClassID.Equals(kRDFXMLDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFXMLDataSource((nsIRDFXMLDataSource**) &inst)))
if (NS_FAILED(rv = NS_NewRDFXMLDataSource((nsIRDFDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFFileSystemDataSourceCID)) {
@ -250,12 +248,6 @@ RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
if (NS_FAILED(rv = NS_NewRDFContentSink((nsIRDFContentSink**) &inst)))
return rv;
}
#if 0 // I think we may need this later, re: rejecting assertions
else if (mClassID.Equals(kXULDataSourceCID)) {
if (NS_FAILED(rv = NS_NewXULDataSource((nsIRDFXMLDataSource**) &inst)))
return rv;
}
#endif
else if (mClassID.Equals(kXULContentSinkCID)) {
if (NS_FAILED(rv = NS_NewXULContentSink((nsIXULContentSink**) &inst)))
return rv;
@ -399,11 +391,6 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
NS_RDF_DATASOURCE_PROGID_PREFIX "xml-datasource",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
rv = compMgr->RegisterComponent(kXULDataSourceCID,
"XUL Data Source",
NS_RDF_DATASOURCE_PROGID_PREFIX "xul-datasource",
aPath, PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
// register our built-in resource factories:
rv = compMgr->RegisterComponent(kRDFDefaultResourceCID,
@ -533,12 +520,8 @@ NSUnregisterSelf(nsISupports* aServMgr, const char* aPath)
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kRDFXMLDataSourceCID, aPath);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kXULDataSourceCID, aPath);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kRDFDefaultResourceCID, aPath);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kRDFContentSinkCID, aPath);
if (NS_FAILED(rv)) goto done;
rv = compMgr->UnregisterComponent(kRDFHTMLBuilderCID, aPath);

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

@ -20,8 +20,9 @@
#include "nsFileSpec.h"
#include "nsSpecialSystemDirectory.h"
#include "nsIChromeRegistry.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFObserver.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsCRT.h"
#include "rdf.h"
#include "nsIServiceManager.h"
@ -68,7 +69,6 @@ public:
NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURL);
// nsIRDFDataSource methods
NS_IMETHOD Init(const char* uri) ; // Called to init the data source.
NS_IMETHOD GetURI(char** uri);
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
@ -93,6 +93,14 @@ public:
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target) ;
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
@ -105,7 +113,6 @@ public:
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsISimpleEnumerator** labels /* out */) ;
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult) ;
NS_IMETHOD Flush(void) ;
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands) ;
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
@ -344,9 +351,86 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL)
NS_IMETHODIMP
nsChromeRegistry::InitRegistry()
{
if (mInner == nsnull)
return Init("rdf:chrome");
else return NS_OK;
gRefCnt++;
if (gRefCnt == 1) {
nsresult rv;
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**)&gRDFService);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");
if (NS_FAILED(rv)) return rv;
// get all the properties we'll need:
rv = gRDFService->GetResource(kURICHROME_chrome, &kCHROME_chrome);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_skin, &kCHROME_skin);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_content);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_platform);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_locale);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_behavior);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_base, &kCHROME_base);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_main, &kCHROME_main);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_archive, &kCHROME_archive);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_name, &kCHROME_name);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_displayname, &kCHROME_displayname);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID,
nsnull,
nsIRDFDataSource::GetIID(),
(void**) &mInner);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
if (! remote)
return NS_ERROR_UNEXPECTED;
// Retrieve the mInner data source.
nsSpecialSystemDirectory chromeFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
chromeFile += "chrome";
chromeFile += "registry.rdf";
nsFileURL chromeURL(chromeFile);
const char* innerURI = chromeURL.GetAsString();
rv = remote->Init(innerURI);
if (NS_FAILED(rv)) return rv;
// We need to read this synchronously.
rv = remote->Refresh(PR_TRUE);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////
@ -433,98 +517,14 @@ NS_NewChromeRegistry(nsIChromeRegistry** aResult)
////////////////////////////////////////////////////////////////////////////////
// nsIRDFDataSource methods
NS_IMETHODIMP
nsChromeRegistry::Init(const char* uri)
{
// We're going to be init'ed with the "rdf:chrome" URI.
// We want to use the location of the registry source instead.
nsresult rv = NS_OK;
gRefCnt++;
if (gRefCnt == 1) {
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**)&gRDFService);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");
if (NS_FAILED(rv)) return rv;
// get all the properties we'll need:
rv = gRDFService->GetResource(kURICHROME_chrome, &kCHROME_chrome);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_skin, &kCHROME_skin);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_content);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_platform);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_locale);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_content, &kCHROME_behavior);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_base, &kCHROME_base);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_main, &kCHROME_main);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_archive, &kCHROME_archive);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_name, &kCHROME_name);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = gRDFService->GetResource(kURICHROME_displayname, &kCHROME_displayname);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
if (NS_FAILED(rv)) return rv;
rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID,
nsnull,
nsIRDFXMLDataSource::GetIID(),
(void**) &mInner);
if (NS_FAILED(rv)) return rv;
// Retrieve the mInner data source.
nsSpecialSystemDirectory chromeFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
chromeFile += "chrome";
chromeFile += "registry.rdf";
nsFileURL chromeURL(chromeFile);
const char* innerURI = chromeURL.GetAsString();
rv = mInner->Init(innerURI);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFXMLDataSource> xmlds = do_QueryInterface(mInner);
if (! xmlds)
return NS_ERROR_FAILURE;
// We need to read this synchronously.
rv = xmlds->Open(PR_TRUE);
}
return rv;
}
NS_IMETHODIMP
nsChromeRegistry::GetURI(char** uri)
{
return mInner->GetURI(uri);
*uri = nsXPIDLCString::Copy("rdf:chrome");
if (! *uri)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
NS_IMETHODIMP
@ -581,6 +581,24 @@ nsChromeRegistry::Unassert(nsIRDFResource* source,
return mInner->Unassert(source, property, target);
}
NS_IMETHODIMP
nsChromeRegistry::Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
return mInner->Change(aSource, aProperty, aOldTarget, aNewTarget);
}
NS_IMETHODIMP
nsChromeRegistry::Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
return mInner->Move(aOldSource, aNewSource, aProperty, aTarget);
}
NS_IMETHODIMP
nsChromeRegistry::HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
@ -618,12 +636,6 @@ NS_IMETHODIMP nsChromeRegistry::GetAllResources(nsISimpleEnumerator** aCursor)
return mInner->GetAllResources(aCursor);
}
NS_IMETHODIMP
nsChromeRegistry::Flush(void)
{
return mInner->Flush();
}
NS_IMETHODIMP
nsChromeRegistry::GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands)

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

@ -1616,6 +1616,29 @@ RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSubject,
return NS_OK;
}
NS_IMETHODIMP
RDFGenericBuilderImpl::OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RDFGenericBuilderImpl::OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMNodeObserver interface
//

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

@ -78,8 +78,23 @@ public:
PRBool isUnique, nsIRDFResource* aProperty, nsIRDFNode* aValue);
// nsIRDFObserver interface
NS_IMETHOD OnAssert(nsIRDFResource* aSubject, nsIRDFResource* aPredicate, nsIRDFNode* aObject);
NS_IMETHOD OnUnassert(nsIRDFResource* aSubject, nsIRDFResource* aPredicate, nsIRDFNode* aObjetct);
NS_IMETHOD OnAssert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD OnUnassert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
// nsIDOMNodeObserver interface
NS_DECL_IDOMNODEOBSERVER

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

@ -239,8 +239,24 @@ public:
// nsIRDFObserver interface
NS_IMETHOD OnAssert(nsIRDFResource* aSource, nsIRDFResource* aProperty, nsIRDFNode* aTarget);
NS_IMETHOD OnUnassert(nsIRDFResource* aSource, nsIRDFResource* aProperty, nsIRDFNode* aObjetct);
NS_IMETHOD OnAssert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD OnUnassert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aObjetct);
NS_IMETHOD OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
// nsIDOMNodeObserver interface
NS_DECL_IDOMNODEOBSERVER
@ -1177,6 +1193,29 @@ RDFXULBuilderImpl::OnUnassert(nsIRDFResource* aSource,
}
NS_IMETHODIMP
RDFXULBuilderImpl::OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RDFXULBuilderImpl::OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMNodeObserver interface

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

@ -175,7 +175,6 @@ static NS_DEFINE_CID(kRangeListCID, NS_RANGELIST_CID);
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
static NS_DEFINE_CID(kXULDataSourceCID, NS_XULDATASOURCE_CID);
static NS_DEFINE_CID(kXULFocusTrackerCID, NS_XULFOCUSTRACKER_CID);
static NS_DEFINE_IID(kIXULFocusTrackerIID, NS_IXULFOCUSTRACKER_IID);
@ -1189,13 +1188,6 @@ XULDocumentImpl::PrepareToLoad( nsCOMPtr<nsIParser>* created_parser,
if (NS_FAILED(rv = db->AddDataSource(mDocumentDataSource))) {
NS_ERROR("unable to add XUL datasource to db");
return rv;
}
const char* seedCString = 0;
syntheticURL->GetSpec(&seedCString);
if (NS_FAILED(rv = mDocumentDataSource->Init(seedCString))) {
NS_ERROR("unable to initialize XUL data source");
return rv;
}
}

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

@ -1616,6 +1616,29 @@ RDFGenericBuilderImpl::OnUnassert(nsIRDFResource* aSubject,
return NS_OK;
}
NS_IMETHODIMP
RDFGenericBuilderImpl::OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RDFGenericBuilderImpl::OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMNodeObserver interface
//

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup" -*-
*
* 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
@ -100,8 +100,6 @@ public:
class FTPDataSource : public nsIRDFFTPDataSource
{
private:
char *mURI;
static PRInt32 gRefCnt;
// pseudo-constants
@ -123,14 +121,15 @@ public:
NS_DECL_ISUPPORTS
FTPDataSource(void);
FTPDataSource(void);
virtual ~FTPDataSource(void);
nsresult Init();
//friend class FTPDataSourceCallback;
// nsIRDFDataSource methods
NS_IMETHOD Init(const char *uri);
NS_IMETHOD GetURI(char **uri);
NS_IMETHOD GetSource(nsIRDFResource *property,
nsIRDFNode *target,
@ -155,6 +154,14 @@ public:
NS_IMETHOD Unassert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target);
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD HasAssertion(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target,
@ -167,7 +174,6 @@ public:
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aCursor);
NS_IMETHOD AddObserver(nsIRDFObserver *n);
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
NS_IMETHOD Flush();
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands);
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
@ -240,7 +246,6 @@ isFTPDirectory(nsIRDFResource *r)
FTPDataSource::FTPDataSource(void)
: mURI(nsnull)
{
NS_INIT_REFCNT();
@ -269,8 +274,6 @@ FTPDataSource::~FTPDataSource (void)
{
gRDFService->UnregisterDataSource(this);
PL_strfree(mURI);
if (--gRefCnt == 0)
{
NS_RELEASE(kNC_Child);
@ -294,23 +297,19 @@ NS_IMPL_ISUPPORTS(FTPDataSource, nsIRDFDataSource::GetIID());
NS_IMETHODIMP
FTPDataSource::Init(const char *uri)
nsresult
FTPDataSource::Init()
{
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull, nsIRDFDataSource::GetIID(), (void **)&mInner)))
return rv;
if (NS_FAILED(rv = mInner->Init(uri)))
return rv;
if ((mURI = PL_strdup(uri)) == nsnull)
return rv;
// register this as a named data source with the service manager
if (NS_FAILED(rv = gRDFService->RegisterDataSource(this, PR_FALSE)))
return rv;
return NS_OK;
}
@ -319,10 +318,10 @@ FTPDataSource::Init(const char *uri)
NS_IMETHODIMP
FTPDataSource::GetURI(char **uri)
{
if ((*uri = nsXPIDLCString::Copy(mURI)) == nsnull)
if ((*uri = nsXPIDLCString::Copy("rdf:ftp")) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
else
return NS_OK;
return NS_OK;
}
@ -835,7 +834,6 @@ FTPDataSource::Assert(nsIRDFResource *source,
nsIRDFNode *target,
PRBool tv)
{
// PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -846,7 +844,26 @@ FTPDataSource::Unassert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target)
{
// PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FTPDataSource::Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FTPDataSource::Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -924,15 +941,6 @@ FTPDataSource::RemoveObserver(nsIRDFObserver *n)
}
NS_IMETHODIMP
FTPDataSource::Flush()
{
return mInner->Flush();
}
NS_IMETHODIMP
FTPDataSource::GetAllCommands(nsIRDFResource* source,nsIEnumerator/*<nsIRDFResource>*/** commands)
{
@ -978,6 +986,14 @@ NS_NewRDFFTPDataSource(nsIRDFDataSource **result)
{
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv;
rv = gFTPDataSource->Init();
if (NS_FAILED(rv)) {
delete gFTPDataSource;
gFTPDataSource = nsnull;
return rv;
}
}
NS_ADDREF(gFTPDataSource);
*result = gFTPDataSource;

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

@ -63,8 +63,7 @@ static const char kURINC_FileSystemRoot[] = "NC:FilesRoot";
class FileSystemDataSource : public nsIRDFFileSystemDataSource
{
private:
char *mURI;
nsVoidArray *mObservers;
nsCOMPtr<nsISupportsArray> mObservers;
static PRInt32 gRefCnt;
@ -87,7 +86,6 @@ public:
// nsIRDFDataSource methods
NS_IMETHOD Init(const char *uri);
NS_IMETHOD GetURI(char **uri);
NS_IMETHOD GetSource(nsIRDFResource *property,
nsIRDFNode *target,
@ -112,6 +110,14 @@ public:
NS_IMETHOD Unassert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target);
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD HasAssertion(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target,
@ -124,7 +130,6 @@ public:
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult);
NS_IMETHOD AddObserver(nsIRDFObserver *n);
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
NS_IMETHOD Flush();
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands);
@ -188,8 +193,6 @@ FileSystemDataSource::isFileURI(nsIRDFResource *r)
FileSystemDataSource::FileSystemDataSource(void)
: mURI(nsnull),
mObservers(nsnull)
{
NS_INIT_REFCNT();
@ -220,10 +223,6 @@ FileSystemDataSource::~FileSystemDataSource (void)
{
gRDFService->UnregisterDataSource(this);
PL_strfree(mURI);
delete mObservers; // we only hold a weak ref to each observer
if (--gRefCnt == 0) {
NS_RELEASE(kNC_FileSystemRoot);
NS_RELEASE(kNC_Child);
@ -242,26 +241,6 @@ FileSystemDataSource::~FileSystemDataSource (void)
NS_IMPL_ISUPPORTS(FileSystemDataSource, nsIRDFDataSource::GetIID());
NS_IMETHODIMP
FileSystemDataSource::Init(const char *uri)
{
NS_PRECONDITION(uri != nsnull, "null ptr");
if (! uri)
return NS_ERROR_NULL_POINTER;
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
if ((mURI = PL_strdup(uri)) == nsnull)
return rv;
// register this as a named data source with the service manager
if (NS_FAILED(rv = gRDFService->RegisterDataSource(this, PR_FALSE)))
return rv;
return NS_OK;
}
NS_IMETHODIMP
FileSystemDataSource::GetURI(char **uri)
{
@ -269,10 +248,10 @@ FileSystemDataSource::GetURI(char **uri)
if (! uri)
return NS_ERROR_NULL_POINTER;
if ((*uri = nsXPIDLCString::Copy(mURI)) == nsnull)
if ((*uri = nsXPIDLCString::Copy("rdf:files")) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
else
return NS_OK;
return NS_OK;
}
@ -546,7 +525,6 @@ FileSystemDataSource::Assert(nsIRDFResource *source,
nsIRDFNode *target,
PRBool tv)
{
// PR_ASSERT(0);
return NS_RDF_ASSERTION_REJECTED;
}
@ -557,11 +535,28 @@ FileSystemDataSource::Unassert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target)
{
// PR_ASSERT(0);
return NS_RDF_ASSERTION_REJECTED;
}
NS_IMETHODIMP
FileSystemDataSource::Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
return NS_RDF_ASSERTION_REJECTED;
}
NS_IMETHODIMP
FileSystemDataSource::Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
return NS_RDF_ASSERTION_REJECTED;
}
NS_IMETHODIMP
FileSystemDataSource::HasAssertion(nsIRDFResource *source,
@ -700,10 +695,11 @@ FileSystemDataSource::AddObserver(nsIRDFObserver *n)
if (! n)
return NS_ERROR_NULL_POINTER;
if (nsnull == mObservers)
if (! mObservers)
{
if ((mObservers = new nsVoidArray()) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
rv = NS_NewISupportsArray(getter_AddRefs(mObservers));
if (NS_FAILED(rv)) return rv;
}
mObservers->AppendElement(n);
return NS_OK;
@ -718,23 +714,14 @@ FileSystemDataSource::RemoveObserver(nsIRDFObserver *n)
if (! n)
return NS_ERROR_NULL_POINTER;
if (nsnull == mObservers)
if (! mObservers)
return NS_OK;
mObservers->RemoveElement(n);
return NS_OK;
}
NS_IMETHODIMP
FileSystemDataSource::Flush()
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FileSystemDataSource::GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands)

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup" -*-
*
* 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
@ -60,8 +60,7 @@ typedef struct _findTokenStruct
class FindDataSource : public nsIRDFFindDataSource
{
private:
char *mURI;
nsVoidArray *mObservers;
nsCOMPtr<nsISupportsArray> mObservers;
static PRInt32 gRefCnt;
@ -94,7 +93,6 @@ public:
// nsIRDFDataSource methods
NS_IMETHOD Init(const char *uri);
NS_IMETHOD GetURI(char **uri);
NS_IMETHOD GetSource(nsIRDFResource *property,
nsIRDFNode *target,
@ -119,6 +117,14 @@ public:
NS_IMETHOD Unassert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target);
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD HasAssertion(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target,
@ -131,7 +137,6 @@ public:
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aCursor);
NS_IMETHOD AddObserver(nsIRDFObserver *n);
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
NS_IMETHOD Flush();
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands);
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
@ -176,8 +181,6 @@ isFindURI(nsIRDFResource *r)
FindDataSource::FindDataSource(void)
: mURI(nsnull),
mObservers(nsnull)
{
NS_INIT_REFCNT();
@ -207,10 +210,6 @@ FindDataSource::~FindDataSource (void)
{
gRDFService->UnregisterDataSource(this);
PL_strfree(mURI);
delete mObservers; // we only hold a weak ref to each observer
if (--gRefCnt == 0)
{
NS_RELEASE(kNC_Child);
@ -231,28 +230,6 @@ FindDataSource::~FindDataSource (void)
NS_IMPL_ISUPPORTS(FindDataSource, nsIRDFDataSource::GetIID());
NS_IMETHODIMP
FindDataSource::Init(const char *uri)
{
NS_PRECONDITION(uri != nsnull, "null ptr");
if (! uri)
return NS_ERROR_NULL_POINTER;
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
if ((mURI = PL_strdup(uri)) == nsnull)
return rv;
// register this as a named data source with the service manager
if (NS_FAILED(rv = gRDFService->RegisterDataSource(this, PR_FALSE)))
return rv;
return NS_OK;
}
NS_IMETHODIMP
FindDataSource::GetURI(char **uri)
{
@ -260,10 +237,10 @@ FindDataSource::GetURI(char **uri)
if (! uri)
return NS_ERROR_NULL_POINTER;
if ((*uri = nsXPIDLCString::Copy(mURI)) == nsnull)
if ((*uri = nsXPIDLCString::Copy("rdf:find")) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
else
return NS_OK;
return NS_OK;
}
@ -439,7 +416,7 @@ FindDataSource::doMatch(nsIRDFLiteral *literal, char *matchMethod, char *matchTe
else if (!PL_strcmp(matchMethod, "endswith"))
{
PRInt32 pos = value.RFind(matchText, PR_TRUE);
if ((pos >= 0) && (pos == (value.Length() - strlen(matchText))))
if ((pos >= 0) && (pos == (value.Length() - PRInt32(strlen(matchText)))))
found = PR_TRUE;
}
else if (!PL_strcmp(matchMethod, "is"))
@ -689,8 +666,7 @@ FindDataSource::Assert(nsIRDFResource *source,
nsIRDFNode *target,
PRBool tv)
{
// PR_ASSERT(0);
return NS_RDF_ASSERTION_REJECTED;
return NS_RDF_ASSERTION_REJECTED;
}
@ -700,7 +676,25 @@ FindDataSource::Unassert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target)
{
// PR_ASSERT(0);
return NS_RDF_ASSERTION_REJECTED;
}
NS_IMETHODIMP
FindDataSource::Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
return NS_RDF_ASSERTION_REJECTED;
}
NS_IMETHODIMP
FindDataSource::Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
return NS_RDF_ASSERTION_REJECTED;
}
@ -819,10 +813,11 @@ FindDataSource::AddObserver(nsIRDFObserver *n)
if (! n)
return NS_ERROR_NULL_POINTER;
if (nsnull == mObservers)
if (! mObservers)
{
if ((mObservers = new nsVoidArray()) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
rv = NS_NewISupportsArray(getter_AddRefs(mObservers));
if (NS_FAILED(rv)) return rv;
}
return mObservers->AppendElement(n) ? NS_OK : NS_ERROR_FAILURE;
}
@ -836,7 +831,7 @@ FindDataSource::RemoveObserver(nsIRDFObserver *n)
if (! n)
return NS_ERROR_NULL_POINTER;
if (nsnull == mObservers)
if (! mObservers)
return NS_OK;
NS_VERIFY(mObservers->RemoveElement(n), "observer not present");
@ -844,16 +839,6 @@ FindDataSource::RemoveObserver(nsIRDFObserver *n)
}
NS_IMETHODIMP
FindDataSource::Flush()
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FindDataSource::GetAllCommands(nsIRDFResource* source,nsIEnumerator/*<nsIRDFResource>*/** commands)
{

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

@ -27,7 +27,7 @@
#include "nsIComponentManager.h"
#include "nsILocalStore.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
@ -42,13 +42,16 @@ class LocalStoreImpl : public nsILocalStore,
public nsIRDFDataSource
{
private:
nsIRDFXMLDataSource* mInner;
char* mURI;
nsCOMPtr<nsIRDFDataSource> mInner;
public:
LocalStoreImpl();
virtual ~LocalStoreImpl();
nsresult Init();
friend nsresult
NS_NewLocalStore(nsILocalStore** aResult);
public:
// nsISupports interface
NS_DECL_ISUPPORTS
@ -56,8 +59,6 @@ public:
// nsIRDFDataSource interface. Most of these are just delegated to
// the inner, in-memory datasource.
NS_IMETHOD Init(const char* aURI);
NS_IMETHOD GetURI(char* *aURI);
NS_IMETHOD GetSource(nsIRDFResource* aProperty,
@ -101,6 +102,20 @@ public:
return mInner->Unassert(aSource, aProperty, aTarget);
}
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget) {
return mInner->Change(aSource, aProperty, aOldTarget, aNewTarget);
}
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget) {
return mInner->Move(aOldSource, aNewSource, aProperty, aTarget);
}
NS_IMETHOD HasAssertion(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget,
@ -131,10 +146,6 @@ public:
return mInner->GetAllResources(aResult);
}
NS_IMETHOD Flush(void) {
return mInner->Flush();
}
NS_IMETHOD GetAllCommands(nsIRDFResource* aSource,
nsIEnumerator/*<nsIRDFResource>*/** aCommands);
@ -154,20 +165,16 @@ public:
LocalStoreImpl::LocalStoreImpl(void)
: mInner(nsnull), mURI(nsnull)
{
NS_INIT_ISUPPORTS();
}
LocalStoreImpl::~LocalStoreImpl(void)
{
Flush();
NS_IF_RELEASE(mInner);
PL_strfree(mURI);
}
PR_IMPLEMENT(nsresult)
nsresult
NS_NewLocalStore(nsILocalStore** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
@ -178,6 +185,13 @@ NS_NewLocalStore(nsILocalStore** aResult)
if (! impl)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
rv = impl->Init();
if (NS_FAILED(rv)) {
delete impl;
return rv;
}
NS_ADDREF(impl);
*aResult = impl;
return NS_OK;
@ -221,8 +235,8 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
// nsIRDFDataSource interface
NS_IMETHODIMP
LocalStoreImpl::Init(const char* aURI)
nsresult
LocalStoreImpl::Init()
{
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
@ -242,17 +256,15 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
os << "</RDF:RDF>" << nsEndl;
}
mURI = PL_strdup(aURI);
if (! mURI)
return NS_ERROR_OUT_OF_MEMORY;
rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID,
nsnull,
nsIRDFXMLDataSource::GetIID(),
nsIRDFDataSource::GetIID(),
(void**) &mInner);
if (NS_FAILED(rv)) return rv;
rv = mInner->Init((const char*) nsFileURL(spec));
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(mInner);
rv = remote->Init((const char*) nsFileURL(spec));
if (NS_FAILED(rv)) return rv;
// register this as a named data source with the RDF service
@ -279,7 +291,7 @@ LocalStoreImpl::GetURI(char* *aURI)
if (! aURI)
return NS_ERROR_NULL_POINTER;
*aURI = nsXPIDLCString::Copy(mURI);
*aURI = nsXPIDLCString::Copy("rdf:localstore");
if (! *aURI)
return NS_ERROR_OUT_OF_MEMORY;

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4; c-file-style: "stroustrup" -*-
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4; c-file-style: "stroustrup" -*-
*
* 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
@ -129,9 +129,6 @@ public:
class SearchDataSource : public nsIRDFSearchDataSource
{
private:
char *mURI;
nsVoidArray *mObservers;
static PRInt32 gRefCnt;
// pseudo-constants
@ -152,12 +149,12 @@ friend class SearchDataSourceCallback;
NS_DECL_ISUPPORTS
SearchDataSource(void);
SearchDataSource(void);
virtual ~SearchDataSource(void);
nsresult Init();
// nsIRDFDataSource methods
NS_IMETHOD Init(const char *uri);
NS_IMETHOD GetURI(char **uri);
NS_IMETHOD GetSource(nsIRDFResource *property,
nsIRDFNode *target,
@ -182,6 +179,14 @@ friend class SearchDataSourceCallback;
NS_IMETHOD Unassert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target);
NS_IMETHOD Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD HasAssertion(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target,
@ -194,7 +199,6 @@ friend class SearchDataSourceCallback;
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult);
NS_IMETHOD AddObserver(nsIRDFObserver *n);
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
NS_IMETHOD Flush();
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
nsIEnumerator/*<nsIRDFResource>*/** commands);
@ -284,8 +288,6 @@ SearchDataSource::isSearchURI(nsIRDFResource *r)
SearchDataSource::SearchDataSource(void)
: mURI(nsnull),
mObservers(nsnull)
{
NS_INIT_REFCNT();
@ -315,10 +317,6 @@ SearchDataSource::~SearchDataSource (void)
{
gRDFService->UnregisterDataSource(this);
PL_strfree(mURI);
delete mObservers; // we only hold a weak ref to each observer
if (--gRefCnt == 0)
{
NS_RELEASE(kNC_SearchRoot);
@ -343,23 +341,14 @@ NS_IMPL_ISUPPORTS(SearchDataSource, nsIRDFDataSource::GetIID());
NS_IMETHODIMP
SearchDataSource::Init(const char *uri)
nsresult
SearchDataSource::Init()
{
NS_PRECONDITION(uri != nsnull, "null ptr");
if (! uri)
return NS_ERROR_NULL_POINTER;
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull, nsIRDFDataSource::GetIID(), (void **)&mInner)))
return(rv);
if (NS_FAILED(rv = mInner->Init(uri)))
return(rv);
if ((mURI = PL_strdup(uri)) == nsnull)
return(rv);
// register this as a named data source with the service manager
if (NS_FAILED(rv = gRDFService->RegisterDataSource(this, PR_FALSE)))
@ -381,8 +370,9 @@ SearchDataSource::GetURI(char **uri)
if (! uri)
return NS_ERROR_NULL_POINTER;
if ((*uri = nsXPIDLCString::Copy(mURI)) == nsnull)
if ((*uri = nsXPIDLCString::Copy("rdf:search")) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
@ -523,7 +513,6 @@ SearchDataSource::Assert(nsIRDFResource *source,
nsIRDFNode *target,
PRBool tv)
{
// PR_ASSERT(0);
return NS_RDF_ASSERTION_REJECTED;
}
@ -534,10 +523,27 @@ SearchDataSource::Unassert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target)
{
// PR_ASSERT(0);
return NS_RDF_ASSERTION_REJECTED;
}
NS_IMETHODIMP
SearchDataSource::Change(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
return NS_RDF_ASSERTION_REJECTED;
}
NS_IMETHODIMP
SearchDataSource::Move(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
return NS_RDF_ASSERTION_REJECTED;
}
NS_IMETHODIMP
@ -621,7 +627,7 @@ SearchDataSource::ArcLabelsOut(nsIRDFResource *source,
return NS_OK;
}
return NS_NewEmptyEnumerator(labels);
return NS_NewEmptyEnumerator(labels);
}
@ -629,72 +635,23 @@ SearchDataSource::ArcLabelsOut(nsIRDFResource *source,
NS_IMETHODIMP
SearchDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
{
nsresult rv = NS_RDF_NO_VALUE;
if (mInner)
{
rv = mInner->GetAllResources(aCursor);
}
return(rv);
return mInner->GetAllResources(aCursor);
}
NS_IMETHODIMP
SearchDataSource::AddObserver(nsIRDFObserver *n)
SearchDataSource::AddObserver(nsIRDFObserver *aObserver)
{
nsresult rv = NS_OK;
NS_PRECONDITION(n != nsnull, "null ptr");
if (! n)
return(NS_ERROR_NULL_POINTER);
if (nsnull == mObservers)
{
if ((mObservers = new nsVoidArray()) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
}
mObservers->AppendElement(n);
if (mInner)
{
rv = mInner->AddObserver(n);
}
return(rv);
return mInner->AddObserver(aObserver);
}
NS_IMETHODIMP
SearchDataSource::RemoveObserver(nsIRDFObserver *n)
SearchDataSource::RemoveObserver(nsIRDFObserver *aObserver)
{
nsresult rv = NS_OK;
NS_PRECONDITION(n != nsnull, "null ptr");
if (! n)
return NS_ERROR_NULL_POINTER;
if (nsnull == mObservers)
return NS_OK;
mObservers->RemoveElement(n);
if (mInner)
{
rv = mInner->RemoveObserver(n);
}
return(rv);
}
NS_IMETHODIMP
SearchDataSource::Flush()
{
nsresult rv = NS_OK;
if (mInner)
{
rv = mInner->Flush();
}
return(rv);
return mInner->RemoveObserver(aObserver);
}
@ -745,6 +702,13 @@ NS_NewRDFSearchDataSource(nsIRDFDataSource **result)
{
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = gSearchDataSource->Init();
if (NS_FAILED(rv)) {
delete gSearchDataSource;
gSearchDataSource = nsnull;
return rv;
}
}
NS_ADDREF(gSearchDataSource);
*result = gSearchDataSource;

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

@ -53,7 +53,6 @@
#include "nsIRDFDocument.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
#include "nsIServiceManager.h"

Двоичные данные
rdf/macbuild/RDFIDL.mcp

Двоичный файл не отображается.

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

@ -44,11 +44,13 @@ function Init()
// synchronously. nsIRDFService::GetDataSource() loads RDF/XML
// asynchronously by default.
registry = Components.classes['component://netscape/rdf/datasource?name=xml-datasource'].createInstance();
registry = registry.QueryInterface(Components.interfaces.nsIRDFXMLDataSource);
registry.Init(flashdb); // this will throw if it's already been opened and registered.
registry = registry.QueryInterface(Components.interfaces.nsIRDFDataSource);
var remote = registry.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
remote.Init(flashdb); // this will throw if it's already been opened and registered.
// read it in synchronously.
registry.Open(true);
remote.Refresh(true);
}
catch (ex) {
// if we get here, then the RDF/XML has been opened and read
@ -120,10 +122,10 @@ function Reload(url, pollInterval)
dump('Reload(' + url + ', ' + pollInterval + ')\n');
var datasource = RDF.GetDataSource(url);
datasource = datasource.QueryInterface(Components.interfaces.nsIRDFXMLDataSource);
datasource = datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
// Reload, asynchronously.
datasource.Open(false);
datasource.Refresh(false);
// Reschedule
Schedule(url, pollInterval);

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

@ -57,11 +57,13 @@ function Init(sidebardb, sidebar_resource)
// synchronously. nsIRDFService::GetDataSource() loads RDF/XML
// asynchronously by default.
registry = Components.classes['component://netscape/rdf/datasource?name=xml-datasource'].createInstance();
registry = registry.QueryInterface(Components.interfaces.nsIRDFXMLDataSource);
registry.Init(sidebardb); // this will throw if it's already been opened and registered.
registry = registry.QueryInterface(Components.interfaces.nsIRDFDataSource);
var remote = registry.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
remote.Init(sidebardb); // this will throw if it's already been opened and registered.
// read it in synchronously.
registry.Open(true);
remote.Refresh(true);
}
catch (ex) {
// if we get here, then the RDF/XML has been opened and read
@ -179,10 +181,10 @@ function Reload(url, pollInterval)
dump('Reload(' + url + ', ' + pollInterval + ')\n');
var datasource = RDF.GetDataSource(url);
datasource = datasource.QueryInterface(Components.interfaces.nsIRDFXMLDataSource);
datasource = datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
// Reload, asynchronously.
datasource.Open(false);
datasource.Refresh(false);
// Reschedule
Schedule(url, pollInterval);

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

@ -38,7 +38,7 @@
#include "nsIGenericFactory.h"
#include "nsIPostToServer.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFDocument.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
@ -96,9 +96,6 @@ static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
NS_DEFINE_IID(kIRDFXMLDataSourceIID, NS_IRDFXMLDATASOURCE_IID);
NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
NS_DEFINE_IID(kIRDFXMLSourceIID, NS_IRDFXMLSOURCE_IID);
#include "nsIAllocator.h" // for the CID
@ -201,21 +198,27 @@ main(int argc, char** argv)
// Create a stream data source and initialize it on argv[1], which
// is hopefully a "file:" URL.
nsCOMPtr<nsIRDFXMLDataSource> ds;
nsCOMPtr<nsIRDFDataSource> ds;
rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID,
nsnull,
kIRDFXMLDataSourceIID,
nsIRDFDataSource::GetIID(),
getter_AddRefs(ds));
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create RDF/XML data source");
if (NS_FAILED(rv)) return rv;
rv = ds->Init(argv[1]);
nsCOMPtr<nsIRDFRemoteDataSource> remote
= do_QueryInterface(ds);
if (! remote)
return NS_ERROR_UNEXPECTED;
rv = remote->Init(argv[1]);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to initialize data source");
if (NS_FAILED(rv)) return rv;
// Okay, this should load the XML file...
rv = ds->Open(PR_TRUE);
rv = remote->Refresh(PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to open datasource");
if (NS_FAILED(rv)) return rv;

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

@ -39,7 +39,7 @@ NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
#endif // NECKO
#include "nsIGenericFactory.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFDocument.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
@ -97,9 +97,6 @@ static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
// IIDs
NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
NS_DEFINE_IID(kIRDFXMLDataSourceIID, NS_IRDFXMLDATASOURCE_IID);
NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
NS_DEFINE_IID(kIRDFXMLSourceIID, NS_IRDFXMLSOURCE_IID);
#include "nsIAllocator.h" // for the CID
@ -157,6 +154,16 @@ public:
NS_IMETHOD OnUnassert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
NS_IMETHOD OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget);
NS_IMETHOD OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget);
};
Observer::Observer()
@ -166,10 +173,11 @@ Observer::Observer()
NS_IMPL_ISUPPORTS(Observer, nsIRDFObserver::GetIID());
NS_IMETHODIMP
Observer::OnAssert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
static nsresult
rdf_WriteOp(const char* aOp,
nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
nsresult rv;
@ -184,7 +192,7 @@ Observer::OnAssert(nsIRDFResource* aSource,
nsCOMPtr<nsIRDFResource> resource;
nsCOMPtr<nsIRDFLiteral> literal;
printf(" assert [%s]\n", (const char*) source);
printf("%.8s [%s]\n", aOp, (const char*) source);
printf(" --[%s]--\n", (const char*) property);
if ((resource = do_QueryInterface(aTarget)) != nsnull) {
@ -212,53 +220,57 @@ Observer::OnAssert(nsIRDFResource* aSource,
return NS_OK;
}
NS_IMETHODIMP
Observer::OnAssert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
return rdf_WriteOp("assert", aSource, aProperty, aTarget);
}
NS_IMETHODIMP
Observer::OnUnassert(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
return rdf_WriteOp("unassert", aSource, aProperty, aTarget);
}
NS_IMETHODIMP
Observer::OnChange(nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aOldTarget,
nsIRDFNode* aNewTarget)
{
nsresult rv;
nsXPIDLCString source;
rv = aSource->GetValue(getter_Copies(source));
rv = rdf_WriteOp("chg-from", aSource, aProperty, aOldTarget);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString property;
rv = aProperty->GetValue(getter_Copies(property));
rv = rdf_WriteOp("chg-to", aSource, aProperty, aNewTarget);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFResource> resource;
nsCOMPtr<nsIRDFLiteral> literal;
printf("unassert [%s]\n", (const char*) source);
printf(" --[%s]--\n", (const char*) property);
if ((resource = do_QueryInterface(aTarget)) != nsnull) {
nsXPIDLCString target;
rv = resource->GetValue(getter_Copies(target));
if (NS_FAILED(rv)) return rv;
printf(" ->[%s]\n", (const char*) target);
}
else if ((literal = do_QueryInterface(aTarget)) != nsnull) {
nsXPIDLString target;
rv = literal->GetValue(getter_Copies(target));
if (NS_FAILED(rv)) return rv;
char* p = nsAutoString(target).ToNewCString();
if (! p)
return NS_ERROR_OUT_OF_MEMORY;
printf(" ->\"%s\"\n", p);
delete[] p;
}
printf("\n");
return NS_OK;
}
NS_IMETHODIMP
Observer::OnMove(nsIRDFResource* aOldSource,
nsIRDFResource* aNewSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget)
{
nsresult rv;
rv = rdf_WriteOp("mv-from", aOldSource, aProperty, aTarget);
if (NS_FAILED(rv)) return rv;
rv = rdf_WriteOp("mv-to", aNewSource, aProperty, aTarget);
if (NS_FAILED(rv)) return rv;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
int
@ -284,16 +296,22 @@ main(int argc, char** argv)
// Create a stream data source and initialize it on argv[1], which
// is hopefully a "file:" URL. (Actually, we can do _any_ kind of
// URL, but only a "file:" URL will be written back to disk.)
nsCOMPtr<nsIRDFXMLDataSource> ds;
nsCOMPtr<nsIRDFDataSource> ds;
rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID,
nsnull,
kIRDFXMLDataSourceIID,
nsIRDFDataSource::GetIID(),
getter_AddRefs(ds));
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create RDF/XML data source");
if (NS_FAILED(rv)) return rv;
rv = ds->Init(argv[1]);
nsCOMPtr<nsIRDFRemoteDataSource> remote
= do_QueryInterface(ds);
if (! remote)
return NS_ERROR_UNEXPECTED;
rv = remote->Init(argv[1]);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to initialize data source");
if (NS_FAILED(rv)) return rv;
@ -308,7 +326,7 @@ main(int argc, char** argv)
while (1) {
// Okay, this should load the XML file...
rv = ds->Open(PR_TRUE);
rv = remote->Refresh(PR_TRUE);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to open datasource");
if (NS_FAILED(rv)) return rv;