Checked in new BlackConnect version

git-svn-id: svn://10.0.0.236/trunk@71032 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
idk%eng.sun.com
2000-05-29 01:26:46 +00:00
parent 452443a5fa
commit e3a3cf5021
72 changed files with 5389 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/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.org 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.
#
# Contributor(s):
# Igor Kushnirskiy <idk@eng.sun.com>
#
DEPTH=../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = bcjavastubs
MODULE = bcjavastubs
IS_COMPONENT = 1
EXPORTS = \
bcJavaStubsAndProxies.h
CPPSRCS = \
bcJavaMarshalToolkit.cpp \
bcJavaStub.cpp \
bcJavaGlobal.cpp \
bcJavaStubsAndProxies.cpp \
bcIIDJava.cpp \
org_mozilla_xpcom_Utilities.cpp \
$(NULL)
CXXFLAGS += $(MOZ_TOOLKIT_REGISTRY_CFLAGS) -D_REENTRANT -DOJI_DISABLE -I$(CONNECT_SRC)/public
DSO_LDOPTS += \
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/ \
-L$(JDKHOME)/jre/lib/$(HOSTTYPE)/classic \
-ljava -ljvm \
$(NULL)
ifneq ($(OS_ARCH), Linux)
DSO_LDOPTS += \
-lthread -lXm -lX11 -lXt -lm
endif
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,99 @@
/* -*- 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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "bcIIDJava.h"
#include "bcJavaGlobal.h"
jclass bcIIDJava::iidClass = NULL;
jmethodID bcIIDJava::iidInitMID = NULL;
jmethodID bcIIDJava::getStringMID = NULL;
void bcIIDJava::Init(void) {
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
if (env) {
if (!(iidClass = env->FindClass("org/mozilla/xpcom/IID"))
|| !(iidClass = (jclass) env->NewGlobalRef(iidClass))) {
env->ExceptionDescribe();
Destroy();
return;
}
if (!(iidInitMID = env->GetMethodID(iidClass,"<init>","(Ljava/lang/String;)V"))) {
env->ExceptionDescribe();
Destroy();
return;
}
if (!(getStringMID = env->GetMethodID(iidClass,"getString","()Ljava/lang/String;"))) {
env->ExceptionDescribe();
Destroy();
return;
}
}
}
void bcIIDJava::Destroy() {
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
if (env) {
if (iidClass) {
env->DeleteGlobalRef(iidClass);
iidClass = NULL;
}
}
}
jobject bcIIDJava::GetObject(nsIID *iid) {
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
if (!iid
|| !env ) {
return NULL;
}
if (!iidClass) {
Init();
}
char *str = iid->ToString(); //nb free ?
jstring jstr = NULL;
if (str) {
char *siid = str+1; //we do need to have {_fdsf_}
siid[strlen(siid)-1] = 0;
jstr = env->NewStringUTF((const char *)siid);
}
return env->NewObject(iidClass,iidInitMID,jstr);
}
jclass bcIIDJava::GetClass() {
return iidClass;
}
nsIID bcIIDJava::GetIID(jobject obj) {
nsIID iid;
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
if (env) {
if (!iidClass) {
Init();
}
jstring jstr = (jstring)env->CallObjectMethod(obj, getStringMID);
const char * str = NULL;
str = env->GetStringUTFChars(jstr,NULL);
iid.Parse(str);
env->ReleaseStringUTFChars(jstr,str);
}
return iid;
}

View File

@@ -0,0 +1,41 @@
/* -*- 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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcIIDJava_H
#define __bcIIDJava_H
#include "nsIID.h"
#include "jni.h"
class bcIIDJava {
public:
static jobject GetObject(nsIID * iid);
static nsIID GetIID(jobject obj);
static jclass GetClass();
private:
static jclass iidClass;
static jmethodID iidInitMID;
static jmethodID getStringMID;
static void Init(void);
static void Destroy(void);
};
#endif

View File

@@ -0,0 +1,68 @@
/* -*- 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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "bcJavaGlobal.h"
#include "prenv.h"
JavaVM *bcJavaGlobal::jvm = NULL;
#define PATH_SEPARATOR ':'
JNIEnv * bcJavaGlobal::GetJNIEnv(void) {
JNIEnv * res;
if (!jvm) {
StartJVM();
}
if (jvm) {
jvm->AttachCurrentThread(&res,NULL);
}
printf("--bcJavaGlobal::GetJNIEnv \n");
return res;
}
void bcJavaGlobal::StartJVM() {
JNIEnv *env = NULL;
jint res;
jsize jvmCount;
JNI_GetCreatedJavaVMs(&jvm, 1, &jvmCount);
if (jvmCount) {
return;
}
JDK1_1InitArgs vm_args;
char classpath[1024];
JNI_GetDefaultJavaVMInitArgs(&vm_args);
vm_args.version = 0x00010001;
/* Append USER_CLASSPATH to the default system class path */
sprintf(classpath, "%s%c%s",
vm_args.classpath, PATH_SEPARATOR, PR_GetEnv("CLASSPATH"));
char **props = new char*[2];
props[0]="java.compiler=NONE";
props[1]=0;
vm_args.properties = props;
vm_args.classpath = classpath;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, &env, &vm_args);
printf("--bcJavaGlobal::StartJVM jvm started\n");
}

View File

@@ -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.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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcJavaGlobal_h_
#define __bcJavaGlobal_h_
#include "jni.h"
class bcJavaGlobal {
public:
static JNIEnv * GetJNIEnv(void);
private:
static JavaVM *jvm;
static void StartJVM(void);
};
#endif

View File

@@ -0,0 +1,534 @@
/* -*- 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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nsIAllocator.h"
#include "nsCOMPtr.h"
#include "bcJavaMarshalToolkit.h"
#include "bcIIDJava.h"
#include "bcJavaStubsAndProxies.h"
#include "nsIServiceManager.h"
jclass bcJavaMarshalToolkit::objectClass = NULL;
jclass bcJavaMarshalToolkit::booleanClass = NULL;
jmethodID bcJavaMarshalToolkit::booleanInitMID = NULL;
jmethodID bcJavaMarshalToolkit::booleanValueMID = NULL;
jclass bcJavaMarshalToolkit::characterClass = NULL;
jmethodID bcJavaMarshalToolkit::characterInitMID = NULL;
jmethodID bcJavaMarshalToolkit::characterValueMID = NULL;
jclass bcJavaMarshalToolkit::byteClass = NULL;
jmethodID bcJavaMarshalToolkit::byteInitMID = NULL;
jmethodID bcJavaMarshalToolkit::byteValueMID = NULL;
jclass bcJavaMarshalToolkit::shortClass = NULL;
jmethodID bcJavaMarshalToolkit::shortInitMID = NULL;
jmethodID bcJavaMarshalToolkit::shortValueMID = NULL;
jclass bcJavaMarshalToolkit::integerClass = NULL;
jmethodID bcJavaMarshalToolkit::integerInitMID = NULL;
jmethodID bcJavaMarshalToolkit::integerValueMID = NULL;
jclass bcJavaMarshalToolkit::longClass = NULL;
jmethodID bcJavaMarshalToolkit::longInitMID = NULL;
jmethodID bcJavaMarshalToolkit::longValueMID = NULL;
jclass bcJavaMarshalToolkit::floatClass = NULL;
jmethodID bcJavaMarshalToolkit::floatInitMID = NULL;
jmethodID bcJavaMarshalToolkit::floatValueMID = NULL;
jclass bcJavaMarshalToolkit::doubleClass = NULL;
jmethodID bcJavaMarshalToolkit::doubleInitMID = NULL;
jmethodID bcJavaMarshalToolkit::doubleValueMID = NULL;
jclass bcJavaMarshalToolkit::stringClass = NULL;
static NS_DEFINE_CID(kJavaStubsAndProxies,BC_JAVASTUBSANDPROXIES_CID);
bcJavaMarshalToolkit::bcJavaMarshalToolkit(PRUint16 _methodIndex,
nsIInterfaceInfo *_interfaceInfo, jobjectArray _args, JNIEnv *_env, int isOnServer, bcIORB *_orb) {
env = _env;
callSide = (isOnServer) ? onServer : onClient;
methodIndex = _methodIndex;
interfaceInfo = _interfaceInfo;
interfaceInfo->GetMethodInfo(methodIndex,(const nsXPTMethodInfo **)&info); // These do *not* make copies ***explicit bending of XPCOM rules***
args = _args;
if(!objectClass) {
InitializeStatic();
if(!objectClass) {
//nb ? we do not have java classes. What could we do?
}
}
orb = _orb;
}
bcJavaMarshalToolkit::~bcJavaMarshalToolkit() {
}
nsresult bcJavaMarshalToolkit::Marshal(bcIMarshaler *m) {
//nb todo
return NS_OK;
}
class javaAllocator : public bcIAllocator {
public:
javaAllocator(nsIAllocator *_allocator) {
allocator = _allocator;
}
virtual ~javaAllocator() {}
virtual void * Alloc(size_t size) {
return allocator->Alloc(size);
}
virtual void Free(void *ptr) {
allocator->Free(ptr);
}
virtual void * Realloc(void* ptr, size_t size) {
return allocator->Realloc(ptr,size);
}
private:
nsCOMPtr<nsIAllocator> allocator;
};
nsresult bcJavaMarshalToolkit::UnMarshal(bcIUnMarshaler *um) {
printf("--nsresult bcJavaMarshalToolkit::UnMarshal\n");
bcIAllocator * allocator = new javaAllocator(nsAllocator::GetGlobalAllocator());
PRUint32 paramCount = info->GetParamCount();
jobject value;
void * data = allocator->Alloc(sizeof(nsXPTCMiniVariant)); // sizeof(nsXPTCMiniVariant) is ok
for (int i = 0; i < paramCount; i++) {
nsXPTParamInfo param = info->GetParam(i);
PRBool isOut = param.IsOut();
nsXPTType type = param.GetType();
if ( (callSide == onServer && !param.IsIn()
|| (callSide == onClient && !param.IsOut()))){
if (callSide == onServer
&& isOut) { //we need to allocate memory for out parametr
value = Native2Java(NULL,XPTType2bcXPType(type.TagPart()),1);
env->SetObjectArrayElement(args,i,value);
}
continue;
}
switch(type.TagPart()) {
case nsXPTType::T_IID :
case nsXPTType::T_I8 :
case nsXPTType::T_U8 :
case nsXPTType::T_I16 :
case nsXPTType::T_U16 :
case nsXPTType::T_I32 :
case nsXPTType::T_U32 :
case nsXPTType::T_I64 :
case nsXPTType::T_U64 :
case nsXPTType::T_FLOAT :
case nsXPTType::T_DOUBLE :
case nsXPTType::T_BOOL :
case nsXPTType::T_CHAR :
case nsXPTType::T_WCHAR :
um->ReadSimple(data,XPTType2bcXPType(type.TagPart()));
value = Native2Java(data,XPTType2bcXPType(type.TagPart()),isOut);
break;
case nsXPTType::T_PSTRING_SIZE_IS:
case nsXPTType::T_PWSTRING_SIZE_IS:
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_WCHAR_STR :
size_t size;
um->ReadString(data,&size,allocator);
//nb to do
break;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
{
printf("--[c++] we have an interface\n");
bcOID oid;
um->ReadSimple(&oid,XPTType2bcXPType(type.TagPart()));
printf("%d oid", oid);
nsIID iid;
um->ReadSimple(&iid,bc_T_IID);
void * p[2];
p[0]=&oid; p[1]= &iid;
data = p;
value = Native2Java(data,bc_T_INTERFACE,isOut);
break;
}
case nsXPTType::T_ARRAY:
{
nsXPTType datumType;
if(NS_FAILED(interfaceInfo->GetTypeForParam(methodIndex, &param, 1,&datumType))) {
return NS_ERROR_FAILURE;
}
//nb to do array
break;
}
default:
return NS_ERROR_FAILURE;
}
env->SetObjectArrayElement(args,i,value);
}
return NS_OK;
}
bcXPType bcJavaMarshalToolkit::XPTType2bcXPType(uint8 type) {
switch(type) {
case nsXPTType::T_I8 :
return bc_T_I8;
case nsXPTType::T_U8 :
return bc_T_U8;
case nsXPTType::T_I16 :
return bc_T_I16;
case nsXPTType::T_U16 :
return bc_T_U16;
case nsXPTType::T_I32 :
return bc_T_I32;
case nsXPTType::T_U32 :
return bc_T_U32;
case nsXPTType::T_I64 :
return bc_T_I64;
case nsXPTType::T_U64 :
return bc_T_U64;
case nsXPTType::T_FLOAT :
return bc_T_FLOAT;
case nsXPTType::T_DOUBLE :
return bc_T_DOUBLE;
case nsXPTType::T_BOOL :
return bc_T_BOOL;
case nsXPTType::T_CHAR :
return bc_T_CHAR;
case nsXPTType::T_WCHAR :
return bc_T_WCHAR;
case nsXPTType::T_IID :
return bc_T_IID;
case nsXPTType::T_CHAR_STR :
case nsXPTType::T_PSTRING_SIZE_IS:
return bc_T_CHAR_STR;
case nsXPTType::T_WCHAR_STR :
case nsXPTType::T_PWSTRING_SIZE_IS:
return bc_T_WCHAR_STR;
case nsXPTType::T_INTERFACE :
case nsXPTType::T_INTERFACE_IS :
return bc_T_INTERFACE;
case nsXPTType::T_ARRAY:
return bc_T_ARRAY;
}
}
//if p == 0 and isOut than return one element array
jobject bcJavaMarshalToolkit::Native2Java(void *p, bcXPType type, int isOut) {
//nb we shoud care about endianes. should we?
printf("--[c++]bcJavaMarshalToolkit::Native2Java \n");
jobject res = NULL;
if (!p
&& !isOut) {
printf("--[c++]bcJavaMarshalToolkit::Native2Java !p && !isOut\n");
return res;
}
switch (type) {
case bc_T_I8:
case bc_T_U8:
if (isOut) {
res = env->NewByteArray(1);
if (p) {
env->SetByteArrayRegion((jbyteArray)res,0,1,(jbyte*)p);
}
} else {
res = env->NewObject(byteClass,byteInitMID,*(jbyte*)p);
}
break;
case bc_T_I16:
case bc_T_U16:
if (isOut) {
res = env->NewShortArray(1);
if (p) {
env->SetShortArrayRegion((jshortArray)res,0,1,(jshort*)p);
}
} else {
res = env->NewObject(shortClass,shortInitMID,*(jshort*)p);
}
break;
case bc_T_I32:
case bc_T_U32:
if (isOut) {
res = env->NewIntArray(1);
if (p) {
env->SetIntArrayRegion((jintArray)res,0,1,(jint*)p);
}
} else {
res = env->NewObject(integerClass,integerInitMID,*(jint*)p);
printf("--bcJavaMarshalToolkit::Native2Java we'v got i32\n");
}
break;
case bc_T_I64:
case bc_T_U64:
if (isOut) {
res = env->NewLongArray(1);
if (p) {
env->SetLongArrayRegion((jlongArray)res,0,1,(jlong*)p);
}
} else {
res = env->NewObject(longClass,longInitMID,*(jlong*)p);
}
break;
case bc_T_FLOAT:
if (isOut) {
res = env->NewFloatArray(1);
if (p) {
env->SetFloatArrayRegion((jfloatArray)res,0,1,(jfloat*)p);
}
} else {
res = env->NewObject(floatClass,floatInitMID,*(jfloat*)p);
}
break;
case bc_T_DOUBLE:
if (isOut) {
res = env->NewDoubleArray(1);
if (p) {
env->SetDoubleArrayRegion((jdoubleArray)res,0,1,(jdouble*)p);
}
} else {
res = env->NewObject(doubleClass,doubleInitMID,*(jdouble*)p);
}
break;
case bc_T_BOOL:
if (isOut) {
res = env->NewBooleanArray(1);
if (p) {
env->SetBooleanArrayRegion((jbooleanArray)res,0,1,(jboolean*)p);
}
} else {
res = env->NewObject(booleanClass,booleanInitMID,*(jboolean*)p);
}
break;
case bc_T_CHAR:
case bc_T_WCHAR:
if (isOut) {
res = env->NewCharArray(1);
if (p) {
env->SetCharArrayRegion((jcharArray)res,0,1,(jchar*)p);
}
} else {
res = env->NewObject(characterClass,characterInitMID,*(jchar*)p);
}
break;
case bc_T_CHAR_STR:
case bc_T_WCHAR_STR: //nb not sure about this
{
jstring str = NULL;
if (p) {
str = env->NewStringUTF((const char*)p);
}
if (isOut) {
res = env->NewObjectArray(1,stringClass,NULL);
if (str) {
env->SetObjectArrayElement((jobjectArray)res,0,str);
}
} else {
res = str;
}
break;
}
case bc_T_IID:
{
jobject iid = NULL;
if (p) {
iid = bcIIDJava::GetObject((nsIID*)p);
}
if (isOut) {
res = env->NewObjectArray(1,bcIIDJava::GetClass(),NULL);
env->SetObjectArrayElement((jobjectArray)res,0,iid);
} else {
res = iid;
}
break;
}
case bc_T_INTERFACE:
{
printf("--[c++]bcJavaMarshalToolkit::... we have an Interfaces \n");
jobject obj = NULL;
nsresult r;
nsIID *iid;
bcOID *oid;
jobject proxy;
if (p) {
oid = (bcOID*)((void**)p)[0];
iid = (bcIID*)((void**)p)[1];
NS_WITH_SERVICE(bcJavaStubsAndProxies, javaStubsAndProxies, kJavaStubsAndProxies, &r);
if (NS_FAILED(r)) {
return NULL;
}
javaStubsAndProxies->GetProxy(*oid, *iid, orb, &proxy);
}
if (isOut) { //nb to do
/*
res = env->NewObjectArray(1,bcIIDJava::GetClass(),NULL);
env->SetObjectArrayElement((jobjectArray)res,0,proxy);
*/
} else {
res = proxy;
}
break;
}
default:
;
}
return res;
}
void bcJavaMarshalToolkit::InitializeStatic() {
jclass clazz;
if (!(clazz = env->FindClass("java/lang/Object"))
|| !(objectClass = (jclass) env->NewGlobalRef(clazz))) {
return;
}
if (!(clazz = env->FindClass("java/lang/Boolean"))
|| !(booleanClass = (jclass) env->NewGlobalRef(clazz))) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Character"))
|| !(characterClass = (jclass) env->NewGlobalRef(clazz))) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Byte"))
|| !(byteClass = (jclass) env->NewGlobalRef(clazz))) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Short"))
|| !(shortClass = (jclass) env->NewGlobalRef(clazz))) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Integer"))
|| !(integerClass = (jclass) env->NewGlobalRef(clazz))) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Long"))
|| !(longClass = (jclass) env->NewGlobalRef(clazz))) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Float"))
|| !(floatClass = (jclass) env->NewGlobalRef(clazz))) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/Double"))
|| !(doubleClass = (jclass) env->NewGlobalRef(clazz))) {
DeInitializeStatic();
return;
}
if (!(clazz = env->FindClass("java/lang/String"))
|| !(stringClass = (jclass) env->NewGlobalRef(clazz))) {
DeInitializeStatic();
return;
}
if (!(booleanInitMID = env->GetMethodID(booleanClass,"<init>","(Z)V"))) {
DeInitializeStatic();
return;
}
if (!(booleanValueMID = env->GetMethodID(booleanClass,"booleanValue","()Z"))) {
DeInitializeStatic();
return;
}
if (!(characterInitMID = env->GetMethodID(characterClass,"<init>","(C)V"))) {
DeInitializeStatic();
return;
}
if (!(characterValueMID = env->GetMethodID(characterClass,"charValue","()C"))) {
DeInitializeStatic();
return;
}
if (!(byteInitMID = env->GetMethodID(byteClass,"<init>","(B)V"))) {
DeInitializeStatic();
return;
}
if (!(byteValueMID = env->GetMethodID(byteClass,"byteValue","()B"))) {
DeInitializeStatic();
return;
}
if (!(shortInitMID = env->GetMethodID(shortClass,"<init>","(S)V"))) {
DeInitializeStatic();
return;
}
if (!(shortValueMID = env->GetMethodID(shortClass,"shortValue","()S"))) {
DeInitializeStatic();
return;
}
if (!(integerInitMID = env->GetMethodID(integerClass,"<init>","(I)V"))) {
DeInitializeStatic();
return;
}
if (!(integerValueMID = env->GetMethodID(integerClass,"intValue","()I"))) {
DeInitializeStatic();
return;
}
if (!(longInitMID = env->GetMethodID(longClass,"<init>","(J)V"))) {
DeInitializeStatic();
return;
}
if (!(longValueMID = env->GetMethodID(longClass,"longValue","()J"))) {
DeInitializeStatic();
return;
}
if (!(floatInitMID = env->GetMethodID(floatClass,"<init>","(F)V"))) {
DeInitializeStatic();
return;
}
if (!(floatValueMID = env->GetMethodID(floatClass,"floatValue","()F"))) {
DeInitializeStatic();
return;
}
if (!(doubleInitMID = env->GetMethodID(doubleClass,"<init>","(D)V"))) {
DeInitializeStatic();
return;
}
if (!(doubleValueMID = env->GetMethodID(doubleClass,"doubleValue","()D"))) {
DeInitializeStatic();
return;
}
}
void bcJavaMarshalToolkit::DeInitializeStatic() { //nb need to do
}

View File

@@ -0,0 +1,85 @@
/* -*- 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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef _bcJavaMarshalToolkit_h
#define _bcJavaMarshalToolkit_h
#include "jni.h"
#include "nsISupports.h"
#include "xptcall.h"
#include "bcIMarshaler.h"
#include "bcIUnMarshaler.h"
#include "bcIORB.h"
class bcJavaMarshalToolkit {
public:
bcJavaMarshalToolkit(PRUint16 methodIndex,
nsIInterfaceInfo *interfaceInfo, jobjectArray args,
JNIEnv *env, int isOnServer, bcIORB *orb) ;
virtual ~bcJavaMarshalToolkit();
nsresult Marshal(bcIMarshaler *);
nsresult UnMarshal(bcIUnMarshaler *);
private:
enum { unDefined, onServer, onClient } callSide;
JNIEnv *env;
PRUint16 methodIndex;
nsXPTMethodInfo *info;
nsIInterfaceInfo * interfaceInfo;
bcIORB *orb;
jobjectArray args;
static jclass objectClass;
static jclass booleanClass;
static jmethodID booleanInitMID;
static jmethodID booleanValueMID;
static jclass characterClass;
static jmethodID characterInitMID;
static jmethodID characterValueMID;
static jclass byteClass;
static jmethodID byteInitMID;
static jmethodID byteValueMID;
static jclass shortClass;
static jmethodID shortInitMID;
static jmethodID shortValueMID;
static jclass integerClass;
static jmethodID integerInitMID;
static jmethodID integerValueMID;
static jclass longClass;
static jmethodID longInitMID;
static jmethodID longValueMID;
static jclass floatClass;
static jmethodID floatInitMID;
static jmethodID floatValueMID;
static jclass doubleClass;
static jmethodID doubleInitMID;
static jmethodID doubleValueMID;
static jclass stringClass;
void InitializeStatic();
void DeInitializeStatic();
bcXPType XPTType2bcXPType(uint8 type);
jobject Native2Java(void *,bcXPType type,int isOut = 0);
};
#endif

View File

@@ -0,0 +1,40 @@
/* -*- 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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcJavaProxy_h
#define __bcJavaProxy_h
#include "jni.h"
#include "bcDefs.h"
#include "bcIORB.h"
class bcJavaProxy {
public:
bcJavaProxy(bcOID oid, bcIID * iid, bcIORB *orb);
virtual ~bcJavaProxy();
jobject GetObject();
private:
bcIORB *orb;
bcOID oid;
bcIID iid;
};
#endif

View File

@@ -0,0 +1,113 @@
/* -*- 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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "bcJavaStub.h"
#include "nsIInterfaceInfo.h"
#include "nsIInterfaceInfoManager.h"
#include "xptcall.h"
#include "bcJavaMarshalToolkit.h"
#include "bcJavaGlobal.h"
#include "bcIIDJava.h"
#include "unistd.h"
#include "signal.h"
jclass bcJavaStub::objectClass = NULL;
jclass bcJavaStub::utilitiesClass = NULL;
jmethodID bcJavaStub::callMethodByIndexMID = NULL;
bcJavaStub::bcJavaStub(jobject obj) {
printf("--bcJavaStub::bcJavaStub \n");
if (!obj) {
printf("--bcJavaStub::bcJavaStub obj== 0\n");
return;
}
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
object = env->NewGlobalRef(obj);
}
bcJavaStub::~bcJavaStub() {
bcJavaGlobal::GetJNIEnv()->DeleteGlobalRef(object);
}
void bcJavaStub::Dispatch(bcICall *call) {
//sigsend(P_PID, getpid(),SIGINT);
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
bcIID iid; bcOID oid; bcMID mid;
jobjectArray args;
call->GetParams(&iid, &oid, &mid);
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if(iimgr = XPTI_GetInterfaceInfoManager()) {
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
return; //nb exception handling
}
NS_RELEASE(iimgr);
} else {
return;
}
nsXPTMethodInfo* info;
interfaceInfo->GetMethodInfo(mid,(const nsXPTMethodInfo **)&info);
PRUint32 paramCount = info->GetParamCount();
args = env->NewObjectArray(paramCount, objectClass,NULL);
bcJavaMarshalToolkit * mt = new bcJavaMarshalToolkit(mid, interfaceInfo, args, env,1, call->GetORB());
bcIUnMarshaler * um = call->GetUnMarshaler();
mt->UnMarshal(um);
if (!objectClass) {
Init();
if (!objectClass) {
return;
}
}
jobject jiid = bcIIDJava::GetObject(&iid);
bcJavaGlobal::GetJNIEnv()->CallStaticObjectMethod(utilitiesClass, callMethodByIndexMID, object, jiid, (jint)mid, args);
//nb return value; excepion handling
bcIMarshaler * m = call->GetMarshaler(); //nb ** to do
mt->Marshal(m);
return;
}
void bcJavaStub::Init() {
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
objectClass = (jclass)env->NewGlobalRef(env->FindClass("java/lang/Object"));
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return;
}
utilitiesClass = (jclass)env->NewGlobalRef(env->FindClass("org/mozilla/xpcom/Utilities"));
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return;
}
callMethodByIndexMID = env->GetStaticMethodID(utilitiesClass,"callMethodByIndex","(Ljava/lang/Object;Lorg/mozilla/xpcom/IID;I[Ljava/lang/Object;)Ljava/lang/Object;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return;
}
}

View File

@@ -0,0 +1,41 @@
/* -*- 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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcJavaStub_h
#define __bcJavaStub_h
#include "bcIStub.h"
#include "jni.h"
class bcJavaStub : public bcIStub {
public:
bcJavaStub(jobject obj);
virtual ~bcJavaStub();
virtual void Dispatch(bcICall *call) ;
private:
jobject object;
static jclass objectClass;
static jclass utilitiesClass;
static jmethodID callMethodByIndexMID;
void Init();
};
#endif

View File

@@ -0,0 +1,149 @@
/* -*- 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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "bcJavaStubsAndProxies.h"
#include "bcJavaStub.h"
#include "bcJavaGlobal.h"
#include "bcORB.h"
#include "bcIIDJava.h"
jclass bcJavaStubsAndProxies::componentLoader = 0;
jmethodID bcJavaStubsAndProxies::loadComponentID = 0;
jclass bcJavaStubsAndProxies::proxyFactory = 0;
jmethodID bcJavaStubsAndProxies::getProxyID = 0;
NS_DEFINE_CID(kORBCIID,BC_ORB_CID);
NS_GENERIC_FACTORY_CONSTRUCTOR(bcJavaStubsAndProxies);
static nsModuleComponentInfo components[] =
{
{
"Black Connect Java stubs and proxies",
BC_JAVASTUBSANDPROXIES_CID,
BC_JAVASTUBSANDPROXIES_PROGID,
bcJavaStubsAndProxiesConstructor
}
};
NS_IMPL_NSGETMODULE("BlackConnect Java stubs and proxies",components);
NS_IMPL_ISUPPORTS(bcJavaStubsAndProxies,NS_GET_IID(bcJavaStubsAndProxies));
bcJavaStubsAndProxies::bcJavaStubsAndProxies() {
NS_INIT_REFCNT();
}
bcJavaStubsAndProxies::~bcJavaStubsAndProxies() {
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetStub(jobject obj, bcIStub **stub) {
if (!stub) {
return NS_ERROR_NULL_POINTER;
}
*stub = new bcJavaStub(obj);
return NS_OK;
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetProxy(bcOID oid, const nsIID &iid, bcIORB *orb, jobject *proxy) {
printf("--[c++] bcJavaStubsAndProxies::GetProxy\n");
if (!componentLoader) {
Init();
}
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
*proxy = env->CallStaticObjectMethod(proxyFactory,getProxyID, (jlong)oid, jiid, (jlong)orb);
return NS_OK;
}
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) {
printf("--bcJavaStubsAndProxies::GetOID %s\n",location);
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
nsresult result;
if (!componentLoader) {
Init();
}
location[strlen(location)-5] = 0; //nb dirty hack. location is xyz.jar.info
jstring jstr = env->NewStringUTF(location);
jobject object = env->CallStaticObjectMethod(componentLoader, loadComponentID, jstr);
bcIStub *stub = new bcJavaStub(object);
NS_WITH_SERVICE(bcORB,_orb,kORBCIID,&result);
if (NS_FAILED(result)) {
printf("--bcJavaStubsAndProxies::GetOID failed\n");
return result;
}
bcIORB *orb;
_orb->GetORB(&orb);
*oid = orb->RegisterStub(stub);
return NS_OK;
}
void bcJavaStubsAndProxies::Init(void) {
printf("--[c++]bcJavaStubsAndProxies::Init\n");
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
componentLoader = env->FindClass("org/mozilla/xpcom/ComponentLoader");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
componentLoader = (jclass)env->NewGlobalRef(componentLoader);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
loadComponentID = env->GetStaticMethodID(componentLoader,"loadComponent","(Ljava/lang/String;)Ljava/lang/Object;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
proxyFactory = env->FindClass("org/mozilla/xpcom/ProxyFactory");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
proxyFactory = (jclass)env->NewGlobalRef(proxyFactory);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
getProxyID = env->GetStaticMethodID(proxyFactory, "getProxy","(JLorg/mozilla/xpcom/IID;J)Ljava/lang/Object;");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
componentLoader = 0;
return;
}
}

View File

@@ -0,0 +1,63 @@
/* -*- 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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#ifndef __bcJavaStubsAndProxies_h
#define __bcJavaStubsAndProxies_h
#include "nsISupports.h"
#include "jni.h"
#include "bcDefs.h"
#include "bcIStub.h"
#include "bcIORB.h"
/* 58034ea6-1dd2-11b2-9b58-8630abb8af47 */
#define BC_JAVASTUBSANDPROXIES_IID \
{0x58034ea6, 0x1dd2, 0x11b2, \
{0x9b, 0x58, 0x86, 0x30, 0xab, 0xb8, 0xaf,0x47}}
#define BC_JAVASTUBSANDPROXIES_PROGID "component://netscape/blackwood/blackconnect/java-stubs-and-proxies"
/* 7cadf6e8-1dd2-11b2-9a6e-b1c37844e004 */
#define BC_JAVASTUBSANDPROXIES_CID \
{0x7cadf6e8, 0x1dd2, 0x11b2, \
{0x9a, 0x6e, 0xb1, 0xc3, 0x78,0x44, 0xe0, 0x04}}
class bcJavaStubsAndProxies : public nsISupports {
NS_DECL_ISUPPORTS
NS_DEFINE_STATIC_IID_ACCESSOR(BC_JAVASTUBSANDPROXIES_IID)
NS_IMETHOD GetStub(jobject obj, bcIStub **stub);
NS_IMETHOD GetOID(char *location, bcOID *); //load component by location
NS_IMETHOD GetProxy(bcOID oid, const nsIID &iid, bcIORB *orb, jobject *proxy);
bcJavaStubsAndProxies();
virtual ~bcJavaStubsAndProxies();
protected:
void Init(void);
static jclass componentLoader;
static jmethodID loadComponentID;
static jclass proxyFactory;
static jmethodID getProxyID;
};
#endif /* __bcJavaStubsAndProxies_h */

View File

@@ -0,0 +1,49 @@
/* -*- 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 mozilla.org code.
*
* 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.
*
* Contributor(s):
* Igor Kushnirskiy <idk@eng.sun.com>
*/
#include "nsISupports.h"
#include "org_mozilla_xpcom_Utilities.h"
#include "bcIORB.h"
#include "bcICall.h"
#include "bcDefs.h"
/*
* Class: org_mozilla_xpcom_Utilities
* Method: callMethodByIndex
* Signature: (JILjava/lang/String;J[Ljava/lang/Object;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_org_mozilla_xpcom_Utilities_callMethodByIndex
(JNIEnv *env, jclass clazz, jlong _oid, jint mid, jstring jiid, jlong _orb, jobjectArray) {
bcIORB * orb = (bcIORB*) _orb;
bcOID oid = (bcOID)_oid;
nsIID iid;
printf("--[c++] jni %d\n",(int)mid);
const char * str = NULL;
str = env->GetStringUTFChars(jiid,NULL);
iid.Parse(str);
env->ReleaseStringUTFChars(jiid,str);
bcICall *call = orb->CreateCall(&iid, &oid, mid);
orb->SendReceive(call);
return NULL;
}

View File

@@ -0,0 +1,21 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_mozilla_xpcom_Utilities */
#ifndef _Included_org_mozilla_xpcom_Utilities
#define _Included_org_mozilla_xpcom_Utilities
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_mozilla_xpcom_Utilities
* Method: callMethodByIndex
* Signature: (JILjava/lang/String;J[Ljava/lang/Object;)Ljava/lang/Object;
*/
JNIEXPORT jobject JNICALL Java_org_mozilla_xpcom_Utilities_callMethodByIndex
(JNIEnv *, jclass, jlong, jint, jstring, jlong, jobjectArray);
#ifdef __cplusplus
}
#endif
#endif