1998-12-24 06:20:35 +00:00
|
|
|
/* -*- 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.
|
|
|
|
*/
|
|
|
|
|
1999-01-05 21:22:20 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
The RDF factory implementation.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
1998-12-24 06:20:35 +00:00
|
|
|
#include "nsIFactory.h"
|
1999-01-20 01:42:13 +00:00
|
|
|
#include "nsIRDFCompositeDataSource.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsIRDFContentModelBuilder.h"
|
1999-01-05 03:53:15 +00:00
|
|
|
#include "nsIRDFContentSink.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsIRDFDocument.h"
|
1999-01-05 03:53:15 +00:00
|
|
|
#include "nsIRDFService.h"
|
1999-01-20 01:42:13 +00:00
|
|
|
#include "nsIRDFXMLDataSource.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsISupports.h"
|
1998-12-24 06:39:28 +00:00
|
|
|
#include "nsRDFBaseDataSources.h"
|
1998-12-24 06:20:35 +00:00
|
|
|
#include "nsRDFBuiltInDataSources.h"
|
|
|
|
#include "nsRDFCID.h"
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kRDFBookmarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
|
1999-01-20 01:42:13 +00:00
|
|
|
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
|
1999-01-12 19:41:06 +00:00
|
|
|
static NS_DEFINE_CID(kRDFDocumentCID, NS_RDFDOCUMENT_CID);
|
|
|
|
static NS_DEFINE_CID(kRDFHTMLBuilderCID, NS_RDFHTMLBUILDER_CID);
|
1999-01-05 03:53:15 +00:00
|
|
|
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
|
|
|
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
1999-01-14 10:55:08 +00:00
|
|
|
static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
|
1999-01-20 01:42:13 +00:00
|
|
|
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
1999-01-12 19:41:06 +00:00
|
|
|
static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID);
|
1998-12-24 06:20:35 +00:00
|
|
|
|
|
|
|
class RDFFactoryImpl : public nsIFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RDFFactoryImpl(const nsCID &aClass);
|
|
|
|
|
|
|
|
// nsISupports methods
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIFactory methods
|
|
|
|
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult);
|
|
|
|
|
|
|
|
NS_IMETHOD LockFactory(PRBool aLock);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~RDFFactoryImpl();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCID mClassID;
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
RDFFactoryImpl::RDFFactoryImpl(const nsCID &aClass)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
mClassID = aClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
RDFFactoryImpl::~RDFFactoryImpl()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFFactoryImpl::QueryInterface(const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
if (! aResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// Always NULL result, in case of failure
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aResult = NS_STATIC_CAST(nsISupports*, this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
} else if (aIID.Equals(kIFactoryIID)) {
|
|
|
|
*aResult = NS_STATIC_CAST(nsIFactory*, this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(RDFFactoryImpl);
|
|
|
|
NS_IMPL_RELEASE(RDFFactoryImpl);
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
if (! aResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
PRBool wasRefCounted = PR_TRUE;
|
|
|
|
nsISupports *inst = nsnull;
|
1999-01-05 03:53:15 +00:00
|
|
|
if (mClassID.Equals(kRDFServiceCID)) {
|
|
|
|
if (NS_FAILED(rv = NS_NewRDFService((nsIRDFService**) &inst)))
|
1998-12-24 06:20:35 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-01-05 03:53:15 +00:00
|
|
|
else if (mClassID.Equals(kRDFInMemoryDataSourceCID)) {
|
|
|
|
|
1998-12-28 04:12:55 +00:00
|
|
|
if (NS_FAILED(rv = NS_NewRDFInMemoryDataSource((nsIRDFDataSource**) &inst)))
|
1998-12-24 06:20:35 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-01-20 01:42:13 +00:00
|
|
|
else if (mClassID.Equals(kRDFXMLDataSourceCID)) {
|
|
|
|
if (NS_FAILED(rv = NS_NewRDFXMLDataSource((nsIRDFXMLDataSource**) &inst)))
|
1999-01-05 03:53:15 +00:00
|
|
|
return rv;
|
1998-12-24 06:20:35 +00:00
|
|
|
}
|
|
|
|
else if (mClassID.Equals(kRDFBookmarkDataSourceCID)) {
|
|
|
|
if (NS_FAILED(rv = NS_NewRDFBookmarkDataSource((nsIRDFDataSource**) &inst)))
|
|
|
|
return rv;
|
|
|
|
}
|
1999-01-20 01:42:13 +00:00
|
|
|
else if (mClassID.Equals(kRDFCompositeDataSourceCID)) {
|
|
|
|
if (NS_FAILED(rv = NS_NewRDFCompositeDataSource((nsIRDFCompositeDataSource**) &inst)))
|
1998-12-24 06:20:35 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-01-12 19:41:06 +00:00
|
|
|
else if (mClassID.Equals(kRDFDocumentCID)) {
|
|
|
|
if (NS_FAILED(rv = NS_NewRDFDocument((nsIRDFDocument**) &inst)))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
else if (mClassID.Equals(kRDFHTMLBuilderCID)) {
|
|
|
|
if (NS_FAILED(rv = NS_NewRDFHTMLBuilder((nsIRDFContentModelBuilder**) &inst)))
|
1998-12-24 06:20:35 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-01-12 19:41:06 +00:00
|
|
|
else if (mClassID.Equals(kRDFTreeBuilderCID)) {
|
|
|
|
if (NS_FAILED(rv = NS_NewRDFTreeBuilder((nsIRDFContentModelBuilder**) &inst)))
|
1998-12-24 06:20:35 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-01-14 10:55:08 +00:00
|
|
|
else if (mClassID.Equals(kRDFContentSinkCID)) {
|
|
|
|
if (NS_FAILED(rv = NS_NewRDFContentSink((nsIRDFContentSink**) &inst)))
|
1999-01-05 03:53:15 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-12-24 06:20:35 +00:00
|
|
|
else {
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! inst)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult)))
|
|
|
|
// We didn't get the right interface, so clean up
|
|
|
|
delete inst;
|
|
|
|
|
|
|
|
if (wasRefCounted)
|
|
|
|
NS_IF_RELEASE(inst);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult RDFFactoryImpl::LockFactory(PRBool aLock)
|
|
|
|
{
|
|
|
|
// Not implemented in simplest case.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return the proper factory to the caller
|
|
|
|
extern "C" PR_IMPLEMENT(nsresult)
|
1999-01-26 01:21:25 +00:00
|
|
|
NSGetFactory(const nsCID &aClass, nsISupports* aServiceManager, nsIFactory **aFactory)
|
1998-12-24 06:20:35 +00:00
|
|
|
{
|
|
|
|
if (! aFactory)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-01-26 01:21:25 +00:00
|
|
|
RDFFactoryImpl* factory = new RDFFactoryImpl(aClass);
|
|
|
|
if (factory == nsnull)
|
1998-12-24 06:20:35 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
1999-01-26 01:21:25 +00:00
|
|
|
NS_ADDREF(factory);
|
|
|
|
*aFactory = factory;
|
|
|
|
return NS_OK;
|
1998-12-24 06:20:35 +00:00
|
|
|
}
|
|
|
|
|