gecko-dev/java/webclient/src_moz/RDFTreeNode.cpp
edburns%acm.org c2d7e96b90 The churn continues. After this checkin, BrowserControlFactoryTest
runs, but nothing else does.

As you all probably already know, all mozilla API calls have to happen
on the same thread.  For webclient, this will be the NativeEventThread.
This change-bundle does many many things, here are the main ones.

These changes are in concert with the checkin I just did to the diagram
at
<http://www.mozilla.org/projects/blackwood/webclient/design/20040306-webclient-2_0.zargo>.

M classes_spec/org/mozilla/webclient/impl/WrapperFactory.java
M classes_spec/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImpl.java

 * <p>This class is the hub of the startup and shutdown sequence for
 * Webclient.  It is a singleton and owns references to other app
 * singletons:</p>
 *
 * 	<ul>
 * 	  <li><p>{@link NativeEventThread}</p></li>
 *
 * 	  <li><p>{@link Bookmarks}</p></li>
 *
 * 	  <li><p>{@link Preferences}</p></li>
 *
 * 	  <li><p>{@link ProfileManager}</p></li>

 * 	  <li><p>the native object singleton corresponding to this java
 * 	  object (if necessary)</p></li>
 *
 *	</ul>
 *
 * <p>It maintains a set of {@link BrowserControlImpl} instances so that
 * we may return the native pointer for each one.</p>
 *
 * <p>This class is responsible for creating and initializing and
 * deleting {@link BrowserControlImpl} instances, as well as ensuring
 * that the native counterpart is proprely maintained in kind.</p>
 *
 * <p>This class has a tight contract with {@link
 * NativeEventThread}.</p>

- make BrowserControl creation and deletion part of this classes
  responsibilities.

- introduce NativeWrapperFactory concept.

- own the one and only NativeEventThread.

M classes_spec/org/mozilla/webclient/impl/wrapper_native/NativeEventThread.java

- make this a singleton.

- remove dependencies on BrowserControl and nativeBrowserControl

 * <p>This is a singleton class.  All native events pass thru this class
 * by virtue of the {@link #pushRunnable} or {@link pushNotifyRunnable}
 * methods.</p>

- remove listener logic.  This'll go into EventRegistration, where it
  belongs.

A src_moz/NativeWrapperFactory.cpp
A src_moz/NativeWrapperFactory.h

- takes the place of the old WebclientContext

- is now a class

M classes_spec/org/mozilla/webclient/impl/BrowserControlImpl.java

- this no longer destroys the nativeBrowserControl.  That is now done by
  WrapperFactoryImpl.

M classes_spec/org/mozilla/webclient/impl/WebclientFactoryImpl.java

- no longer maintain browserControlCount.

M classes_spec/org/mozilla/webclient/impl/wrapper_native/BookmarksImpl.java
M classes_spec/org/mozilla/webclient/impl/wrapper_native/NavigationImpl.java
M classes_spec/org/mozilla/webclient/impl/wrapper_native/PreferencesImpl.java
M classes_spec/org/mozilla/webclient/impl/wrapper_native/ProfileManagerImpl.java

- rename NativeContext to NativeWrapperFactory, to illustrate its
  singletonness.

M classes_spec/org/mozilla/webclient/impl/wrapper_native/EventRegistrationImpl.java

- comment out a bunch of stuff in anticipation of the new threading
  model, currently being fleshed out.

M classes_spec/org/mozilla/webclient/impl/wrapper_native/ImplObjectNative.java

- NativeEventThread is singleton

M src_moz/BookmarksImpl.cpp
M src_moz/PreferencesImpl.cpp
M src_moz/ProfileManagerImpl.cpp
M src_moz/RDFEnumeration.cpp
M src_moz/RDFTreeNode.cpp

- rename WebclientContext to NativeWrapperFactory.

M src_moz/EmbedWindow.cpp

-  mBaseWindow->Destroy();
+  if (mBaseWindow) {
+      mBaseWindow->Destroy();
+  }

M src_moz/Makefile.in

- Bring back NavigationImpl

- add NativeWrapperFactory.

M src_moz/NativeBrowserControl.cpp
M src_moz/NativeBrowserControl.h

- move event queue and java related stuff to NativeWrapperFactory.  This
  class is now essentially a copy of EmbedPrivate in GtkEmbed.

M src_moz/NativeEventThread.cpp

- remove methods, most of it has moved to
  WrapperFactoryImpl/NativeWrapperFactory.

M src_moz/NavigationImpl.cpp

- comment out all methods but LoadURI.

M src_moz/WrapperFactoryImpl.cpp

- take functionality over from NativeEventThread.

M src_moz/ns_util.cpp
M src_moz/ns_util.h

- the eventQueue is owned by NativeWrapperFactory now.

M src_moz/rdf_util.cpp
M src_share/jni_util.cpp

- make all exceptions RuntimeExceptions, so they can be thrown from a
  Runnable.

M test/automated/src/classes/org/mozilla/webclient/impl/wrapper_native/WrapperFactoryImplTest.java

- comment out the meat of this test until I figure out how to test it.

M test/automated/src/test/BrowserControlFactoryTest_correct

- new content.
2004-04-15 22:58:08 +00:00

586 lines
20 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (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/MPL/
*
* 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 RaptorCanvas.
*
* The Initial Developer of the Original Code is Kirk Baker and
* Ian Wilkinson. Portions created by Kirk Baker and Ian Wilkinson are
* Copyright (C) 1999 Kirk Baker and Ian Wilkinson. All
* Rights Reserved.
*
* Contributor(s): Ed Burns <edburns@acm.org>
*/
#include "org_mozilla_webclient_impl_wrapper_0005fnative_RDFTreeNode.h"
#include "rdf_util.h"
#include "rdf_progids.h"
#include "ns_util.h"
#include "wsRDFObserver.h"
#include <nsIServiceManager.h>
#include <nsString.h> // for nsCAutoString
#include <prlog.h> // for PR_ASSERT
#include <nsRDFCID.h> // for NS_RDFCONTAINER_CID
static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID);
static NS_DEFINE_CID(kSupportsArrayCID, NS_SUPPORTSARRAY_CID);
//
// Local function prototypes
//
//
// JNI methods
//
JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_RDFTreeNode_nativeIsLeaf
(JNIEnv *env, jobject obj, jint nativeContext, jint nativeRDFNode)
{
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeIsLeaf: entering\n"));
NativeWrapperFactory *wcContext = (NativeWrapperFactory *) nativeContext;
PR_ASSERT(wcContext);
jboolean result = JNI_FALSE;
PRInt32 count;
nsresult rv;
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) nativeRDFNode;
rv = rdf_getChildCount(parent, &count);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeGetChildCount: Can't get child count.");
return nsnull;
}
result = (count == 0) ? JNI_TRUE : JNI_FALSE;
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeIsLeaf: exiting\n"));
return result;
}
JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_RDFTreeNode_nativeIsContainer
(JNIEnv *env, jobject obj, jint nativeContext, jint nativeRDFNode)
{
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeIsContainer: entering\n"));
NativeWrapperFactory *wcContext = (NativeWrapperFactory *) nativeContext;
PR_ASSERT(wcContext);
nsCOMPtr<nsIRDFNode> node = (nsIRDFNode *) nativeRDFNode;
nsCOMPtr<nsIRDFResource> nodeResource;
nsresult rv;
jboolean result = JNI_FALSE;
PRBool prBool;
rv = node->QueryInterface(NS_GET_IID(nsIRDFResource),
getter_AddRefs(nodeResource));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeIsContainer: nativeRDFNode is not an RDFResource.");
return nsnull;
}
rv = gRDFCU->IsContainer(gBookmarksDataSource, nodeResource,
&prBool);
result = (prBool == PR_FALSE) ? JNI_FALSE : JNI_TRUE;
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeIsContainer: exiting\n"));
return result;
}
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_impl_wrapper_1native_RDFTreeNode_nativeGetChildAt
(JNIEnv *env, jobject obj, jint nativeContext, jint nativeRDFNode,
jint childIndex)
{
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeGetChildAt: entering\n"));
NativeWrapperFactory *wcContext = (NativeWrapperFactory *) nativeContext;
PR_ASSERT(wcContext);
jint result = -1;
nsresult rv;
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) nativeRDFNode;
nsCOMPtr<nsIRDFResource> child;
rv = rdf_getChildAt(childIndex, parent, getter_AddRefs(child));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeGetChildAt: Can't get child.");
return nsnull;
}
result = (jint)child.get();
((nsISupports *)result)->AddRef();
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeGetChildAt: exiting\n"));
return result;
}
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_impl_wrapper_1native_RDFTreeNode_nativeGetChildCount
(JNIEnv *env, jobject obj, jint nativeContext, jint nativeRDFNode)
{
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeGetChildCount: entering\n"));
NativeWrapperFactory *wcContext = (NativeWrapperFactory *) nativeContext;
PR_ASSERT(wcContext);
jint result = -1;
PRInt32 count;
nsresult rv;
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) nativeRDFNode;
rv = rdf_getChildCount(parent, &count);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeGetChildCount: Can't get child count.");
return result;
}
result = (jint) count;
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeGetChildCount: exiting\n"));
return result;
}
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_impl_wrapper_1native_RDFTreeNode_nativeGetIndex
(JNIEnv *env, jobject obj, jint nativeContext, jint nativeRDFNode,
jint childRDFNode)
{
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeGetIndex: entering\n"));
NativeWrapperFactory *wcContext = (NativeWrapperFactory *) nativeContext;
PR_ASSERT(wcContext);
jint result = -1;
PRInt32 index;
nsresult rv;
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) nativeRDFNode;
nsCOMPtr<nsIRDFResource> child = (nsIRDFResource *) childRDFNode;
rv = rdf_getIndexOfChild(parent, child, &index);
result = (jint) index;
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeGetIndex: exiting\n"));
return result;
}
JNIEXPORT jstring JNICALL
Java_org_mozilla_webclient_impl_wrapper_1native_RDFTreeNode_nativeToString
(JNIEnv *env, jobject obj, jint nativeContext, jint nativeRDFNode)
{
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeToString: entering\n"));
NativeWrapperFactory *wcContext = (NativeWrapperFactory *) nativeContext;
PR_ASSERT(wcContext);
nsCOMPtr<nsIRDFResource> currentResource =
(nsIRDFResource *) nativeRDFNode;
nsCOMPtr<nsIRDFNode> node;
nsCOMPtr<nsIRDFLiteral> literal;
PRBool isContainer = PR_FALSE;
jstring result = nsnull;
nsresult rv;
const PRUnichar *textForNode = nsnull;
rv = gRDFCU->IsContainer(gBookmarksDataSource, currentResource,
&isContainer);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeToString: Can't tell if RDFResource is container.");
return nsnull;
}
if (isContainer) {
// It's a bookmarks folder
rv = gBookmarksDataSource->GetTarget(currentResource,
kNC_Name, PR_TRUE,
getter_AddRefs(node));
// get the name of the folder
if (rv == 0) {
// if so, make sure it's an nsIRDFLiteral
rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral),
getter_AddRefs(literal));
if (NS_SUCCEEDED(rv)) {
rv = literal->GetValueConst(&textForNode);
}
else {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node is not an nsIRDFLiteral.\n"));
}
}
}
}
else {
// It's a bookmark or a Separator
rv = gBookmarksDataSource->GetTarget(currentResource,
kNC_URL, PR_TRUE,
getter_AddRefs(node));
// See if it has a Name
if (0 != rv) {
rv = gBookmarksDataSource->GetTarget(currentResource,
kNC_Name, PR_TRUE,
getter_AddRefs(node));
}
if (0 == rv) {
rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral),
getter_AddRefs(literal));
if (NS_SUCCEEDED(rv)) {
// get the value of the literal
rv = literal->GetValueConst(&textForNode);
if (NS_FAILED(rv)) {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node doesn't have a value.\n"));
}
}
}
else {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node is not an nsIRDFLiteral.\n"));
}
}
}
else {
if (prLogModuleInfo) {
PR_LOG(prLogModuleInfo, 3,
("nativeToString: node doesn't have a URL.\n"));
}
}
}
if (nsnull != textForNode) {
nsString * string = new nsString(textForNode);
int length = 0;
if (nsnull != string) {
length = string->Length();
}
result = ::util_NewString(env, (const jchar *) textForNode, length);
}
else {
result = ::util_NewStringUTF(env, "");
}
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeToString: exiting\n"));
return result;
}
JNIEXPORT void JNICALL
Java_org_mozilla_webclient_impl_wrapper_1native_RDFTreeNode_nativeInsertElementAt
(JNIEnv *env, jobject obj, jint nativeContext, jint parentRDFNode,
jint childRDFNode, jobject childProps, jint childIndex)
{
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeInsertElementAt: entering\n"));
NativeWrapperFactory *wcContext = (NativeWrapperFactory *) nativeContext;
PR_ASSERT(wcContext);
PR_ASSERT(childProps); // PENDING(edburns): do we need to NewGlobalRef this?
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) parentRDFNode;
nsCOMPtr<nsIRDFResource> newChild = (nsIRDFResource *) childRDFNode;
nsCOMPtr<nsIRDFContainer> container;
nsCOMPtr<nsIRDFLiteral> nameLiteral;
nsCOMPtr<nsIRDFLiteral> urlLiteral;
jstring name;
const jchar *nameJchar;
jstring url;
const jchar *urlJchar;
nsresult rv;
PRBool isContainer;
rv = gRDFCU->IsContainer(gBookmarksDataSource, parent,
&isContainer);
// PENDING(edburns): I don't think we can throw exceptions from
// here, no?
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: RDFResource is not a container.");
rv = NS_ERROR_UNEXPECTED;
goto omwiwnrtnniea_CLEANUP;
}
// get a container in order to create a child
container = do_CreateInstance(kRDFContainerCID);
if (!container) {
::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't create container.");
rv = NS_ERROR_UNEXPECTED;
goto omwiwnrtnniea_CLEANUP;
}
rv = container->Init(gBookmarksDataSource, parent);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't create container.");
rv = NS_ERROR_UNEXPECTED;
goto omwiwnrtnniea_CLEANUP;
}
// pull the info from the properties object and add it to the new
// node.
if (nsnull == (name = (jstring) ::util_GetFromPropertiesObject(env,
childProps,
BM_NAME_VALUE,
(jobject) &(wcContext->shareContext)))) {
rv = NS_ERROR_UNEXPECTED;
goto omwiwnrtnniea_CLEANUP;
}
if (nsnull == (nameJchar = ::util_GetStringChars(env, name))) {
rv = NS_ERROR_UNEXPECTED;
goto omwiwnrtnniea_CLEANUP;
}
if (nsnull == (url = (jstring) ::util_GetFromPropertiesObject(env, childProps,
BM_URL_VALUE,
(jobject) &(wcContext->shareContext)))) {
rv = NS_ERROR_UNEXPECTED;
goto omwiwnrtnniea_CLEANUP;
}
if (nsnull == (urlJchar = ::util_GetStringChars(env, url))) {
rv = NS_ERROR_UNEXPECTED;
goto omwiwnrtnniea_CLEANUP;
}
// if we get here, we have valid nameJchar and urlJchar strings.
// create literals for the name and url
rv = gRDF->GetLiteral((const PRUnichar *) nameJchar,
getter_AddRefs(nameLiteral));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't arguments nsISupportsArray.");
rv = NS_ERROR_UNEXPECTED;
goto omwiwnrtnniea_CLEANUP;
}
rv = gRDF->GetLiteral((const PRUnichar *) urlJchar,
getter_AddRefs(urlLiteral));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't create arguments nsISupportsArray.");
rv = NS_ERROR_UNEXPECTED;
goto omwiwnrtnniea_CLEANUP;
}
// now Assert them to add the to the newChild
rv = gBookmarksDataSource->Assert(newChild, kNC_Name, nameLiteral,
PR_TRUE);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't add name literal to new node.");
rv = NS_ERROR_UNEXPECTED;
goto omwiwnrtnniea_CLEANUP;
}
// + 1 because for some reason the 1 is the first, not 0.
rv = container->InsertElementAt(newChild, childIndex + 1, PR_TRUE);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't insert element into parent container.");
rv = NS_ERROR_UNEXPECTED;
goto omwiwnrtnniea_CLEANUP;
}
omwiwnrtnniea_CLEANUP:
::util_ReleaseStringChars(env, name, nameJchar);
::util_ReleaseStringChars(env, url, urlJchar);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: Can't InsertElementAt");
}
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeInsertElementAt: exiting\n"));
return;
}
JNIEXPORT jint JNICALL
Java_org_mozilla_webclient_impl_wrapper_1native_RDFTreeNode_nativeNewFolder
(JNIEnv *env, jobject obj, jint nativeContext, jint parentRDFNode,
jobject childProps)
{
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeNewFolder: entering\n"));
NativeWrapperFactory *wcContext = (NativeWrapperFactory *) nativeContext;
PR_ASSERT(wcContext);
jint result = -1;
nsCOMPtr<nsIRDFResource> parent = (nsIRDFResource *) parentRDFNode;
nsCOMPtr<nsIRDFResource> newChildFromObserver;
nsCOMPtr<nsISupportsArray> selectionArray;
nsCOMPtr<nsISupportsArray> argumentsArray;
nsCOMPtr<nsIRDFLiteral> nameLiteral;
nsCOMPtr<nsIRDFLiteral> urlLiteral;
nsresult rv = NS_ERROR_UNEXPECTED;
PRBool isContainer;
nsCOMPtr<nsIRDFObserver> observer = new wsRDFObserver();
wsRDFObserver *wsO = nsnull;
jstring name;
const jchar *nameJchar;
jstring url;
const jchar *urlJchar;
rv = gRDFCU->IsContainer(gBookmarksDataSource, parent, &isContainer);
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewFolder: RDFResource is not a container.");
rv = NS_ERROR_UNEXPECTED;
goto RNFEHE_CLEANUP;
}
// pull out the necessary keys from the properties table
if (nsnull == (name = (jstring) ::util_GetFromPropertiesObject(env,
childProps,
BM_NAME_VALUE,
(jobject) &(wcContext->shareContext)))) {
rv = NS_ERROR_UNEXPECTED;
goto RNFEHE_CLEANUP;
}
if (nsnull == (nameJchar = ::util_GetStringChars(env, name))) {
rv = NS_ERROR_UNEXPECTED;
goto RNFEHE_CLEANUP;
}
if (nsnull == (url = (jstring) ::util_GetFromPropertiesObject(env, childProps,
BM_URL_VALUE,
(jobject) &(wcContext->shareContext)))) {
rv = NS_ERROR_UNEXPECTED;
goto RNFEHE_CLEANUP;
}
if (nsnull == (urlJchar = ::util_GetStringChars(env, url))) {
rv = NS_ERROR_UNEXPECTED;
goto RNFEHE_CLEANUP;
}
// if we get here, we have valid nameJchar and urlJchar strings.
// use the magic "command interface" as in bookmarks.js
// http://lxr.mozilla.org/mozilla/source/xpfe/components/bookmarks/resources/bookmarks.js#1190
// set up selection nsISupportsArray
selectionArray = do_CreateInstance(kSupportsArrayCID);
if (!selectionArray) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewFolder: can't create selection nsISupportsArray.");
rv = NS_ERROR_UNEXPECTED;
goto RNFEHE_CLEANUP;
}
// set up arguments nsISupportsArray
argumentsArray = do_CreateInstance(kSupportsArrayCID);
if (argumentsArray) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewFolder: can't create arguments nsISupportsArray.");
rv = NS_ERROR_UNEXPECTED;
goto RNFEHE_CLEANUP;
}
// get various arguments (parent, name)
// kNC_parent
// kNC_Name
// kNC_URL
// add parent into selection array
selectionArray->AppendElement(parent);
// add multiple arguments into arguments array
argumentsArray->AppendElement(kNC_parent);
argumentsArray->AppendElement(parent);
rv = gRDF->GetLiteral((const PRUnichar *) nameJchar,
getter_AddRefs(nameLiteral));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewFolder: can't arguments nsISupportsArray.");
rv = NS_ERROR_UNEXPECTED;
goto RNFEHE_CLEANUP;
}
argumentsArray->AppendElement(kNC_Name);
argumentsArray->AppendElement(nameLiteral);
rv = gRDF->GetLiteral((const PRUnichar *) urlJchar,
getter_AddRefs(urlLiteral));
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeNewFolder: can't create arguments nsISupportsArray.");
rv = NS_ERROR_UNEXPECTED;
goto RNFEHE_CLEANUP;
}
argumentsArray->AppendElement(kNC_URL);
argumentsArray->AppendElement(urlLiteral);
// at this point, selectionArray contains the parent
// and argumentsArray contains arcs and literals for the name and the
// url of the node to be inserted.
if (observer) {
gBookmarksDataSource->AddObserver(observer);
}
// find out if it's a folder
if (nsnull != ::util_GetFromPropertiesObject(env, childProps,
BM_IS_FOLDER_VALUE, (jobject)
(jobject) &(wcContext->shareContext))){
// do the command
rv = gBookmarksDataSource->DoCommand(selectionArray,
kNewFolderCommand,
argumentsArray);
}
if (NS_FAILED(rv)) {
::util_ThrowExceptionToJava(env, "Exception: nativeInsertElementAt: can't execute bookmarks command to add folder.");
rv = NS_ERROR_UNEXPECTED;
goto RNFEHE_CLEANUP;
}
if (observer) {
gBookmarksDataSource->RemoveObserver(observer);
wsO = (wsRDFObserver *) observer.get();
newChildFromObserver = wsO->getFolder();
if (newChildFromObserver) {
result = (jint) newChildFromObserver.get();
((nsISupports *)result)->AddRef();
}
}
RNFEHE_CLEANUP:
::util_ReleaseStringChars(env, name, nameJchar);
::util_ReleaseStringChars(env, url, urlJchar);
PR_LOG(prLogModuleInfo, PR_LOG_DEBUG,
("RDFTreeNode_nativeNewFolder: exiting\n"));
return result;
}
//
// Local functions
//