![]() |
XPIDL Binding to JavaDRAFT: 23 July 1999Note: This document is not a formal specification, but notes on a work in progress. Feedback is encouraged. OverviewTo use XPCOM interfaces from Java, we must have a consistent mapping that meets the following design goals:
The following mapping is not the only one possible, and because of the mismatches between Java and XPCOM no mapping can be perfect. The author believes, however, that this mapping makes the best compromises for the sake of usability and simplicity. InterfacesEach XPCOM interface corresponds to a public Java interface of the same name. In addition to the constants defined in the interface, each Java interface also has two additional public static final fields: INTERFACENAME_IID, of type org.mozilla.xpcom.nsID, containing the interface's IID, and INTERFACENAME_IID_STRING, a java.lang.String containing the IID's string value. For backwards-compatibility, names beginning with "ns" will become NS_INTERFACENAME_IID{_STRING}, e.g. nsISupports has an IID field called NS_ISUPPORTS_IID. Namespaces
By default, all XPCOM interfaces reside in the Java package
A "namespace" attribute on the interface places the interface in the package named by the attribute's value. TypesEach XPIDL/XPCOM type maps to a Java type. Basic types -- integers, floating-point numbers, booleans and characters -- map to the corresponding Java "primitive" type. If a parameter's or attribute's type declaration has a "ref" or "ptr" attribute, the mapping uses the listed "reference" type. Strings, interfaces, and nsIDs always use a reference type. and other complex types always use a reference type. In some cases, no Java type corresponds exactly to the XPIDL type; conversions between the XPIDL and Java values are noted.
TypedefsBecause Java has no corresponding "typedef" declaration, the Java type for a defined type is the "expanded" type from unravelling that and all intermediate typedefs. Forward ReferencesJava does not require forward references per se. If the interface resides in a different namespace from the interface being generated, the generated Java interface will include an appropriate import statement; otherwise, the import will be omitted. A "namespace" attribute on a forward reference tells the XPIDL compiler which package the named interface belongs in, should the compiler not be able to discover that information itself. For more information, see Namespaces, above. ConstantsEach constant defined within the interface corresponds to a public static final field of the same name, of the Java type corresponding to the XPIDL type, according to the mapping above. MethodsEach method defined within the interface corresponds to a public method the same name. The signature and Java types of the methods conform to patterns summarized in the table below.
Error CodesInstead of explicitly returning an "nsresult" as the C++ binding does, Java XPCOM methods throw an org.mozilla.xpcom.XPCOMException when the nsresult is negative (or greater than 0x80000000). XPCOMException is a RuntimeException, so it is not declared in the method's throws clause.
Success CodesAny nsresults greater than 0 (but less than 0x80000000) are available by calling {method in class TBD}. This value is stored per thread, so it must be used before calling another XPCOM method. Out Parameters and Return ValuesThe method's return value, or its out parameter marked with the "retval" attribute, becomes the return value of the corresponding Java method. Other out or inout parameters become arguments of the array type corresponding to the XPIDL's parameter type. For example, an "out double" becomes an argument of Java type "double[]". Callers pass in an array of at least one element, which the method would fill with its value.
Attributes
Each attribute corresponds to a pair of methods of the form
Support Classes and Interfaces
class org.mozilla.xpcom.XPCOMExceptionTBD class org.mozilla.xpcom.nsIDTBD interface org.mozilla.xpcom.nsISupportsTBD interface org.mozilla.xpcom.nsIComponentManagerTBD interface org.mozilla.xpcom.nsIServiceManagerTBD class namespace.InterfaceName__ProxyTBD Frank Mitchell Last modified: Thu Jul 22 15:34:49 PDT 1999 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Copyright © 1998-1999 The Mozilla Organization. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||