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,37 @@
#!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@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS= \
loader \
src \
classes \
test \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,43 @@
#!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@
VPATH = @srcdir@
srcdir = @srcdir@
JAVA_OR_NSJVM=1
include $(DEPTH)/config/autoconf.mk
JAR_PLUGLET_CLASSES = \
org/mozilla/xpcom \
$(NULL)
JDIRS = $(JAR_PLUGLET_CLASSES)
include $(topsrcdir)/config/rules.mk
JAVAC=$(JDKHOME)/bin/javac -classpath .:$(CLASSPATH) -d $(DIST)/classes

View File

@@ -0,0 +1,62 @@
/* -*- 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>
*/
package org.mozilla.xpcom;
import java.net.URLClassLoader;
import java.net.URL;
import java.util.jar.Manifest;
import java.util.jar.Attributes;
import java.io.InputStream;
import java.io.File;
public class ComponentLoader {
// path to jar file. Name of main class sould to be in MANIFEST.
public static Object loadComponent(String location) {
try {
File file = (new File(location)).getCanonicalFile(); //To avoid spelling diffs, e.g c: and C:
location = file.getAbsolutePath();
if (File.separatorChar != '/') {
location = location.replace(File.separatorChar,'/');
}
if (!location.startsWith("/")) {
location = "/" + location;
}
URL url = new URL("file:"+location);
URLClassLoader loader = URLClassLoader.newInstance(new URL[]{url});
URL manifestURL = new URL("jar:file:"+location+"!/META-INF/MANIFEST.MF");
InputStream inputStream = manifestURL.openStream();
Manifest manifest = new Manifest(inputStream);
Attributes attr = manifest.getMainAttributes();
String componentClassName = attr.getValue("Component-Class");
if (componentClassName == null) {
//nb
return null;
}
Object object = loader.loadClass(componentClassName).newInstance();
return object;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View File

@@ -0,0 +1,55 @@
/* -*- 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>
*/
package org.mozilla.xpcom;
public class IID {
public IID(String iid) {
this.iid = (iid == null) ? "" : iid;
}
public boolean equals(Object obj) {
if (! (obj instanceof IID)) {
return false;
}
boolean res = iid.equals(((IID)obj).iid);
return res;
}
public String toString() {
return "org.mozilla.xpcom.IID@"+iid;
}
public int hashCode() {
int h = iid.hashCode();
return h;
}
public String getString() {
return iid;
}
private String iid;
public static Class TYPE;
static {
try {
TYPE = Class.forName("org.mozilla.xpcom.Proxy");
} catch (Exception e) { //it could not happen
TYPE = null;
}
}
}

View File

@@ -0,0 +1,77 @@
/* -*- 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>
*/
package org.mozilla.xpcom;
import java.lang.reflect.*;
import java.util.*;
public class ProxyClass { //nb it should not be public
public ProxyClass(IID _iid, Method[] _methods) { //nb it should not be public
iid = _iid;
methods = _methods;
if (classes == null) {
classes = new Hashtable();
}
classes.put(iid, this);
}
Method getMethodByIndex(int mid) { //first method has index equal to 'offset'
System.out.println("--[java]ProxyClass.GetMehodByIndex "+mid);
Method result = null;
try {
result = methods[mid-offset];
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
int getIndexByMethod(Method method) {
int result = 0;
if (method == null
||methods == null) {
return result;
}
for (int i = 0; i < methods.length; i++) {
if (methods[i].equals(method)) {
result = i + offset;
break;
}
}
return result;
}
static ProxyClass getProxyClass(IID iid) {
ProxyClass result = null;
Object obj = null;
if (classes != null) {
obj = classes.get(iid);
if (obj != null
&& (obj instanceof ProxyClass)) {
result = (ProxyClass)obj;
}
}
return result;
}
private IID iid;
private Method[] methods;
private final int offset = 3; //from xpcom
static Hashtable classes = null;
}

View File

@@ -0,0 +1,97 @@
/* -*- 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>
*/
package org.mozilla.xpcom;
import java.util.*;
import java.lang.reflect.*;
import java.lang.ref.*;
class ProxyKey {
ProxyKey(long _oid, IID _iid) {
oid = new Long(_oid);
iid = _iid;
}
public boolean equals(Object obj) {
if (! (obj instanceof ProxyKey)) {
return false;
}
return (oid.equals(((ProxyKey)obj).oid) && iid.equals(((ProxyKey)obj).iid));
}
public int hashCode() {
return oid.hashCode();
}
public String toString() {
return "org.mozilla.xpcom.ProxyFactory.ProxyKey "+oid+" "+iid;
}
Long oid;
IID iid;
}
public class ProxyFactory {
public static void registerInterfaceForIID(Class inter, IID iid) {
System.out.println("--[java] ProxyFactory.registerInterfaceForIID "+iid);
if (interfaces == null) {
interfaces = new Hashtable();
}
interfaces.put(iid, inter); //nb who is gonna remove object from cache?
}
public static Object getProxy(long oid, IID iid, long orb) {
System.out.println("--[java] ProxyFactory.getProxy "+iid);
ProxyKey key = new ProxyKey(oid, iid);
Object obj = null;
Object result = null;
if (proxies != null) {
obj = proxies.get(key);
if (obj != null
&& (obj instanceof Reference)) {
result = ((Reference)obj).get();
}
} else {
proxies = new Hashtable();
}
if (result == null) {
if (interfaces != null) {
obj = interfaces.get(iid);
if (obj == null) {
System.out.println("--[java] ProxyFactory.getProxy obj == null");
return null;
}
}
if (!(obj instanceof Class)) {
System.out.println("--[java] ProxyFactory.getProxy !(obj instanceof Class"+obj);
return null;
}
Class inter = (Class) obj;
InvocationHandler handler = new ProxyHandler(oid, iid, orb);
result = Proxy.newProxyInstance(inter.getClassLoader(), new Class[] {inter},handler);
proxies.put(new WeakReference(result), key);
}
System.out.println("--[java] ProxyFactory.getProxy end"+result);
return result;
}
protected static Hashtable proxies = null;
private static Hashtable interfaces = null;
}

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>
*/
package org.mozilla.xpcom;
import java.lang.reflect.*;
class ProxyHandler implements InvocationHandler {
ProxyHandler(long _oid, IID _iid, long _orb) {
oid = _oid;
iid = _iid;
orb = _orb;
}
public Object invoke(Object proxy,
Method method,
Object[] args) throws Throwable {
return Utilities.callMethod(oid, method, iid, orb, args);
}
private long oid;
private IID iid;
private long orb;
}

View File

@@ -0,0 +1,78 @@
/* -*- 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>
*/
package org.mozilla.xpcom;
import java.lang.reflect.*;
public class Utilities {
static Object callMethodByIndex(Object obj, IID iid, int mid, Object[] args) {
System.out.println("--org.mozilla.xpcom.Utilities.callMethodByIndex "+args.length+" "+mid);
for (int i = 0; i < args.length; i++) {
System.out.println("--callMethodByIndex args["+i+"] = "+args[i]);
}
Method method = getMethodByIndex(mid,iid);
System.out.println("--callMethodByIndex method "+method);
try {
if (method != null) {
method.invoke(obj,args);
}
} catch (Exception e) {
e.printStackTrace();
}
return null; //nb for testing
}
static Object callMethod(long oid, Method method, IID iid, long orb , Object[] args) {
System.out.println("--[java]Utilities.callMethod "+method);
int mid = getIndexByMethod(method, iid);
if (mid <= 0) {
return null;
}
System.out.println("--[java]Utilities.callMethod "+mid);
return callMethodByIndex(oid,mid,iid.getString(), orb, args);
}
private static Method getMethodByIndex(int index, IID iid) {
Method result = null;
ProxyClass proxyClass = ProxyClass.getProxyClass(iid);
if (proxyClass != null) {
result = proxyClass.getMethodByIndex(index);
}
return result;
}
private static int getIndexByMethod(Method method, IID iid) {
int result = 0;
ProxyClass proxyClass = ProxyClass.getProxyClass(iid);
if (proxyClass != null) {
result = proxyClass.getIndexByMethod(method);
}
return result;
}
private static native Object callMethodByIndex(long oid, int index, String iid, long orb, Object[] args);
static {
System.loadLibrary("bcjavastubs");
}
}

View File

@@ -0,0 +1,46 @@
#!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
MODULE = javaloader
LIBRARY_NAME = javaloader
IS_COMPONENT = 1
CPPSRCS = bcJavaComponentLoader.cpp bcJavaModule.cpp bcJavaComponentFactory.cpp
include $(topsrcdir)/config/rules.mk
ifneq ($(OS_ARCH),BeOS)
LIBS += -lmozjs -lxpcom $(NSPR_LIBS)
endif
EXTRA_DSO_LDOPTS += \
$(MOZ_COMPONENT_LIBS) \
$(NULL)

View File

@@ -0,0 +1,89 @@
/* -*- 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 "nsIServiceManager.h"
#include "nsCRT.h"
#include "bcJavaComponentFactory.h"
#include "bcJavaStubsAndProxies.h"
#include "bcXPCOMStubsAndProxies.h"
#include "bcORB.h"
static NS_DEFINE_CID(kJavaStubsAndProxies,BC_JAVASTUBSANDPROXIES_CID);
static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
static NS_DEFINE_CID(kORBCIID,BC_ORB_CID);
NS_IMPL_ISUPPORTS1(bcJavaComponentFactory, nsIFactory)
bcJavaComponentFactory::bcJavaComponentFactory(const char *_location) {
NS_INIT_ISUPPORTS();
location = nsCRT::strdup(_location);
}
bcJavaComponentFactory::~bcJavaComponentFactory() {
nsCRT::free((char*)location);
}
/* void CreateInstance (in nsISupports aOuter, in nsIIDRef iid, [iid_is (iid), retval] out nsQIResult result);
*/
NS_IMETHODIMP bcJavaComponentFactory::CreateInstance(nsISupports *aOuter, const nsIID & iid, void * *result) {
printf("--bcJavaComponentFactory::CreateInstance\n");
nsresult r;
NS_WITH_SERVICE(bcJavaStubsAndProxies, javaStubsAndProxies, kJavaStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--bcJavaComponentFactory::CreateInstance javaStubsAndProxies failed \n");
return r;
}
NS_WITH_SERVICE(bcXPCOMStubsAndProxies, xpcomStubsAndProxies, kXPCOMStubsAndProxies, &r);
if (NS_FAILED(r)) {
printf("--bcJavaComponentFactory::CreateInstance xpcomStubsAndProxies failed \n");
return r;
}
NS_WITH_SERVICE(bcORB, _orb, kORBCIID, &r);
if (NS_FAILED(r)) {
printf("--bcJavaComponentFactory::CreateInstance bcORB failed \n");
return r;
}
bcIORB *orb;
_orb->GetORB(&orb);
bcOID oid;
r = javaStubsAndProxies->GetOID(location, &oid);
printf("--bcJavaComponentFactory::CreateInstance after GetOID");
nsISupports *proxy;
xpcomStubsAndProxies->GetProxy(oid, iid, orb, &proxy);
*result = proxy;
printf("--bcJavaComponentFactory::CreateInstance end");
return NS_OK;
}
/* void LockFactory (in PRBool lock); */
NS_IMETHODIMP bcJavaComponentFactory::LockFactory(PRBool lock)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@@ -0,0 +1,39 @@
/* -*- 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 __bcJavaComponentFactory_h
#define __bcJavaComponentFactory_h
#include "nsIFactory.h"
class bcJavaComponentFactory : public nsIFactory {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
bcJavaComponentFactory(const char *location);
virtual ~bcJavaComponentFactory();
private:
char *location;
};
#endif

View File

@@ -0,0 +1,632 @@
/* -*- 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>
*/
/*
A bunch of stuff was copied from mozJSComponentLoader.cpp
*/
#include "bcJavaComponentLoader.h"
#include "nsCOMPtr.h"
#include "nsIModule.h"
#include "nsIGenericFactory.h"
#include "nsXPIDLString.h"
#include "nsCRT.h"
#include "bcJavaModule.h"
/*********************************************************************************/
//#include "bcIJavaSample.h"
#include "unistd.h"
#include "signal.h"
/********************************************************************************/
const char javaComponentTypeName[] = JAVACOMPONENTTYPENAME;
extern const char xpcomKeyName[];
NS_IMPL_ISUPPORTS(bcJavaComponentLoader,NS_GET_IID(nsIComponentLoader));
bcJavaComponentLoader::bcJavaComponentLoader()
: mCompMgr(NULL),
mXPCOMKey(0)
{
NS_INIT_REFCNT();
printf("--bcJavaComponentLoader::bcJavaComponentLoader \n");
}
bcJavaComponentLoader::~bcJavaComponentLoader() { //nb
printf("--bcJavaComponentLoader::~bcJavaComponentLoader \n");
}
/**
* Get the factory for a given component.
*/
/* nsIFactory getFactory (in nsIIDRef aCID, in string aLocation, in string aType); */
NS_IMETHODIMP bcJavaComponentLoader::GetFactory(const nsIID & aCID, const char *aLocation, const char *aType, nsIFactory **_retval) {
printf("--bcJavaComponentLoader::GetFactory \n");
if (!_retval)
return NS_ERROR_NULL_POINTER;
#ifdef DEBUG
char *cidString = aCID.ToString();
fprintf(stderr, "--bcJavaComponentLoader::GetFactory(%s,%s,%s)\n", cidString, aLocation, aType);
delete [] cidString;
#endif
nsIModule * module = ModuleForLocation(aLocation, 0);
if (!module) {
#ifdef DEBUG
fprintf(stderr, "ERROR: couldn't get module for %s\n", aLocation);
#endif
return NS_ERROR_FACTORY_NOT_LOADED;
}
nsresult rv = module->GetClassObject(mCompMgr, aCID,
NS_GET_IID(nsIFactory),
(void **)_retval);
#ifdef DEBUG
fprintf(stderr, "GetClassObject %s\n", NS_FAILED(rv) ? "FAILED" : "ok");
#endif
return rv;
}
/**
* Initialize the loader.
*
* We use nsISupports here because nsIRegistry isn't IDLized yet.
*/
/* void init (in nsIComponentManager aCompMgr, in nsISupports aRegistry); */
NS_IMETHODIMP bcJavaComponentLoader::Init(nsIComponentManager *aCompMgr, nsISupports *aReg) {
printf("--bcJavaComponentLoader::Init \n");
nsresult rv;
mCompMgr = aCompMgr;
mRegistry = do_QueryInterface(aReg, &rv);
if (NS_SUCCEEDED(rv)) {
rv = mRegistry->GetSubtree(nsIRegistry::Common, xpcomKeyName,
&mXPCOMKey);
if (NS_FAILED(rv))
/* if we can't get the XPCOM key, just skip all registry ops */
mRegistry = nsnull;
}
return NS_OK;
}
/**
* Called when a component of the appropriate type is registered,
* to give the component loader an opportunity to do things like
* annotate the registry and such.
*/
/* void onRegister (in nsIIDRef aCID, in string aType, in string aClassName, in string aProgID, in string aLocation, in boolean aReplace, in boolean aPersist); */
NS_IMETHODIMP bcJavaComponentLoader::OnRegister(const nsIID & aCID, const char *aType, const char *aClassName, const char *aProgID, const char *aLocation, PRBool aReplace, PRBool aPersist) { //nb
printf("--bcJavaComponentLoader::OnRegister \n");
return NS_OK;
}
/**
* AutoRegister components in the given directory.
*/
/* void autoRegisterComponents (in long aWhen, in nsIFile aDirectory); */
NS_IMETHODIMP bcJavaComponentLoader::AutoRegisterComponents(PRInt32 aWhen, nsIFile *aDirectory) {
//printf("--bcJavaComponentLoader::AutoRegisterComponents \n");
return RegisterComponentsInDir(aWhen,aDirectory);
}
nsresult bcJavaComponentLoader::RegisterComponentsInDir(PRInt32 when, nsIFile *dir)
{
nsresult rv;
PRBool isDir;
if (NS_FAILED(rv = dir->IsDirectory(&isDir)))
return rv;
if (!isDir)
return NS_ERROR_INVALID_ARG;
// Create a directory iterator
nsCOMPtr<nsISimpleEnumerator> dirIterator;
rv = dir->GetDirectoryEntries(getter_AddRefs(dirIterator));
if (NS_FAILED(rv)) return rv;
// whip through the directory to register every file
nsIFile *dirEntry = NULL;
PRBool more = PR_FALSE;
rv = dirIterator->HasMoreElements(&more);
if (NS_FAILED(rv)) return rv;
while (more == PR_TRUE)
{
rv = dirIterator->GetNext((nsISupports**)&dirEntry);
if (NS_SUCCEEDED(rv))
{
rv = dirEntry->IsDirectory(&isDir);
if (NS_SUCCEEDED(rv))
{
if (isDir == PR_TRUE)
{
// This is a directory. Grovel for components into the directory.
rv = RegisterComponentsInDir(when, dirEntry);
}
else
{
PRBool registered;
// This is a file. Try to register it.
rv = AutoRegisterComponent(when, dirEntry, &registered);
}
}
NS_RELEASE(dirEntry);
}
rv = dirIterator->HasMoreElements(&more);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;
}
/**
* AutoRegister the given component.
*
* Returns true if the component was registered, false if it couldn't
* attempt to register the component (wrong type) and ``throws'' an
* NS_FAILED code if there was an error during registration.
*/
/* boolean autoRegisterComponent (in long aWhen, in nsIFile aComponent); */
/* copied from mozJSComponentLoader.cpp */
NS_IMETHODIMP bcJavaComponentLoader::AutoRegisterComponent(PRInt32 when, nsIFile *component, PRBool *registered) {
//printf("--bcJavaComponentLoader::AutoRegisterComponent \n");
nsresult rv;
if (!registered)
return NS_ERROR_NULL_POINTER;
const char javaExtension[] = ".jar.info";
int javaExtensionLen = 9;
nsXPIDLCString leafName;
*registered = PR_FALSE;
/* we only do files */
PRBool isFile = PR_FALSE;
if (NS_FAILED(rv = component->IsFile(&isFile)) || !isFile)
return rv;
if (NS_FAILED(rv = component->GetLeafName(getter_Copies(leafName))))
return rv;
int len = PL_strlen(leafName);
/* if it's not javaExtension return now */
if (len < javaExtensionLen || // too short
PL_strcasecmp(leafName + len - javaExtensionLen, javaExtension))
return NS_OK;
printf("--bcJavaComponentLoader: registering bcJavaComponent component %s\n",(const char *)leafName);
rv = AttemptRegistration(component, PR_FALSE);
if (NS_SUCCEEDED(rv))
printf("registered module %s\n", (const char *)leafName);
else if (rv == NS_ERROR_FACTORY_REGISTER_AGAIN)
printf("deferred module %s\n", (const char *)leafName);
else
printf("failed to register %s\n", (const char *)leafName);
*registered = (PRBool) NS_SUCCEEDED(rv);
return NS_OK;
}
nsresult bcJavaComponentLoader::AttemptRegistration(nsIFile *component,
PRBool deferred) {
nsXPIDLCString registryLocation;
nsresult rv;
nsIModule *module;
rv = mCompMgr->RegistryLocationForSpec(component,
getter_Copies(registryLocation));
if (NS_FAILED(rv))
return rv;
/* no need to check registry data on deferred reg */
if (deferred || HasChanged(registryLocation, component)) {
module = ModuleForLocation(registryLocation, component);
if (module) {
rv = module->RegisterSelf(mCompMgr, component, registryLocation,
javaComponentTypeName);
if (rv == NS_ERROR_FACTORY_REGISTER_AGAIN) {
mDeferredComponents.AppendElement(component);
/*
* we don't enter in the registry because we may want to
* try again on a later autoreg, in case a dependency has
* become available.
*/
return rv;
}
}
}
SetRegistryInfo(registryLocation, component);
return rv;
}
nsresult bcJavaComponentLoader::SetRegistryInfo(const char *registryLocation,
nsIFile *component)
{
if (!mRegistry.get())
return NS_OK; // silent failure
nsresult rv;
nsRegistryKey key;
rv = mRegistry->AddSubtreeRaw(mXPCOMKey, registryLocation, &key);
if (NS_FAILED(rv))
return rv;
PRInt64 modDate;
if (NS_FAILED(rv = component->GetLastModificationDate(&modDate)) ||
NS_FAILED(rv = mRegistry->SetLongLong(key, lastModValueName, &modDate)))
return rv;
PRInt64 fileSize;
if (NS_FAILED(rv = component->GetFileSize(&fileSize)) ||
NS_FAILED(rv = mRegistry->SetLongLong(key, fileSizeValueName, &fileSize)))
return rv;
printf("SetRegistryInfo(%s) => (%d,%d)\n", registryLocation,
modDate, fileSize);
return NS_OK;
}
PRBool bcJavaComponentLoader::HasChanged(const char *registryLocation, nsIFile *component) {
/* if we don't have a registry handle, force registration of component */
if (!mRegistry)
return PR_TRUE;
nsRegistryKey key;
if (NS_FAILED(mRegistry->GetSubtreeRaw(mXPCOMKey, registryLocation, &key)))
return PR_TRUE;
/* check modification date */
PRInt64 regTime, lastTime;
if (NS_FAILED(mRegistry->GetLongLong(key, lastModValueName, &regTime)))
return PR_TRUE;
if (NS_FAILED(component->GetLastModificationDate(&lastTime)) || LL_NE(lastTime, regTime))
return PR_TRUE;
/* check file size */
PRInt64 regSize;
if (NS_FAILED(mRegistry->GetLongLong(key, fileSizeValueName, &regSize)))
return PR_TRUE;
PRInt64 size;
if (NS_FAILED(component->GetFileSize(&size)) || LL_NE(size,regSize) )
return PR_TRUE;
return PR_FALSE;
}
nsIModule * bcJavaComponentLoader::ModuleForLocation(const char *registryLocation, nsIFile *component) {
nsStringKey key(registryLocation);
nsIModule *res = NULL;
res = (nsIModule*)mModules.Get(&key);
PRBool needRelease = PR_FALSE;
if (res) {
return res;
}
if (!component) {
if (NS_FAILED(mCompMgr->SpecForRegistryLocation(registryLocation, &component)))
return NULL;
needRelease = PR_TRUE;
}
res = new bcJavaModule(registryLocation, component);
if (needRelease) {
NS_IF_RELEASE(component);
}
if (res) {
mModules.Put(&key,res);
}
return res;
}
/**
* Register any deferred (NS_ERROR_FACTORY_REGISTER_AGAIN) components.
* Return registered-any-components?
*/
/* boolean registerDeferredComponents (in long aWhen); */
NS_IMETHODIMP bcJavaComponentLoader::RegisterDeferredComponents(PRInt32 aWhen, PRBool *aRegistered) {
printf("--bcJavaComponentLoader::RegisterDeferredComponents \n");
nsresult rv;
*aRegistered = PR_FALSE;
PRUint32 count;
rv = mDeferredComponents.Count(&count);
printf("mJCL: registering deferred (%d)\n", count);
if (NS_FAILED(rv) || !count)
return NS_OK;
for (PRUint32 i = 0; i < count; i++) {
nsCOMPtr<nsISupports> supports;
nsCOMPtr<nsIFile> component;
rv = mDeferredComponents.GetElementAt(i, getter_AddRefs(supports));
if (NS_FAILED(rv))
continue;
component = do_QueryInterface(supports, &rv);
if (NS_FAILED(rv))
continue;
rv = AttemptRegistration(component, PR_TRUE /* deferred */);
if (rv != NS_ERROR_FACTORY_REGISTER_AGAIN) {
if (NS_SUCCEEDED(rv))
*aRegistered = PR_TRUE;
mDeferredComponents.RemoveElementAt(i);
}
}
rv = mDeferredComponents.Count(&count);
if (NS_SUCCEEDED(rv)) {
if (*aRegistered)
printf("mJCL: registered deferred, %d left\n", count);
else
printf("mJCL: didn't register any components, %d left\n", count);
}
/* are there any fatal errors? */
return NS_OK;
}
/**
* Unload all components that are willing.
*/
/* void unloadAll (in long aWhen); */
NS_IMETHODIMP bcJavaComponentLoader::UnloadAll(PRInt32 aWhen) { //nb
printf("--bcJavaComponentLoader::UnloadAll \n");
return NS_OK;
}
NS_GENERIC_FACTORY_CONSTRUCTOR(bcJavaComponentLoader)
static nsModuleComponentInfo components[] =
{
{
"Java Component Loader",
BC_JAVACOMPONENTLOADER_CID,
BC_JAVACOMPONENTLOADER_PROGID,
bcJavaComponentLoaderConstructor
}
};
/* copied-and-pasted from mozJSComponentLoader */
#include "nsHashtable.h"
class bcJavaComponentLoaderModule : public nsIModule
{
public:
bcJavaComponentLoaderModule(const char *moduleName, PRUint32 componentCount,
nsModuleComponentInfo *components);
virtual ~bcJavaComponentLoaderModule();
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
protected:
nsresult Initialize();
void Shutdown();
PRBool mInitialized;
const char* mModuleName;
PRUint32 mComponentCount;
nsModuleComponentInfo* mComponents;
nsSupportsHashtable mFactories;
};
bcJavaComponentLoaderModule::bcJavaComponentLoaderModule(const char* moduleName, PRUint32 componentCount,
nsModuleComponentInfo* aComponents)
: mInitialized(PR_FALSE),
mModuleName(moduleName),
mComponentCount(componentCount),
mComponents(aComponents),
mFactories(8, PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
bcJavaComponentLoaderModule::~bcJavaComponentLoaderModule()
{
Shutdown();
}
NS_IMPL_ISUPPORTS1(bcJavaComponentLoaderModule, nsIModule)
// Perform our one-time intialization for this module
nsresult
bcJavaComponentLoaderModule::Initialize()
{
if (mInitialized) {
return NS_OK;
}
mInitialized = PR_TRUE;
return NS_OK;
}
// Shutdown this module, releasing all of the module resources
void
bcJavaComponentLoaderModule::Shutdown()
{
// Release the factory objects
mFactories.Reset();
}
// Create a factory object for creating instances of aClass.
NS_IMETHODIMP
bcJavaComponentLoaderModule::GetClassObject(nsIComponentManager *aCompMgr,
const nsCID& aClass,
const nsIID& aIID,
void** r_classObj)
{
nsresult rv;
// Defensive programming: Initialize *r_classObj in case of error below
if (!r_classObj) {
return NS_ERROR_INVALID_POINTER;
}
*r_classObj = NULL;
// Do one-time-only initialization if necessary
if (!mInitialized) {
rv = Initialize();
if (NS_FAILED(rv)) {
// Initialization failed! yikes!
return rv;
}
}
// Choose the appropriate factory, based on the desired instance
// class type (aClass).
nsIDKey key(aClass);
nsCOMPtr<nsIGenericFactory> fact = getter_AddRefs(NS_REINTERPRET_CAST(nsIGenericFactory *, mFactories.Get(&key)));
if (fact == nsnull) {
nsModuleComponentInfo* desc = mComponents;
for (PRUint32 i = 0; i < mComponentCount; i++) {
if (desc->mCID.Equals(aClass)) {
rv = NS_NewGenericFactory(getter_AddRefs(fact), desc->mConstructor);
if (NS_FAILED(rv)) return rv;
(void)mFactories.Put(&key, fact);
goto found;
}
desc++;
}
// not found in descriptions
#ifdef DEBUG
char* cs = aClass.ToString();
printf("+++ nsGenericModule %s: unable to create factory for %s\n", mModuleName, cs);
nsCRT::free(cs);
#endif
// XXX put in stop-gap so that we don't search for this one again
return NS_ERROR_FACTORY_NOT_REGISTERED;
}
found:
rv = fact->QueryInterface(aIID, r_classObj);
return rv;
}
NS_IMETHODIMP
bcJavaComponentLoaderModule::RegisterSelf(nsIComponentManager *aCompMgr,
nsIFile* aPath,
const char* registryLocation,
const char* componentType)
{
nsresult rv = NS_OK;
#ifdef DEBUG
printf("*** Registering %s components (all right -- an almost-generic module!)\n", mModuleName);
#endif
nsModuleComponentInfo* cp = mComponents;
for (PRUint32 i = 0; i < mComponentCount; i++) {
rv = aCompMgr->RegisterComponentSpec(cp->mCID, cp->mDescription,
cp->mProgID, aPath, PR_TRUE,
PR_TRUE);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsGenericModule %s: unable to register %s component => %x\n",
mModuleName, cp->mDescription, rv);
#endif
break;
}
cp++;
}
printf("JavaComponentLoaderModule::RegisterSelf \n");
return aCompMgr->RegisterComponentLoader(javaComponentTypeName,
BC_JAVACOMPONENTLOADER_PROGID,
PR_TRUE);
}
NS_IMETHODIMP
bcJavaComponentLoaderModule::UnregisterSelf(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* registryLocation)
{
#ifdef DEBUG
printf("*** Unregistering %s components (all right -- an almost-generic module!)\n", mModuleName);
#endif
nsModuleComponentInfo* cp = mComponents;
for (PRUint32 i = 0; i < mComponentCount; i++) {
nsresult rv = aCompMgr->UnregisterComponentSpec(cp->mCID, aPath);
if (NS_FAILED(rv)) {
#ifdef DEBUG
printf("nsGenericModule %s: unable to unregister %s component => %x\n",
mModuleName, cp->mDescription, rv);
#endif
}
cp++;
}
return NS_OK;
}
NS_IMETHODIMP
bcJavaComponentLoaderModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *okToUnload)
{
printf("--bcJavaComponentLoaderModule::CanUnload\n");
if (!okToUnload) {
return NS_ERROR_INVALID_POINTER;
}
*okToUnload = PR_TRUE;
return NS_OK;
}
NS_EXPORT nsresult
NS_NewJavaComponentLoaderModule(const char* moduleName,
PRUint32 componentCount,
nsModuleComponentInfo* aComponents,
nsIModule* *result)
{
nsresult rv = NS_OK;
NS_ASSERTION(result, "Null argument");
// Create and initialize the module instance
bcJavaComponentLoaderModule *m = new bcJavaComponentLoaderModule(moduleName, componentCount, aComponents);
if (!m) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Increase refcnt and store away nsIModule interface to m in return_cobj
rv = m->QueryInterface(NS_GET_IID(nsIModule), (void**)result);
if (NS_FAILED(rv)) {
delete m;
m = nsnull;
}
return rv;
}
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *compMgr,
nsIFile *location,
nsIModule** result)
{
return NS_NewJavaComponentLoaderModule("bcJavaComponentLoaderModule",
sizeof(components) / sizeof(components[0]),
components, result);
}

View File

@@ -0,0 +1,67 @@
/* -*- 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 _bcJavaComponentLoader_h
#define _bcJavaComponentLoader_h
#include "nsIComponentLoader.h"
#include "nsIModule.h"
#include "nsHashtable.h"
#include "nsCOMPtr.h"
#include "nsIFileSpec.h"
#include "nsIFile.h"
#include "nsIRegistry.h"
#include "nsSupportsArray.h"
#define BC_JAVACOMPONENTLOADER_PROGID \
"component://netscape/blackwood/blackconnect/java-component-loader"
/* 0d6b5198-1dd2-11b2-b2f0-ed49ba755db8 */
#define BC_JAVACOMPONENTLOADER_CID \
{ 0x0d6b5198, 0x1dd2, 0x11b2, \
{0xb2, 0xf0, 0xed, 0x49, 0xba, 0x75, 0x5d, 0xb8 }}
#define JAVACOMPONENTTYPENAME "text/java"
class bcJavaComponentLoader : public nsIComponentLoader {
NS_DECL_ISUPPORTS
NS_DECL_NSICOMPONENTLOADER
bcJavaComponentLoader();
virtual ~bcJavaComponentLoader();
protected:
nsHashtable mModules;
nsCOMPtr<nsIRegistry> mRegistry;
nsIComponentManager* mCompMgr; // weak ref, should make it strong?
nsRegistryKey mXPCOMKey;
nsSupportsArray mDeferredComponents;
nsresult RegisterComponentsInDir(PRInt32 when, nsIFile *dir);
nsresult AttemptRegistration(nsIFile *component, PRBool deferred);
nsIModule * ModuleForLocation(const char *registryLocation, nsIFile *component);
PRBool HasChanged(const char *registryLocation, nsIFile *component);
nsresult SetRegistryInfo(const char *registryLocation, nsIFile *component);
};
#endif

View File

@@ -0,0 +1,88 @@
/* -*- 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 <fstream.h>
#include "nsCRT.h"
#include "nsIAllocator.h"
#include "nsXPIDLString.h"
#include "nsCOMPtr.h"
#include "bcJavaModule.h"
#include "bcJavaComponentFactory.h"
NS_IMPL_ISUPPORTS(bcJavaModule,NS_GET_IID(nsIModule));
bcJavaModule::bcJavaModule(const char *registryLocation, nsIFile *component)
: location(NULL) {
NS_INIT_REFCNT();
nsXPIDLCString str;
component->GetPath(getter_Copies(str));
location = nsCRT::strdup(str);
printf("--JavaModule::JavaModule %s\n",(const char*)str);
}
bcJavaModule::~bcJavaModule() {
if (location) {
nsCRT::free((char*)location);
}
}
/* void getClassObject (in nsIComponentManager aCompMgr, in nsCIDRef aClass, in nsIIDRef aIID, [iid_is (aIID), retval] out nsQIResult result); */
NS_IMETHODIMP bcJavaModule::GetClassObject(nsIComponentManager *aCompMgr, const nsCID & aClass, const nsIID & aIID, void * *result) {
printf("--JavaModule::GetClassObject\n");
nsIFactory *f;
f = new bcJavaComponentFactory(location);
NS_ADDREF(f);
*result = f;
return NS_OK;
}
/* void registerSelf (in nsIComponentManager aCompMgr, in nsIFile location, in string registryLocation, in string componentType); */
NS_IMETHODIMP bcJavaModule::RegisterSelf(nsIComponentManager *aCompMgr, nsIFile *_location, const char *registryLocation, const char *componentType) {
nsresult result;
printf("--JavaModule::RegisterSelf\n");
ifstream in(location);
char cidStr[500], progid[1000], desc[1000];
in.getline(cidStr,1000);
in.getline(progid,1000);
in.getline(desc,1000);
printf("%s %s %s", cidStr, progid, desc);
nsCID cid;
cid.Parse((const char *)cidStr);
aCompMgr->RegisterComponentWithType(cid, desc, progid, _location, registryLocation, PR_TRUE, PR_TRUE, componentType);
return NS_OK;
}
/* void unregisterSelf (in nsIComponentManager aCompMgr, in nsIFile location, in string registryLocation); */
NS_IMETHODIMP bcJavaModule::UnregisterSelf(nsIComponentManager *aCompMgr, nsIFile *_location, const char *registryLocation) { //nb
return NS_OK;
}
/* boolean canUnload (in nsIComponentManager aCompMgr); */
NS_IMETHODIMP bcJavaModule::CanUnload(nsIComponentManager *aCompMgr, PRBool *_retval) {
if (!_retval) {
return NS_ERROR_NULL_POINTER;
}
*_retval = PR_TRUE;
return NS_OK;
}

View File

@@ -0,0 +1,35 @@
/* -*- 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 _bcJavaModule_h
#define _bcJavaModule_h
#include "nsIModule.h"
class bcJavaModule : public nsIModule {
NS_DECL_ISUPPORTS
NS_DECL_NSIMODULE
bcJavaModule(const char *registryLocation, nsIFile *component);
virtual ~bcJavaModule();
protected:
const char *location;
};
#endif

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

View File

@@ -0,0 +1,51 @@
#!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 = ../../../..
srcdir = .
VPATH = .
include $(DEPTH)/config/autoconf.mk
MODULE = javaSample
LIBRARY_NAME = javaSample
IS_COMPONENT = 1
XPIDLSRCS = bcIJavaSample.idl
CPPSRCS = bcJavaSample.cpp
include $(topsrcdir)/config/rules.mk
bcJavaSample.jar: manifest bcIJavaSample.class bcJavaSample.class
$(JDKHOME)/bin/jar cvfm bcJavaSample.jar manifest *.class
.java.class:
$(JDKHOME)/bin/javac -classpath .:../classes $<
install-component: bcJavaSample.jar bcJavaSample.jar.info
cp bcJavaSample.jar bcJavaSample.jar.info $(DEPTH)/dist/bin/components/
clobber-java:
rm -f *.class *.jar
clobber:: clobber-java
clobber_all:: clobber-java
install:: install-component

View File

@@ -0,0 +1,9 @@
#include "nsISupports.idl"
[scriptable, uuid(ca1e2656-1dd1-11b2-9c4e-f49ea557abde)]
interface bcIJavaSample : nsISupports
{
void test0();
void test1(in long l);
void test2(in bcIJavaSample o);
};

View File

@@ -0,0 +1,14 @@
/**
* Interface nsISample
*
* IID: 0xca1e2656-1dd1-11b2-9c4e-f49ea557abde
*/
public interface bcIJavaSample
{
public static final String BC_IJAVASAMPLE_IID_STRING =
"ca1e2656-1dd1-11b2-9c4e-f49ea557abde";
void test0();
void test1(int l);
void test2(bcIJavaSample o);
}

View File

@@ -0,0 +1,103 @@
/* -*- 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 "bcIJavaSample.h"
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#define BC_JAVA_SAMPLE_CID \
{0x072fa586, 0x1dd2, 0x11b2, \
{ 0xb2, 0x3a, 0x81, 0xe8, 0x16, 0x49, 0xe8, 0x8b }}
#define BC_JAVA_SAMPLE_PROGID "javaSample.cpp"
class bcJavaSample : public bcIJavaSample {
NS_DECL_ISUPPORTS
NS_DECL_BCIJAVASAMPLE
bcJavaSample();
virtual ~bcJavaSample();
};
NS_IMPL_ISUPPORTS1(bcJavaSample, bcIJavaSample)
bcJavaSample::bcJavaSample()
{
NS_INIT_ISUPPORTS();
/* member initializers and constructor code */
}
bcJavaSample::~bcJavaSample()
{
/* destructor code */
}
NS_IMETHODIMP bcJavaSample::Test0()
{ printf("--[c++] bcJavaSample::Test0() \n");
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void test1 (in long l); */
NS_IMETHODIMP bcJavaSample::Test1(PRInt32 l)
{
printf("--[c++] bcJavaSample.test1\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void test2 (in bcIJavaSample o); */
NS_IMETHODIMP bcJavaSample::Test2(bcIJavaSample *o)
{ printf("--[c++] bcJavaSample.test2\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
void test() {
printf("--BlackConnect test start\n");
nsresult r;
bcIJavaSample *test;
bcIJavaSample *a = new bcJavaSample();
r = nsComponentManager::CreateInstance("bcJavaSample",
nsnull,
NS_GET_IID(bcIJavaSample),
(void**)&test);
//sigsend(P_PID, getpid(),SIGINT);
//test->Test1(2000);
//test->Test1(1000);
test->Test2(a);
printf("--BlackConnect test end\n");
}
static int counter = 0; //we do not need to call it on unload time;
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *compMgr,
nsIFile *location,
nsIModule** result) //I am using it for runnig test *only*
{
if (counter == 0) {
counter ++;
printf("--bcJavaSample before test\n");
test();
printf("--bcJavaSample after test\n");
}
return NS_ERROR_FAILURE;
}

View File

@@ -0,0 +1,3 @@
6b701852-1dd2-11b2-91bd-d3ab05f89834
bcJavaSample
bcJavaSample

View File

@@ -0,0 +1,73 @@
/* -*- 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>
*/
import org.mozilla.xpcom.*;
import java.lang.reflect.*;
public class bcJavaSample implements bcIJavaSample {
public bcJavaSample() {
System.out.println("--[java]bcJavaSample constructor");
}
public void test0() {
System.out.println("--[java]bcJavaSample.test0 ");
}
public void test1(int l) {
try {
System.out.println("--[java]bcJavaSample.test1 "+l);
System.out.println("--[java]bcJavaSample.test1\n :)))) Hey Hong"+l);
Object obj = ProxyFactory.getProxy(0,iid,0);
if (obj instanceof bcIJavaSample) {
bcIJavaSample proxy = (bcIJavaSample)obj;
proxy.test2(null);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void test2(bcIJavaSample o) {
System.out.println("--[java]bcJavaSample.test2");
System.out.println("--[java]bcJavaSample.test2 :)))) Hey Hong");
if (o != null) {
System.out.println("--[java]bcJavaSample.test2 o!= null");
o.test0();
} else {
System.out.println("--[java]bcJavaSample.test2 o== null");
}
}
static IID iid;
static {
try {
Method[] methods = null;
Class bcIJavaSampleClass = Class.forName("bcIJavaSample");
Method[] javaSampleMethods = bcIJavaSampleClass.getMethods();
methods = new Method[3];
methods[0] = javaSampleMethods[javaSampleMethods.length-3];
methods[1] = javaSampleMethods[javaSampleMethods.length-2];
methods[2] = javaSampleMethods[javaSampleMethods.length-1];
System.out.println(methods[0]+" "+methods[1]+" "+methods[2]);
iid = new IID(bcIJavaSample.BC_IJAVASAMPLE_IID_STRING);
ProxyFactory.registerInterfaceForIID(bcIJavaSampleClass,iid);
new ProxyClass(iid, methods);
} catch (Exception e) {
}
}
};

View File

@@ -0,0 +1 @@
Component-Class: bcJavaSample