* NOT PART OF TBOX BUILDS *
Fixed bug with [out] parametrs in java. Improved component registration. Added test for accessing ComponentManager from java git-svn-id: svn://10.0.0.236/trunk@79594 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -51,10 +51,9 @@ public class ComponentLoader {
|
||||
//nb
|
||||
return null;
|
||||
}
|
||||
Object object = loader.loadClass(componentClassName).newInstance();
|
||||
if (object instanceof nsISupports) {
|
||||
InterfaceRegistry.register((nsISupports)object);
|
||||
}
|
||||
Class component = loader.loadClass(componentClassName);
|
||||
InterfaceRegistry.register(component);
|
||||
Object object = component.newInstance();
|
||||
return object;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -25,7 +25,7 @@ package org.mozilla.xpcom;
|
||||
import java.util.Hashtable;
|
||||
import java.lang.reflect.*;
|
||||
|
||||
class InterfaceRegistry {
|
||||
public class InterfaceRegistry {
|
||||
|
||||
private static String IID_STRING = "IID";
|
||||
private static Hashtable interfaces = null;
|
||||
@@ -39,13 +39,20 @@ class InterfaceRegistry {
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
Class cl = obj.getClass();
|
||||
register(cl);
|
||||
}
|
||||
|
||||
public static void register(Class cl) {
|
||||
if (cl == null) {
|
||||
return;
|
||||
}
|
||||
if (interfaces == null) {
|
||||
interfaces = new Hashtable();
|
||||
}
|
||||
if (iMethods == null) {
|
||||
iMethods = new Hashtable();
|
||||
}
|
||||
Class cl = obj.getClass();
|
||||
if (!cl.isInterface()) {
|
||||
Class[] ifaces = cl.getInterfaces();
|
||||
for (int i = 0; i < ifaces.length; i++) {
|
||||
@@ -56,12 +63,11 @@ class InterfaceRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerInterfaces(Class cl) {
|
||||
private static void registerInterfaces(Class cl) {
|
||||
try {
|
||||
Object iidStr = cl.getField(IID_STRING).get(cl);
|
||||
if (iidStr instanceof String) {
|
||||
IID iid = new IID((String)iidStr);
|
||||
ProxyFactory.registerInterfaceForIID(cl,iid);
|
||||
String[] methodNames = Utilities.getInterfaceMethodNames((String)iidStr);
|
||||
if (methodNames != null) {
|
||||
Method[] rmethods = new Method[methodNames.length];
|
||||
@@ -128,7 +134,7 @@ class InterfaceRegistry {
|
||||
}
|
||||
|
||||
public static int getIndexByMethod(Method method, IID iid) {
|
||||
int result = 0;
|
||||
int result = -1;
|
||||
MethodArray m = (MethodArray)iMethods.get(iid);
|
||||
if (m != null && m.methods !=null) {
|
||||
for (int i = 0; i < m.methods.length; i++) {
|
||||
|
||||
@@ -47,28 +47,9 @@ class ProxyKey {
|
||||
}
|
||||
|
||||
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 Class getInterface(IID iid) {
|
||||
System.out.println("--[java] ProxyFactory.getInterface "+iid);
|
||||
Object obj = null;
|
||||
if (interfaces != null) {
|
||||
obj = interfaces.get(iid);
|
||||
if (obj == null) {
|
||||
System.out.println("--[java] ProxyFactory.getInterface interface== null");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (!(obj instanceof Class)) {
|
||||
System.out.println("--[java] ProxyFactory.getInterface !(obj instanceof Class"+obj);
|
||||
return null;
|
||||
}
|
||||
return (Class)obj;
|
||||
return InterfaceRegistry.getInterface(iid);
|
||||
}
|
||||
|
||||
public static Object getProxy(long oid, IID iid, long orb) {
|
||||
@@ -104,7 +85,6 @@ public class ProxyFactory {
|
||||
return null;
|
||||
}
|
||||
protected static Hashtable proxies = null;
|
||||
private static Hashtable interfaces = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ class ProxyHandler implements InvocationHandler {
|
||||
Method method,
|
||||
Object[] args) throws Throwable {
|
||||
System.out.println("--[java]ProxyHandler.invoke "+method);
|
||||
if ("toString".equals(method.getName())) {
|
||||
if ("toString".equals(method.getName()) &&
|
||||
(method.getParameterTypes()).length == 0) { //it is String toString() method
|
||||
return "ProxyObject@{oid = "+oid+" iid = "+iid+"}";
|
||||
}
|
||||
return Utilities.callMethod(oid, method, iid, orb, args);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Utilities {
|
||||
static Object callMethod(long oid, Method method, IID iid, long orb , Object[] args) {
|
||||
System.out.println("--[java]Utilities.callMethod "+method);
|
||||
int mid = InterfaceRegistry.getIndexByMethod(method, iid);
|
||||
if (mid <= 0) {
|
||||
if (mid < 0) {
|
||||
System.out.println("--[java]Utilities.callMethod we do not have implementation for "+method);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* ************* DO NOT EDIT THIS FILE ***********
|
||||
*
|
||||
* This file was automatically generated from nsIComponentManager.idl.
|
||||
*/
|
||||
|
||||
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
|
||||
/**
|
||||
* Interface nsIComponentManager
|
||||
*
|
||||
* IID: 0x8458a740-d5dc-11d2-92fb-00e09805570f
|
||||
*/
|
||||
|
||||
public interface nsIComponentManager extends nsISupports
|
||||
{
|
||||
public static final String IID =
|
||||
"8458a740-d5dc-11d2-92fb-00e09805570f";
|
||||
|
||||
|
||||
/* nsIFactory findFactory (in nsCIDRef aClass); */
|
||||
public void findFactory(IID aClass, nsIFactory[] _retval);
|
||||
|
||||
/* string CLSIDToContractID (in nsCIDRef aClass, out string aClassName); */
|
||||
public void cLSIDToContractID(IID aClass, String[] aClassName, String[] _retval);
|
||||
|
||||
/* string registryLocationForSpec (in nsIFile aSpec); */
|
||||
public void registryLocationForSpec(nsISupports aSpec, String[] _retval);
|
||||
|
||||
/* nsIFile specForRegistryLocation (in string aLocation); */
|
||||
public void specForRegistryLocation(String aLocation, nsISupports[] _retval);
|
||||
|
||||
/* void registerFactory (in nsCIDRef aClass, in string aClassName, in string aContractID, in nsIFactory aFactory, in boolean aReplace); */
|
||||
public void registerFactory(IID aClass, String aClassName, String aContractID, nsIFactory aFactory, boolean aReplace);
|
||||
|
||||
/* void registerComponent (in nsCIDRef aClass, in string aClassName, in string aContractID, in string aLocation, in boolean aReplace, in boolean aPersist); */
|
||||
public void registerComponent(IID aClass, String aClassName, String aContractID, String aLocation, boolean aReplace, boolean aPersist);
|
||||
|
||||
/* void registerComponentWithType (in nsCIDRef aClass, in string aClassName, in string aContractID, in nsIFile aSpec, in string aLocation, in boolean aReplace, in boolean aPersist, in string aType); */
|
||||
public void registerComponentWithType(IID aClass, String aClassName, String aContractID, nsISupports aSpec, String aLocation, boolean aReplace, boolean aPersist, String aType);
|
||||
|
||||
/* void registerComponentSpec (in nsCIDRef aClass, in string aClassName, in string aContractID, in nsIFile aLibrary, in boolean aReplace, in boolean aPersist); */
|
||||
public void registerComponentSpec(IID aClass, String aClassName, String aContractID, nsISupports aLibrary, boolean aReplace, boolean aPersist);
|
||||
|
||||
/* void registerComponentLib (in nsCIDRef aClass, in string aClassName, in string aContractID, in string aDllName, in boolean aReplace, in boolean aPersist); */
|
||||
public void registerComponentLib(IID aClass, String aClassName, String aContractID, String aDllName, boolean aReplace, boolean aPersist);
|
||||
|
||||
/* void unregisterFactory (in nsCIDRef aClass, in nsIFactory aFactory); */
|
||||
public void unregisterFactory(IID aClass, nsIFactory aFactory);
|
||||
|
||||
/* void unregisterComponent (in nsCIDRef aClass, in string aLocation); */
|
||||
public void unregisterComponent(IID aClass, String aLocation);
|
||||
|
||||
/* void unregisterComponentSpec (in nsCIDRef aClass, in nsIFile aLibrarySpec); */
|
||||
public void unregisterComponentSpec(IID aClass, nsISupports aLibrarySpec);
|
||||
|
||||
/* void freeLibraries (); */
|
||||
public void freeLibraries();
|
||||
|
||||
/* const long NS_Startup = 0; */
|
||||
public static final int NS_Startup = 0;
|
||||
|
||||
/* const long NS_Script = 1; */
|
||||
public static final int NS_Script = 1;
|
||||
|
||||
/* const long NS_Timer = 2; */
|
||||
public static final int NS_Timer = 2;
|
||||
|
||||
/* const long NS_Shutdown = 3; */
|
||||
public static final int NS_Shutdown = 3;
|
||||
|
||||
/* void autoRegister (in long when, in nsIFile directory); */
|
||||
public void autoRegister(int when, nsISupports directory);
|
||||
|
||||
/* void autoRegisterComponent (in long when, in nsIFile aFileLocation); */
|
||||
public void autoRegisterComponent(int when, nsISupports aFileLocation);
|
||||
|
||||
/* void autoUnregisterComponent (in long when, in nsIFile aFileLocation); */
|
||||
public void autoUnregisterComponent(int when, nsISupports aFileLocation);
|
||||
|
||||
/* boolean isRegistered (in nsCIDRef aClass); */
|
||||
public void isRegistered(IID aClass, boolean[] _retval);
|
||||
|
||||
/* nsIEnumerator enumerateCLSIDs (); */
|
||||
public void enumerateCLSIDs(nsIEnumerator[] _retval);
|
||||
|
||||
/* nsIEnumerator enumerateContractIDs (); */
|
||||
public void enumerateContractIDs(nsIEnumerator[] _retval);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* end
|
||||
*/
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* ************* DO NOT EDIT THIS FILE ***********
|
||||
*
|
||||
* This file was automatically generated from nsIEnumerator.idl.
|
||||
*/
|
||||
|
||||
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
|
||||
/**
|
||||
* Interface nsIEnumerator
|
||||
*
|
||||
* IID: 0xad385286-cbc4-11d2-8cca-0060b0fc14a3
|
||||
*/
|
||||
|
||||
public interface nsIEnumerator extends nsISupports
|
||||
{
|
||||
public static final String IID =
|
||||
"ad385286-cbc4-11d2-8cca-0060b0fc14a3";
|
||||
|
||||
|
||||
/* void first (); */
|
||||
public void first();
|
||||
|
||||
/* void next (); */
|
||||
public void next();
|
||||
|
||||
/* nsISupports currentItem (); */
|
||||
public void currentItem(nsISupports[] _retval);
|
||||
|
||||
/* void isDone (); */
|
||||
public void isDone();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* end
|
||||
*/
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* ************* DO NOT EDIT THIS FILE ***********
|
||||
*
|
||||
* This file was automatically generated from nsIFactory.idl.
|
||||
*/
|
||||
|
||||
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
|
||||
/**
|
||||
* Interface nsIFactory
|
||||
*
|
||||
* IID: 0x00000001-0000-0000-c000-000000000046
|
||||
*/
|
||||
|
||||
public interface nsIFactory extends nsISupports
|
||||
{
|
||||
public static final String IID =
|
||||
"00000001-0000-0000-c000-000000000046";
|
||||
|
||||
|
||||
/* void createInstance (in nsISupports aOuter, in nsIIDRef iid, [iid_is (iid), retval] out nsQIResult result); */
|
||||
public void createInstance(nsISupports aOuter, IID iid, Object[] result);
|
||||
|
||||
/* void lockFactory (in PRBool lock); */
|
||||
public void lockFactory(boolean lock);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* end
|
||||
*/
|
||||
@@ -21,7 +21,7 @@ public interface nsISupports
|
||||
|
||||
|
||||
/* void QueryInterface (in nsIIDRef uuid, [iid_is (uuid), retval] out nsQIResult result); */
|
||||
public void queryInterface(IID uuid, Object[] obj);
|
||||
public void queryInterface(IID uuid, Object[] result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* ************* DO NOT EDIT THIS FILE ***********
|
||||
*
|
||||
* This file was automatically generated from nsISupportsString.idl.
|
||||
*/
|
||||
|
||||
|
||||
package org.mozilla.xpcom;
|
||||
|
||||
|
||||
/**
|
||||
* Interface nsISupportsString
|
||||
*
|
||||
* IID: 0xd65ff270-4a1c-11d3-9890-006008962422
|
||||
*/
|
||||
|
||||
public interface nsISupportsString extends nsISupports
|
||||
{
|
||||
public static final String IID =
|
||||
"d65ff270-4a1c-11d3-9890-006008962422";
|
||||
|
||||
|
||||
/* string toString (); */
|
||||
public void toString(String[] _retval);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* end
|
||||
*/
|
||||
Reference in New Issue
Block a user