nativeContainerFieldID = env->GetFieldID(objClass, "nativeContainer", "I"); if (nsnull == nativeContainerFieldID) { printf("getNativeEnumFromJava: Can't get fieldID for nativeContainer.\n"); return -1; } env->SetIntField(obj, nativeContainerFieldID, (jint) container.get());
::util_SetIntValueForInstance(env, obj, "nativeContainer", (jint) container.get());
jint getNativeEnumFromJava(JNIEnv *env, jobject obj, jint nativeRDFNode){    nsresult rv;    jint result = -1;    jclass objClass;    jfieldID nativeEnumFieldID;    jfieldID nativeContainerFieldID;    objClass = env->GetObjectClass(obj);    if (nsnull == objClass) {        printf("getNativeEnumFromJava: Can't get object class for RDFEnumeration.\n");        return -1;    }    nativeEnumFieldID = env->GetFieldID(objClass, "nativeEnum", "I");    if (nsnull == nativeEnumFieldID) {        printf("getNativeEnumFromJava: Can't get fieldID for nativeEnum.\n");        return -1;    }    result = env->GetIntField(obj, nativeEnumFieldID);    // if the field has been initialized, just return the value    if (-1 != result) {        // NORMAL EXIT 1        return result;    }    // else, we need to create the enum    nsCOMPtr<nsIRDFNode> node = (nsIRDFNode *) nativeRDFNode;    nsCOMPtr<nsIRDFResource> nodeResource;    nsCOMPtr<nsIRDFContainer> container;    nsCOMPtr<nsISimpleEnumerator> enumerator;    rv = node->QueryInterface(NS_GET_IID(nsIRDFResource),                               getter_AddRefs(nodeResource));    if (NS_FAILED(rv)) {        printf("getNativeEnumFromJava: Argument nativeRDFNode isn't an nsIRDFResource.\n");        return -1;    }        // get a container in order to get the enum    rv = nsComponentManager::CreateInstance(NS_IRDFCONTAINER_PROGID,                                            nsnull,                                            NS_GET_IID(nsIRDFContainer),                                            getter_AddRefs(container));    if (NS_FAILED(rv)) {        printf("recursiveResourceTraversal: can't get a new container\n");        return -1;    }        rv = container->Init(gBookmarksDataSource, nodeResource);    if (NS_FAILED(rv)) {        printf("getNativeEnumFromJava: Can't Init container.\n");        return -1;    }    rv = container->GetElements(getter_AddRefs(enumerator));    if (NS_FAILED(rv)) {        printf("getNativeEnumFromJava: Can't get enumeration from container.\n");        return -1;    }    // IMPORTANT: Store the enum back into java    env->SetIntField(obj, nativeEnumFieldID, (jint) enumerator.get());    // IMPORTANT: make sure it doesn't get deleted when it goes out of scope    ((nsISupports *)enumerator.get())->AddRef();     // PENDING(edburns): I'm not sure if we need to keep the    // nsIRDFContainer from being destructed in order to maintain the    // validity of the nsISimpleEnumerator that came from the container.    // Just to be safe, I'm doing so.    nativeContainerFieldID = env->GetFieldID(objClass, "nativeContainer", "I");    if (nsnull == nativeContainerFieldID) {        printf("getNativeEnumFromJava: Can't get fieldID for nativeContainer.\n");        return -1;    }    env->SetIntField(obj, nativeContainerFieldID, (jint) container.get());    ((nsISupports *)container.get())->AddRef();        // NORMAL EXIT 2    result = (jint)enumerator.get();        return result;}