зеркало из https://github.com/mozilla/gecko-dev.git
Consolidated DefaultResourceImpl with nsRDFResource.
This commit is contained in:
Родитель
c4fbf9fb05
Коммит
da560b4f89
|
@ -27,6 +27,7 @@
|
|||
#define nsIRDFNode_h__
|
||||
|
||||
#include "nscore.h"
|
||||
#include "rdf.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
// {0F78DA50-8321-11d2-8EAC-00805F29F370}
|
||||
|
@ -52,7 +53,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
class nsIRDFNode : public nsISupports {
|
||||
class NS_RDF nsIRDFNode : public nsISupports {
|
||||
public:
|
||||
static const nsIID& IID() { static nsIID iid = NS_IRDFNODE_IID; return iid; }
|
||||
|
||||
|
@ -71,7 +72,7 @@ public:
|
|||
#define NS_IRDFRESOURCE_IID \
|
||||
{ 0xe0c493d1, 0x9542, 0x11d2, { 0x8e, 0xb8, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
class nsIRDFResource : public nsIRDFNode {
|
||||
class NS_RDF nsIRDFResource : public nsIRDFNode {
|
||||
public:
|
||||
static const nsIID& IID() { static nsIID iid = NS_IRDFRESOURCE_IID; return iid; }
|
||||
|
||||
|
@ -96,7 +97,7 @@ public:
|
|||
#define NS_IRDFLITERAL_IID \
|
||||
{ 0xe0c493d2, 0x9542, 0x11d2, { 0x8e, 0xb8, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
class nsIRDFLiteral : public nsIRDFNode {
|
||||
class NS_RDF nsIRDFLiteral : public nsIRDFNode {
|
||||
public:
|
||||
static const nsIID& IID() { static nsIID iid = NS_IRDFLITERAL_IID; return iid; }
|
||||
|
||||
|
|
|
@ -20,12 +20,13 @@
|
|||
#define nsRDFResource_h__
|
||||
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nscore.h"
|
||||
|
||||
/**
|
||||
* This simple base class implements nsIRDFResource, and can be used as a
|
||||
* superclass for more sophisticated resource implementations.
|
||||
*/
|
||||
class nsRDFResource : public nsIRDFResource {
|
||||
class NS_RDF nsRDFResource : public nsIRDFResource {
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -43,7 +44,7 @@ public:
|
|||
virtual ~nsRDFResource(void);
|
||||
|
||||
protected:
|
||||
const char* mURI;
|
||||
char* mURI;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -68,4 +68,18 @@ static const char* kTag##prefix##_##name = kURI##prefix##_##name## + sizeof(##na
|
|||
|
||||
/*@}*/
|
||||
|
||||
#ifdef _IMPL_NS_RDF
|
||||
#ifdef XP_PC
|
||||
#define NS_RDF _declspec(dllexport)
|
||||
#else /* !XP_PC */
|
||||
#define NS_RDF
|
||||
#endif /* !XP_PC */
|
||||
#else /* !_IMPL_NS_RDF */
|
||||
#ifdef XP_PC
|
||||
#define NS_RDF _declspec(dllimport)
|
||||
#else /* !XP_PC */
|
||||
#define NS_RDF
|
||||
#endif /* !XP_PC */
|
||||
#endif /* !_IMPL_NS_RDF */
|
||||
|
||||
#endif /* rdf_h___ */
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
LCFLAGS=-D_IMPL_NS_RDF -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
MODULE=rdf
|
||||
LIBRARY_NAME=rdfbase_s
|
||||
|
||||
|
|
|
@ -24,147 +24,8 @@
|
|||
|
||||
*/
|
||||
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFResourceFactory.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "plstr.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
|
||||
static NS_DEFINE_IID(kIRDFResourceFactoryIID, NS_IRDFRESOURCEFACTORY_IID);
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class DefaultResourceImpl : public nsIRDFResource
|
||||
{
|
||||
public:
|
||||
DefaultResourceImpl(const char* uri);
|
||||
virtual ~DefaultResourceImpl(void);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFNode
|
||||
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;
|
||||
|
||||
// nsIRDFResource
|
||||
NS_IMETHOD GetValue(const char* *uri) const;
|
||||
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;
|
||||
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
|
||||
|
||||
// Implementation methods
|
||||
const char* GetURI(void) const {
|
||||
return mURI;
|
||||
}
|
||||
|
||||
private:
|
||||
char* mURI;
|
||||
};
|
||||
|
||||
|
||||
DefaultResourceImpl::DefaultResourceImpl(const char* uri)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mURI = PL_strdup(uri);
|
||||
}
|
||||
|
||||
|
||||
DefaultResourceImpl::~DefaultResourceImpl(void)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsIRDFService* mgr;
|
||||
rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||
kIRDFServiceIID,
|
||||
(nsISupports**) &mgr);
|
||||
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mgr->UnCacheResource(this);
|
||||
nsServiceManager::ReleaseService(kRDFServiceCID, mgr);
|
||||
}
|
||||
|
||||
// N.B. that we need to free the URI *after* we un-cache the resource,
|
||||
// due to the way that the resource manager is implemented.
|
||||
PL_strfree(mURI);
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(DefaultResourceImpl);
|
||||
NS_IMPL_RELEASE(DefaultResourceImpl);
|
||||
|
||||
nsresult
|
||||
DefaultResourceImpl::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kIRDFResourceIID) ||
|
||||
iid.Equals(kIRDFNodeIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFResource*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DefaultResourceImpl::EqualsNode(nsIRDFNode* node, PRBool* result) const
|
||||
{
|
||||
nsresult rv;
|
||||
nsIRDFResource* resource;
|
||||
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
|
||||
rv = EqualsResource(resource, result);
|
||||
NS_RELEASE(resource);
|
||||
}
|
||||
else {
|
||||
*result = PR_FALSE;
|
||||
rv = NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DefaultResourceImpl::GetValue(const char* *uri) const
|
||||
{
|
||||
if (!uri)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*uri = mURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
DefaultResourceImpl::EqualsResource(const nsIRDFResource* resource, PRBool* result) const
|
||||
{
|
||||
if (!resource || !result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = (resource == this);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
DefaultResourceImpl::EqualsString(const char* uri, PRBool* result) const
|
||||
{
|
||||
if (!uri || !result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = (PL_strcmp(uri, mURI) == 0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#include "nsRDFResource.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -191,7 +52,7 @@ DefaultResourceFactoryImpl::~DefaultResourceFactoryImpl(void)
|
|||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(DefaultResourceFactoryImpl, kIRDFResourceFactoryIID);
|
||||
NS_IMPL_ISUPPORTS(DefaultResourceFactoryImpl, nsIRDFResourceFactory::IID());
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -201,7 +62,7 @@ DefaultResourceFactoryImpl::CreateResource(const char* aURI, nsIRDFResource** aR
|
|||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
DefaultResourceImpl* resource = new DefaultResourceImpl(aURI);
|
||||
nsRDFResource* resource = new nsRDFResource(aURI);
|
||||
if (! resource)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
|
|
|
@ -18,22 +18,39 @@
|
|||
|
||||
#include "nsRDFResource.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsRDFCID.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFResource::nsRDFResource(const char* uri)
|
||||
: mURI(uri)
|
||||
: mURI(nsCRT::strdup(uri))
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsRDFResource::~nsRDFResource(void)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsIRDFService* mgr;
|
||||
rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||
nsIRDFService::IID(),
|
||||
(nsISupports**) &mgr);
|
||||
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mgr->UnCacheResource(this);
|
||||
nsServiceManager::ReleaseService(kRDFServiceCID, mgr);
|
||||
}
|
||||
|
||||
// N.B. that we need to free the URI *after* we un-cache the resource,
|
||||
// due to the way that the resource manager is implemented.
|
||||
delete[] mURI;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsRDFResource)
|
||||
|
@ -46,13 +63,10 @@ nsRDFResource::QueryInterface(REFNSIID iid, void** result)
|
|||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kIRDFResourceIID) ||
|
||||
iid.Equals(kIRDFNodeIID) ||
|
||||
if (iid.Equals(nsIRDFResource::IID()) ||
|
||||
iid.Equals(nsIRDFNode::IID()) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFResource*, this);
|
||||
}
|
||||
|
||||
if (*result != nsnull) {
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -63,12 +77,12 @@ nsRDFResource::QueryInterface(REFNSIID iid, void** result)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIRDFNode methods:
|
||||
|
||||
NS_METHOD
|
||||
NS_IMETHODIMP
|
||||
nsRDFResource::EqualsNode(nsIRDFNode* node, PRBool* result) const
|
||||
{
|
||||
nsresult rv;
|
||||
nsIRDFResource* resource;
|
||||
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
|
||||
if (NS_SUCCEEDED(node->QueryInterface(nsIRDFResource::IID(), (void**)&resource))) {
|
||||
rv = EqualsResource(resource, result);
|
||||
NS_RELEASE(resource);
|
||||
}
|
||||
|
@ -82,7 +96,7 @@ nsRDFResource::EqualsNode(nsIRDFNode* node, PRBool* result) const
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIRDFResource methods:
|
||||
|
||||
NS_METHOD
|
||||
NS_IMETHODIMP
|
||||
nsRDFResource::GetValue(const char* *uri) const
|
||||
{
|
||||
if (!uri)
|
||||
|
@ -91,7 +105,7 @@ nsRDFResource::GetValue(const char* *uri) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
NS_IMETHODIMP
|
||||
nsRDFResource::EqualsResource(const nsIRDFResource* resource, PRBool* result) const
|
||||
{
|
||||
if (!resource || !result)
|
||||
|
@ -99,13 +113,13 @@ nsRDFResource::EqualsResource(const nsIRDFResource* resource, PRBool* result) co
|
|||
|
||||
const char *uri;
|
||||
if (NS_SUCCEEDED(resource->GetValue(&uri))) {
|
||||
return EqualsString(uri, result) ? NS_OK : NS_ERROR_FAILURE;
|
||||
return NS_SUCCEEDED(EqualsString(uri, result)) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
NS_IMETHODIMP
|
||||
nsRDFResource::EqualsString(const char* uri, PRBool* result) const
|
||||
{
|
||||
if (!uri || !result)
|
||||
|
|
Загрузка…
Ссылка в новой задаче