From 434f71e75d9bc3e576a057de352e5e7660880484 Mon Sep 17 00:00:00 2001 From: "rjc%netscape.com" Date: Fri, 26 Feb 1999 02:14:51 +0000 Subject: [PATCH] Add in RDFCore. --- xpfe/AppCores/idl/RDFCore.idl | 10 + xpfe/AppCores/macbuild/AppCores.mcp | Bin 60819 -> 63379 bytes xpfe/AppCores/public/nsIDOMRDFCore.h | 55 ++++ xpfe/AppCores/src/Makefile.in | 3 + xpfe/AppCores/src/makefile.win | 3 + xpfe/AppCores/src/nsAppCoresNameSet.cpp | 9 + xpfe/AppCores/src/nsJSRDFCore.cpp | 362 ++++++++++++++++++++++++ xpfe/AppCores/src/nsRDFCore.cpp | 161 +++++++++++ xpfe/AppCores/src/nsRDFCore.h | 61 ++++ xpfe/AppCores/src/nsRDFCoreFactory.cpp | 131 +++++++++ xpfe/AppCores/src/nsRDFCoreFactory.h | 0 11 files changed, 795 insertions(+) create mode 100644 xpfe/AppCores/idl/RDFCore.idl create mode 100644 xpfe/AppCores/public/nsIDOMRDFCore.h create mode 100644 xpfe/AppCores/src/nsJSRDFCore.cpp create mode 100644 xpfe/AppCores/src/nsRDFCore.cpp create mode 100644 xpfe/AppCores/src/nsRDFCore.h create mode 100644 xpfe/AppCores/src/nsRDFCoreFactory.cpp create mode 100644 xpfe/AppCores/src/nsRDFCoreFactory.h diff --git a/xpfe/AppCores/idl/RDFCore.idl b/xpfe/AppCores/idl/RDFCore.idl new file mode 100644 index 00000000000..e469cb5d99b --- /dev/null +++ b/xpfe/AppCores/idl/RDFCore.idl @@ -0,0 +1,10 @@ +interface RDFCore : BaseAppCore +{ + +/* IID: { 0xdf365f00, 0xcc53, 0x11d2, \ + { 0x8f, 0xdf, 0x0, 0x08, 0xc7, 0x0a, 0xdc, 0x7b } } */ + + void RDFCore(); + + void doSort(in Node node, in DOMString sortResource); + }; diff --git a/xpfe/AppCores/macbuild/AppCores.mcp b/xpfe/AppCores/macbuild/AppCores.mcp index 3bfd06ea265ea7ab5c7c6e20b93c30732fb28ca3..49be4b0d215cf63b1d4450f32cae08f68bb5f5ad 100644 GIT binary patch delta 1258 zcmc(fO-LI-6vtf)vrV zQUnhY#(U|xP;8e9z14nzP%o825B-4l5JN9|@KDI5Z{te|r4)MVz<+=5y?Hw`Z+3R* zM~)tHrC~*xBZP2-Fg8LCfk#hDD-0=FM~}Yg==HKy-U9s%DUVWY1*4yV2dI~xtuf8 z7u!1OFl6e2(B%aMKoV#G)CQ^tO@c!7l5sgToGj3Uj*^F#JT9Gc~1!N<#1?iv> z+i@9Gas>k=NHdkoHu5Jh_N(xGf&Z!SiGMD<6YKfw28{h_1K{)b3v5T+F3!w|VwbC} zz169^?b|X5mf7h@bXpAh17pFffsyf{;JC-{3&a2ZIzW|g%+nm$U~S%Zy!NIQn%svzcAGCm80MdzDQ zJFJ_rJE)+&*?}4R>DvQ)Rk}(0FJUe%1ulnt bd%Z(TGG}Uydl1MkrJ!37A-<_f8JYhHUoZ|^ delta 731 zcmbRIo_X?ZX5r-g{2T@b24)5ZMhymrr$GAIMqvr|$p^NvOb%ClG1*y7Vsf%tjiC}y zkpm-;0Af=h6%WJ-3=C}g3=AAVCXio{Sd^NVTp1s4Xp&d#88-P2hy3ItM|vi@luZ83 zX~8Hw*@VkkI0mF22x1xdz;qk~)8ry9=gnuiK5}q@MZm;l3yzM-2aohmbSc~%Aj&Kt z3Un6(NFGFUZ2GNznt{RQ|K<(b1eqoVuuT5&h-LDzLt6FXZk|4_ObiUNP+AU3%R^}e zD6I&km7ugTls1FX=1|%KN?Sr{Qz)$prPZLcI)t`j(0~dUL1|4Wtp%mEp|lQ^HiptB zlMf#IA_8=|6;yy9N(*ex(d^@yT&z{F*}*J@5gaX-%*EN*)fpJ{PHuh}^qX<=D@!0> z@BjbZM}hpGjGJsknkFCFtGapqrQeL3KLqtMZPtDk%sN@`HC(8VY4f2onUa&WKcq>q zG~^bS0Fwao3vkGT33gyoU~HJY`hyk|$B)U^Kj?d`0E!FbmK0h3lkbrs(0|OJoRegisterGlobalName("RDFCore", + kRDFCoreCID, + PR_TRUE); + + if (NS_OK != result) return result; + result = manager->RegisterGlobalName("ToolbarCore", kToolbarCoreCID, PR_TRUE); diff --git a/xpfe/AppCores/src/nsJSRDFCore.cpp b/xpfe/AppCores/src/nsJSRDFCore.cpp new file mode 100644 index 00000000000..a091f54bcc6 --- /dev/null +++ b/xpfe/AppCores/src/nsJSRDFCore.cpp @@ -0,0 +1,362 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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. + */ +/* AUTO-GENERATED. DO NOT EDIT!!! */ + +#include "jsapi.h" +#include "nsJSUtils.h" +#include "nscore.h" +#include "nsIScriptContext.h" +#include "nsIJSScriptObject.h" +#include "nsIScriptObjectOwner.h" +#include "nsIScriptGlobalObject.h" +#include "nsIPtr.h" +#include "nsString.h" +#include "nsIDOMNode.h" +#include "nsIDOMRDFCore.h" +#include "nsIScriptNameSpaceManager.h" +#include "nsRepository.h" +#include "nsDOMCID.h" + + +static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID); +static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID); +static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID); +static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID); +static NS_DEFINE_IID(kIRDFCoreIID, NS_IDOMRDFCORE_IID); + +NS_DEF_PTR(nsIDOMNode); +NS_DEF_PTR(nsIDOMRDFCore); + + +/***********************************************************************/ +// +// RDFCore Properties Getter +// +PR_STATIC_CALLBACK(JSBool) +GetRDFCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMRDFCore *a = (nsIDOMRDFCore*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case 0: + default: + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp); + } + + return PR_TRUE; +} + +/***********************************************************************/ +// +// RDFCore Properties Setter +// +PR_STATIC_CALLBACK(JSBool) +SetRDFCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + nsIDOMRDFCore *a = (nsIDOMRDFCore*)JS_GetPrivate(cx, obj); + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == a) { + return JS_TRUE; + } + + if (JSVAL_IS_INT(id)) { + switch(JSVAL_TO_INT(id)) { + case 0: + default: + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); + } + } + else { + return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp); + } + + return PR_TRUE; +} + + +// +// RDFCore finalizer +// +PR_STATIC_CALLBACK(void) +FinalizeRDFCore(JSContext *cx, JSObject *obj) +{ + nsJSUtils::nsGenericFinalize(cx, obj); +} + + +// +// RDFCore enumerate +// +PR_STATIC_CALLBACK(JSBool) +EnumerateRDFCore(JSContext *cx, JSObject *obj) +{ + return nsJSUtils::nsGenericEnumerate(cx, obj); +} + + +// +// RDFCore resolve +// +PR_STATIC_CALLBACK(JSBool) +ResolveRDFCore(JSContext *cx, JSObject *obj, jsval id) +{ + return nsJSUtils::nsGenericResolve(cx, obj, id); +} + + +// +// Native method DoSort +// +PR_STATIC_CALLBACK(JSBool) +RDFCoreDoSort(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMRDFCore *nativeThis = (nsIDOMRDFCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsIDOMNodePtr b0; + nsAutoString b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 2) { + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0, + kINodeIID, + "Node", + cx, + argv[0])) { + return JS_FALSE; + } + + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + if (NS_OK != nativeThis->DoSort(b0, b1)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function doSort requires 2 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + +/***********************************************************************/ +// +// class for RDFCore +// +JSClass RDFCoreClass = { + "RDFCore", + JSCLASS_HAS_PRIVATE, + JS_PropertyStub, + JS_PropertyStub, + GetRDFCoreProperty, + SetRDFCoreProperty, + EnumerateRDFCore, + ResolveRDFCore, + JS_ConvertStub, + FinalizeRDFCore +}; + + +// +// RDFCore class properties +// +static JSPropertySpec RDFCoreProperties[] = +{ + {0} +}; + + +// +// RDFCore class methods +// +static JSFunctionSpec RDFCoreMethods[] = +{ + {"doSort", RDFCoreDoSort, 2}, + {0} +}; + + +// +// RDFCore constructor +// +PR_STATIC_CALLBACK(JSBool) +RDFCore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsresult result; + nsIID classID; + nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx); + nsIScriptNameSpaceManager* manager; + nsIDOMRDFCore *nativeThis; + nsIScriptObjectOwner *owner = nsnull; + + static NS_DEFINE_IID(kIDOMRDFCoreIID, NS_IDOMRDFCORE_IID); + + result = context->GetNameSpaceManager(&manager); + if (NS_OK != result) { + return JS_FALSE; + } + + result = manager->LookupName("RDFCore", PR_TRUE, classID); + NS_RELEASE(manager); + if (NS_OK != result) { + return JS_FALSE; + } + + result = nsRepository::CreateInstance(classID, + nsnull, + kIDOMRDFCoreIID, + (void **)&nativeThis); + if (NS_OK != result) { + return JS_FALSE; + } + + // XXX We should be calling Init() on the instance + + result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner); + if (NS_OK != result) { + NS_RELEASE(nativeThis); + return JS_FALSE; + } + + owner->SetScriptObject((void *)obj); + JS_SetPrivate(cx, obj, nativeThis); + + NS_RELEASE(owner); + return JS_TRUE; +} + +// +// RDFCore class initialization +// +extern "C" NS_DOM nsresult NS_InitRDFCoreClass(nsIScriptContext *aContext, void **aPrototype) +{ + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + JSObject *proto = nsnull; + JSObject *constructor = nsnull; + JSObject *parent_proto = nsnull; + JSObject *global = JS_GetGlobalObject(jscontext); + jsval vp; + + if ((PR_TRUE != JS_LookupProperty(jscontext, global, "RDFCore", &vp)) || + !JSVAL_IS_OBJECT(vp) || + ((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) || + (PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) || + !JSVAL_IS_OBJECT(vp)) { + + if (NS_OK != NS_InitBaseAppCoreClass(aContext, (void **)&parent_proto)) { + return NS_ERROR_FAILURE; + } + proto = JS_InitClass(jscontext, // context + global, // global object + parent_proto, // parent proto + &RDFCoreClass, // JSClass + RDFCore, // JSNative ctor + 0, // ctor args + RDFCoreProperties, // proto props + RDFCoreMethods, // proto funcs + nsnull, // ctor props (static) + nsnull); // ctor funcs (static) + if (nsnull == proto) { + return NS_ERROR_FAILURE; + } + + } + else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) { + proto = JSVAL_TO_OBJECT(vp); + } + else { + return NS_ERROR_FAILURE; + } + + if (aPrototype) { + *aPrototype = proto; + } + return NS_OK; +} + + +// +// Method for creating a new RDFCore JavaScript object +// +extern "C" NS_DOM nsresult NS_NewScriptRDFCore(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn) +{ + NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptRDFCore"); + JSObject *proto; + JSObject *parent; + nsIScriptObjectOwner *owner; + JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); + nsresult result = NS_OK; + nsIDOMRDFCore *aRDFCore; + + if (nsnull == aParent) { + parent = nsnull; + } + else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) { + if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) { + NS_RELEASE(owner); + return NS_ERROR_FAILURE; + } + NS_RELEASE(owner); + } + else { + return NS_ERROR_FAILURE; + } + + if (NS_OK != NS_InitRDFCoreClass(aContext, (void **)&proto)) { + return NS_ERROR_FAILURE; + } + + result = aSupports->QueryInterface(kIRDFCoreIID, (void **)&aRDFCore); + if (NS_OK != result) { + return result; + } + + // create a js object for this class + *aReturn = JS_NewObject(jscontext, &RDFCoreClass, proto, parent); + if (nsnull != *aReturn) { + // connect the native object to the js object + JS_SetPrivate(jscontext, (JSObject *)*aReturn, aRDFCore); + } + else { + NS_RELEASE(aRDFCore); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} diff --git a/xpfe/AppCores/src/nsRDFCore.cpp b/xpfe/AppCores/src/nsRDFCore.cpp new file mode 100644 index 00000000000..df473efc4b3 --- /dev/null +++ b/xpfe/AppCores/src/nsRDFCore.cpp @@ -0,0 +1,161 @@ + +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#include "nsRDFCore.h" +#include "nsIBrowserWindow.h" +#include "nsIWebShell.h" +#include "pratom.h" +#include "nsRepository.h" +#include "nsAppCores.h" +#include "nsAppCoresCIDs.h" +#include "nsAppCoresManager.h" + +#include "nsIScriptContext.h" +#include "nsIScriptContextOwner.h" +#include "nsIDOMDocument.h" +#include "nsIDocument.h" +#include "nsIDOMWindow.h" + + +// Globals +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIRDFCoreIID, NS_IDOMRDFCORE_IID); + +static NS_DEFINE_IID(kIDOMDocumentIID, nsIDOMDocument::IID()); +static NS_DEFINE_IID(kIDocumentIID, nsIDocument::IID()); + +static NS_DEFINE_IID(kRDFCoreCID, NS_RDFCORE_CID); +static NS_DEFINE_IID(kBrowserWindowCID, NS_BROWSER_WINDOW_CID); + + +///////////////////////////////////////////////////////////////////////// +// nsRDFCore +///////////////////////////////////////////////////////////////////////// + +nsRDFCore::nsRDFCore() +{ + printf("Created nsRDFCore\n"); + mScriptObject = nsnull; + mScriptContext = nsnull; +/* + mWindow = nsnull; +*/ + IncInstanceCount(); + NS_INIT_REFCNT(); +} + +nsRDFCore::~nsRDFCore() +{ + NS_IF_RELEASE(mScriptContext); +/* + NS_IF_RELEASE(mWindow); +*/ + DecInstanceCount(); +} + + +NS_IMPL_ADDREF(nsRDFCore) +NS_IMPL_RELEASE(nsRDFCore) + + +NS_IMETHODIMP +nsRDFCore::QueryInterface(REFNSIID aIID,void** aInstancePtr) +{ + if (aInstancePtr == NULL) { + return NS_ERROR_NULL_POINTER; + } + + // Always NULL result, in case of failure + *aInstancePtr = NULL; + +printf("About to compare RDFCOREIIDs\n"); + + if ( aIID.Equals(kIRDFCoreIID) ) { + *aInstancePtr = (void*) ((nsIDOMRDFCore*)this); + AddRef(); + return NS_OK; + } + +printf("RDFCOREIIDs did not matched.\n"); + + return nsBaseAppCore::QueryInterface(aIID, aInstancePtr); +} + + +NS_IMETHODIMP +nsRDFCore::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject) +{ + NS_PRECONDITION(nsnull != aScriptObject, "null arg"); + nsresult res = NS_OK; + if (nsnull == mScriptObject) + { + res = NS_NewScriptRDFCore(aContext, + (nsISupports *)(nsIDOMRDFCore*)this, + nsnull, + &mScriptObject); + } + + *aScriptObject = mScriptObject; + return res; +} + +NS_IMETHODIMP +nsRDFCore::Init(const nsString& aId) +{ + + nsBaseAppCore::Init(aId); + + nsAppCoresManager* sdm = new nsAppCoresManager(); + sdm->Add((nsIDOMBaseAppCore *)(nsBaseAppCore *)this); + delete sdm; + + return NS_OK; +} + +NS_IMETHODIMP +nsRDFCore::DoSort(nsIDOMNode* node, const nsString& sortResource) +{ + printf("nsRDFCore::DoSort entered!!!\n"); + +/* + if (nsnull == mScriptContext) { + return NS_ERROR_FAILURE; + } +*/ + + printf("----------------------------\n"); + printf("-- Sort \n"); + printf("----------------------------\n"); + printf("Column: %s \n", sortResource.ToNewCString()); + printf("----------------------------\n"); +/* + if (nsnull != mScriptContext) { + const char* url = ""; + PRBool isUndefined = PR_FALSE; + nsString rVal; + mScriptContext->EvaluateString(mScript, url, 0, rVal, &isUndefined); + } +*/ + return NS_OK; +} + + + + diff --git a/xpfe/AppCores/src/nsRDFCore.h b/xpfe/AppCores/src/nsRDFCore.h new file mode 100644 index 00000000000..fc877deceb1 --- /dev/null +++ b/xpfe/AppCores/src/nsRDFCore.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +#ifndef nsRDFCorePrivate_h___ +#define nsRDFCorePrivate_h___ + +//#include "nsAppCores.h" + +#include "nscore.h" +#include "nsString.h" +#include "nsISupports.h" + +#include "nsIDOMRDFCore.h" +#include "nsBaseAppCore.h" + +class nsIScriptContext; +class nsIDOMNode; + +//////////////////////////////////////////////////////////////////////////////// +// nsRDFCore: +//////////////////////////////////////////////////////////////////////////////// + +class nsRDFCore : public nsBaseAppCore, + public nsIDOMRDFCore +{ + public: + + nsRDFCore(); + virtual ~nsRDFCore(); + + + NS_DECL_ISUPPORTS + NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject); + NS_IMETHOD Init(const nsString& aId); + NS_IMETHOD GetId(nsString& aId) { return nsBaseAppCore::GetId(aId); } + + NS_IMETHOD DoSort(nsIDOMNode* node, const nsString& sortResource); + + protected: + + nsString mScript; + + nsIScriptContext *mScriptContext; + +}; + +#endif // nsRDFCore_h___ diff --git a/xpfe/AppCores/src/nsRDFCoreFactory.cpp b/xpfe/AppCores/src/nsRDFCoreFactory.cpp new file mode 100644 index 00000000000..547d0ff73f8 --- /dev/null +++ b/xpfe/AppCores/src/nsRDFCoreFactory.cpp @@ -0,0 +1,131 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are Copyright (C) 1998 + * Netscape Communications Corporation. All Rights Reserved. + */ + +#include "nsAppCores.h" +#include "nsRDFCoreFactory.h" +#include "nsRDFCore.h" +#include "pratom.h" + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); + +///////////////////////////////////////////////////////////////////////// +// nsRDFCoreFactory +///////////////////////////////////////////////////////////////////////// + +nsRDFCoreFactory::nsRDFCoreFactory(void) +{ + mRefCnt=0; + IncInstanceCount(); +} + +nsRDFCoreFactory::~nsRDFCoreFactory(void) +{ + DecInstanceCount(); +} + + + +NS_IMETHODIMP +nsRDFCoreFactory::QueryInterface(REFNSIID aIID,void** aInstancePtr) +{ + if (aInstancePtr == NULL) + { + return NS_ERROR_NULL_POINTER; + } + + // Always NULL result, in case of failure + *aInstancePtr = NULL; + + if ( aIID.Equals(kISupportsIID) ) + { + *aInstancePtr = (void*) this; + } + else if ( aIID.Equals(kIFactoryIID) ) + { + *aInstancePtr = (void*) this; + } + + if (aInstancePtr == NULL) + { + return NS_ERROR_NO_INTERFACE; + } + + AddRef(); + return NS_OK; +} + + + +NS_IMETHODIMP +nsRDFCoreFactory::AddRef(void) +{ + return ++mRefCnt; +} + + +NS_IMETHODIMP +nsRDFCoreFactory::Release(void) +{ + if (--mRefCnt ==0) + { +// delete this; + return 0; // Don't access mRefCnt after deleting! + } + + return mRefCnt; +} + +NS_IMETHODIMP +nsRDFCoreFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult) +{ + if (aResult == NULL) + { + return NS_ERROR_NULL_POINTER; + } + + *aResult = NULL; + + /* do I have to use iSupports? */ + nsRDFCore *inst = new nsRDFCore(); + + if (inst == NULL) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult result = inst->QueryInterface(aIID, aResult); + + if (result != NS_OK) + delete inst; + + return result; + +} + +NS_IMETHODIMP +nsRDFCoreFactory::LockFactory(PRBool aLock) +{ + if (aLock) + IncLockCount(); + else + DecLockCount(); + + return NS_OK; +} + + diff --git a/xpfe/AppCores/src/nsRDFCoreFactory.h b/xpfe/AppCores/src/nsRDFCoreFactory.h new file mode 100644 index 00000000000..e69de29bb2d