Accessing arbitrary XPCOM interfaces using JavaXPCOM
edburns <[email protected]> Thu, 01 Nov 2007 11:00:46 -0700
| Newsgroups | gmane.comp.mozilla.devel.java |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <1193940046.738699.183610__25108.507826417$1193940380$gmane$org@y42g2000hsy.googlegroups.com> |
Hello, I'm using a XULRunner I built from source pulled with cvs tag
FIREFOX_2_0_0_3_RELEASE. I'm trying to use firebug from my embedding
app using Java XPCOM. I have verified that I can successfully access
the nsIFireBug service from native code by verifying that rv == 0 in
the
following:
C++ Example:
01. nsCOMPtr<nsIFireBug> fireBug = do_GetService("@joehewitt.com/
firebug;1",
02. &rv);
03. if (NS_FAILED(rv)) {
04. ::util_ThrowExceptionToJava(env, "Failed to get FireBug
Service");
05. }
I used xpidl -m java to produce java interfaces from the
nsIFireBug.idl
file, and compiled these interfaces into MozillaInterfaces.jar, like
this:
jar -tf MozillaInterfaces.jar | grep FireBug
org/mozilla/interfaces/nsIFireBug.class
org/mozilla/interfaces/nsIFireBugBreakpointCallback.class
org/mozilla/interfaces/nsIFireBugClient.class
org/mozilla/interfaces/nsIFireBugDebugger.class
I put this MozillaInterfaces.jar and javaxpcom.jar on my app
classpath.
However, when I do the following from my Java code:
Java Example:
01. org.mozilla.xpcom.Mozilla mozilla =
org.mozilla.xpcom.Mozilla.getInstance();
02. mozilla.initialize(new File("F:\Projects\mozilla\MOZILLA_NIH
\FIREFOX_2_0_0_3_RELEASE\mozilla\xulrunner-win32_d.obj\dist\bin"));
03. nsIServiceManager srvMan = mozilla.getServiceManager();
04. nsIObserverService observerService =
05. (nsIObserverService)
srvMan.getServiceByContractID("@mozilla.org/observer-service;1",
06. "d07f5192-e3d1-11d2-8acd-00105a1b8860");
07. nsIFireBug firebug = (nsIFireBug)
08. srvMan.getServiceByContractID("@joehewitt.com/firebug;1",
"f71f61b2-cb37-11da-9b41-b622a1ef5492");
When line 08 executes, I get this exception.
Exception in thread "foo" org.mozilla.xpcom.XPCOMException: The
function "getServiceByContractID" returned an error condition
(0x8000ffff)
at
org.mozilla.xpcom.internal.XPCOMJavaProxy.callXPCOMMethod(Native
Method)
at
org.mozilla.xpcom.internal.XPCOMJavaProxy.invoke(XPCOMJavaProxy.java:
143)
at $Proxy0.getServiceByContractID(Unknown Source)
at org.mozilla.webclient.impl.wrapper_native.WrapperFactoryImpl
$3.run(WrapperFactoryImpl.java:390)
at
org.mozilla.webclient.impl.wrapper_native.NativeEventThread.run(NativeEventThread.java:
162)
Considering that the C++ Example works, but the Java Example does not,
I
must be missing something fundamental.
Can anyone shed light on this? Javier?
Ed