forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Registry class for storing information about java-c++
objects binding
- Loading branch information
idk%eng.sun.com
committed
Sep 25, 1999
1 parent
0e1d8c6
commit dd3ecbe
Showing
7 changed files
with
173 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* -*- Mode: Java; 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.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/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 Initial Developer of the Original Code is Sun Microsystems, | ||
* Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, | ||
* Inc. All Rights Reserved. | ||
*/ | ||
package org.mozilla.pluglet; | ||
|
||
import java.util.*; | ||
|
||
public class Registry { | ||
static Hashtable table = null; | ||
public static void setPeer(Object key,long peer) { | ||
if (table == null) { | ||
table = new Hashtable(10); | ||
} | ||
table.put(key, new Long(peer)); | ||
} | ||
public static long getPeer(Object key) { | ||
if (table == null) { | ||
return 0; | ||
} | ||
Object obj = table.get(key); | ||
if (obj == null) { | ||
return 0; | ||
} else { | ||
return ((Long)obj).longValue(); | ||
} | ||
} | ||
public static void remove(Object key) { | ||
if (table != null) { | ||
table.remove(key); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* -*- 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.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/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 Initial Developer of the Original Code is Sun Microsystems, | ||
* Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, | ||
* Inc. All Rights Reserved. | ||
*/ | ||
|
||
#include "PlugletEngine.h" | ||
#include "Registry.h" | ||
|
||
jclass Registry::clazz = NULL; | ||
jmethodID Registry::setPeerMID = NULL; | ||
jmethodID Registry::removeMID = NULL; | ||
|
||
void Registry::SetPeer(jobject key, jlong peer) { | ||
if (!clazz) { | ||
Initialize(); | ||
if(!clazz) { | ||
return; | ||
} | ||
} | ||
JNIEnv *env = PlugletEngine::GetJNIEnv(); | ||
env->CallStaticVoidMethod(clazz,setPeerMID,key,peer); | ||
if (env->ExceptionOccurred()) { | ||
env->ExceptionDescribe(); | ||
return; | ||
} | ||
} | ||
|
||
void Registry::Remove(jobject key) { | ||
if (!clazz) { // it is impossible | ||
Initialize(); | ||
if(!clazz) { | ||
return; | ||
} | ||
} | ||
JNIEnv *env = PlugletEngine::GetJNIEnv(); | ||
env->CallStaticVoidMethod(clazz,removeMID,key); | ||
if (env->ExceptionOccurred()) { | ||
env->ExceptionDescribe(); | ||
return; | ||
} | ||
} | ||
|
||
void Registry::Initialize() { | ||
JNIEnv *env = PlugletEngine::GetJNIEnv(); | ||
if(!env) { | ||
return; | ||
} | ||
clazz = env->FindClass("org/mozilla/pluglet/Registry"); | ||
if(!clazz) { | ||
env->ExceptionDescribe(); | ||
return; | ||
} | ||
setPeerMID = env->GetStaticMethodID(clazz,"setPeer","(Ljava/lang/Object;J)V"); | ||
if (!setPeerMID) { | ||
env->ExceptionDescribe(); | ||
clazz = NULL; | ||
return; | ||
} | ||
removeMID = env->GetStaticMethodID(clazz,"remove","(Ljava/lang/Object;)V"); | ||
if (!removeMID) { | ||
env->ExceptionDescribe(); | ||
clazz = NULL; | ||
return; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* -*- 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.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/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 Initial Developer of the Original Code is Sun Microsystems, | ||
* Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, | ||
* Inc. All Rights Reserved. | ||
*/ | ||
#ifndef __Registry_h__ | ||
#define __Registry_h__ | ||
#include "jni.h" | ||
class Registry { | ||
public: | ||
static void SetPeer(jobject key, jlong peer); | ||
static void Remove(jobject key); | ||
private: | ||
static void Initialize(); | ||
static jclass clazz; | ||
static jmethodID setPeerMID; | ||
static jmethodID removeMID; | ||
}; | ||
#endif /* __Registry_h__ */ | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters