Index: trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl.h
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl.h	(revision 28992)
+++ trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl.h	(revision 29118)
@@ -15,5 +15,5 @@
  * The Original Code is mozilla.org code.
  *
- * The Initial Developer of the Original Code is 
+ * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
@@ -23,5 +23,5 @@
  *
  * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or 
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
@@ -108,5 +108,5 @@
 /* Function that produces a struct of output-generation functions */
 typedef backend *(*backendFactory)();
- 
+
 extern backend *xpidl_header_dispatch(void);
 extern backend *xpidl_typelib_dispatch(void);
@@ -135,4 +135,8 @@
     nodeHandler      *dispatch;
     void             *priv;     /* mode-private data */
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    char             *real_outname;
+#endif
+
 };
 
@@ -257,5 +261,5 @@
 /*
  * Verifies the interface declaration
- */ 
+ */
 gboolean
 verify_interface_declaration(IDL_tree method_tree);
Index: trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl_idl.c
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl_idl.c	(revision 28992)
+++ trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl_idl.c	(revision 29118)
@@ -15,5 +15,5 @@
  * The Original Code is mozilla.org code.
  *
- * The Initial Developer of the Original Code is 
+ * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
@@ -24,5 +24,5 @@
  *
  * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or 
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
@@ -117,5 +117,5 @@
  */
 typedef struct input_callback_state {
-    struct input_data *input_stack; /* linked list of input_data */   
+    struct input_data *input_stack; /* linked list of input_data */
     GHashTable *already_included;   /* to prevent redundant includes */
     IncludePathEntry *include_path; /* search path for included files */
@@ -266,7 +266,7 @@
     if (!(data->point[0] == '%' && data->point[1] == '{'))
         return 0;
-        
+
     start = *startp = data->point;
-    
+
     end = NULL;
     while (start < data->max && (end = strstr(start, "%}"))) {
@@ -305,5 +305,5 @@
         int skippedLines = 0;
         char *tempPoint;
-        
+
         /* get current lineno */
         IDL_file_get(NULL,(int *)&data->lineno);
@@ -317,5 +317,5 @@
         data->lineno += skippedLines;
         IDL_file_set(data->filename, (int)data->lineno);
-        
+
         *startp = end + 2;
 
@@ -355,5 +355,5 @@
         return 0;
     }
-    
+
     filename = data->point + 10; /* skip #include " */
     XPT_ASSERT(filename < data->max);
@@ -379,5 +379,5 @@
         }
         *end = '\0';
-        
+
         /* make sure we have accurate line info */
         IDL_file_get(&scratch, (int *)&data->lineno);
@@ -400,5 +400,5 @@
          */
         char *filename_cp = xpidl_strdup(filename);
-        
+
         /* note that g_slist_append accepts and likes null as list-start. */
         callback_state->base_includes =
@@ -436,5 +436,5 @@
     *lenp = 0;               /* this is magic, see the comment below */
     return 1;
-}    
+}
 
 static void
@@ -454,5 +454,5 @@
                                  (point > data->point &&                     \
                                   (point[-1] == '\r' || point[-1] == '\n')))
-                                                 
+
     while (point < data->max) {
         if (point[0] == '/' && point[1] == '*')
@@ -536,5 +536,5 @@
             IDL_inhibit_pop();
         }
-        
+
         /*
          * Now we scan for sequences which require special attention:
@@ -542,10 +542,10 @@
          *   \n%{                         begins a raw-source block
          *   /\*                          begins a comment
-         * 
+         *
          * We used to be fancier here, so make sure that we sent the most
          * data possible at any given time.  To that end, we skipped over
          * \n%{ raw \n%} blocks and then _continued_ the search for special
          * sequences like \n#include or /\* comments .
-         * 
+         *
          * It was really ugly, though -- liberal use of goto!  lots of implicit
          * state!  what fun! -- so now we just do this:
@@ -739,5 +739,5 @@
             real_outname = g_strdup(outname);
         } else {
-/* 
+/*
  *This combination seems a little strange, what about OS/2?
  * Assume it's some build issue
@@ -766,4 +766,7 @@
     }
     state.tree = top;
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    state.real_outname = real_outname;
+#endif
 
     if (emitter->emit_prolog)
Index: trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl_java.c
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl_java.c	(revision 28992)
+++ trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl_java.c	(revision 29118)
@@ -13,10 +13,10 @@
  * The Original Code is mozilla.org code.
  *
- * The Initial Developer of the Original Code is Sun Microsystems, 
+ * 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): 
+ * Contributor(s):
  *    Michael Allen (michael.allen@sun.com)
  *    Frank Mitchell (frank.mitchell@sun.com)
@@ -61,4 +61,9 @@
 java_prolog(TreeState *state)
 {
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    const char *basename;
+    const char *ext;
+#endif
+
     state->priv = calloc(1, sizeof(struct java_priv_data));
     if (!state->priv)
@@ -71,22 +76,40 @@
         return FALSE;
     }
-    
+
     /*
      * First pass
      */
-    
+
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    basename = xpidl_basename(state->real_outname ? state->real_outname : state->basename);
+    ext = strrchr(basename, '.');
+    if (!ext)
+        ext = strchr(basename, '\0');
+    fprintf(state->file,
+            "/**\n"
+            " * NOTE: THIS IS A GENERATED FILE. PLEASE CONSULT THE ORIGINAL IDL FILE\n"
+            " * FOR THE FULL DOCUMENTION AND LICENSE.\n"
+            " *\n"
+            " * @see <a href=\"http://lxr.mozilla.org/mozilla/search?string=interface+%.*s\">\n"
+            " **/\n"
+            "\n"
+            "package org.mozilla.interfaces;\n"
+            "\n"
+            , ext - basename >= 19 ? 19 : (int)(ext - basename), basename);
+#else
     fputs("/*\n * ************* DO NOT EDIT THIS FILE ***********\n",
           state->file);
-    
-    fprintf(state->file, 
-            " *\n * This file was automatically generated from %s.idl.\n", 
+
+    fprintf(state->file,
+            " *\n * This file was automatically generated from %s.idl.\n",
             state->basename);
-    
+
     fputs(" */\n\n", state->file);
-	
-    return TRUE;
-}
-
-static gboolean 
+#endif
+
+    return TRUE;
+}
+
+static gboolean
 java_epilog(TreeState *state)
 {
@@ -95,19 +118,21 @@
     free(state->priv);
     state->priv = NULL;
-    
+
+#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
     /*
      * Last pass
      */
-    
+
     fprintf(state->file, "\n/*\n * end\n */\n");
-
-    return TRUE;
-}
-
-static gboolean
-forward_declaration(TreeState *state) 
-{
-    /*
-     * Java doesn't need forward declarations unless the declared 
+#endif
+
+    return TRUE;
+}
+
+static gboolean
+forward_declaration(TreeState *state)
+{
+    /*
+     * Java doesn't need forward declarations unless the declared
      * class resides in a different package.
      */
@@ -126,5 +151,5 @@
 
 static gboolean
-interface_declaration(TreeState *state) 
+interface_declaration(TreeState *state)
 {
     IDL_tree interface = state->tree;
@@ -135,4 +160,5 @@
     if (!verify_interface_declaration(interface))
         return FALSE;
+#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
     /*
      * Write out JavaDoc comment
@@ -140,4 +166,5 @@
 
     fprintf(state->file, "\n/**\n * Interface %s\n", interface_name);
+#endif
 
 #ifndef LIBIDL_MAJOR_VERSION
@@ -147,4 +174,5 @@
 #endif
 
+#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
     if (iid != NULL) {
         fprintf(state->file, " *\n * IID: 0x%s\n */\n\n", iid);
@@ -152,5 +180,5 @@
         fputs(" */\n\n", state->file);
     }
-
+#endif
 
     /*
@@ -170,7 +198,7 @@
         do {
 
-            fprintf(state->file, "%s", 
+            fprintf(state->file, "%s",
                     IDL_IDENT(IDL_LIST(iterator).data).str);
-	    
+
             if (IDL_LIST(iterator).next) {
                 fputs(", ", state->file);
@@ -181,5 +209,5 @@
 
     fputs("\n{\n", state->file);
-    
+
     if (iid) {
         /*
@@ -187,5 +215,9 @@
          */
 
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+        fputs("  public static final String ", state->file);
+#else
         fputs("    public static final String ", state->file);
+#endif
 
         /* XXX s.b just "IID" ? */
@@ -194,4 +226,8 @@
         }
 
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+        fprintf(state->file, " =\n    \"{%s}\";\n", iid);
+
+#else
         fprintf(state->file, "_STRING =\n        \"%s\";\n\n", iid);
 
@@ -204,4 +240,5 @@
 
         fprintf(state->file, " =\n        new nsID(\"%s\");\n\n", iid);
+#endif
     }
 
@@ -209,5 +246,5 @@
      * Advance the state of the tree, go on to process more
      */
-    
+
     state->tree = IDL_INTERFACE(interface).body;
 
@@ -225,4 +262,40 @@
 process_list(TreeState *state)
 {
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    /* To make the diffing simple, group the constants, methods and attributes. */
+    IDL_tree list = state->tree;
+    IDL_tree iter;
+    for (iter = list; iter; iter = IDL_LIST(iter).next) {
+        if (IDL_NODE_TYPE(IDL_LIST(iter).data) == IDLN_CONST_DCL) {
+            state->tree = IDL_LIST(iter).data;
+            if (!xpidl_process_node(state))
+                return FALSE;
+        }
+    }
+    for (iter = list; iter; iter = IDL_LIST(iter).next) {
+        if (IDL_NODE_TYPE(IDL_LIST(iter).data) == IDLN_ATTR_DCL) {
+            state->tree = IDL_LIST(iter).data;
+            if (!xpidl_process_node(state))
+                return FALSE;
+        }
+    }
+    for (iter = list; iter; iter = IDL_LIST(iter).next) {
+        if (IDL_NODE_TYPE(IDL_LIST(iter).data) == IDLN_OP_DCL) {
+            state->tree = IDL_LIST(iter).data;
+            if (!xpidl_process_node(state))
+                return FALSE;
+        }
+    }
+    for (iter = list; iter; iter = IDL_LIST(iter).next) {
+        if (   IDL_NODE_TYPE(IDL_LIST(iter).data) != IDLN_CONST_DCL
+            && IDL_NODE_TYPE(IDL_LIST(iter).data) != IDLN_OP_DCL
+            && IDL_NODE_TYPE(IDL_LIST(iter).data) != IDLN_ATTR_DCL ) {
+            state->tree = IDL_LIST(iter).data;
+            if (!xpidl_process_node(state))
+                return FALSE;
+        }
+    }
+
+#else
     IDL_tree iter;
     for (iter = state->tree; iter; iter = IDL_LIST(iter).next) {
@@ -231,9 +304,71 @@
             return FALSE;
     }
-    return TRUE;
-}
-
-static gboolean 
-xpcom_to_java_type (TreeState *state) 
+#endif
+    return TRUE;
+}
+
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+static gboolean
+interface_declaration_wrapper(TreeState *state)
+{
+    IDL_tree interface = state->tree;
+    char *interface_name = IDL_IDENT(IDL_INTERFACE(interface).ident).str;
+    FILE *org_file = state->file;
+    char *org_name = state->real_outname;
+    void *org_priv = state->priv;
+    gboolean rc;
+
+    /*
+     * Skip non-scriptable interfaces.
+     */
+    if (   !IDL_tree_property_get(IDL_INTERFACE(interface).ident, "scriptable")
+         && strcmp(interface_name, "nsIAppShell") )
+        return TRUE;
+
+    /*
+     * GROSS HACK: If the interface isn't the same as the file name,
+     *             temporarily switch output file.
+     */
+    if (state->real_outname) {
+        const char *basename = xpidl_basename(state->real_outname);
+        const char *ext      = strrchr(basename, '.');
+        if (   ext
+            && !strcmp(ext, ".java")
+            && (   strncmp(interface_name, basename, ext - basename)
+                || interface_name[ext - basename] != '.') ) {
+            size_t needed = strlen(state->real_outname) + strlen(interface_name) + strlen(".java") + 4;
+            char  *tmp = malloc(needed);
+            if (basename != state->real_outname)
+                sprintf(tmp,"%.*s/%s.java", (int)(basename - state->real_outname - 1), state->real_outname, interface_name);
+            else
+                sprintf(tmp,"%s.java", interface_name);
+            state->file = fopen(tmp, "w");
+            if (!state->file) {
+                perror("error opening output file");
+                state->file = org_file;
+                free(tmp);
+                return FALSE;
+            }
+            state->real_outname = tmp;
+            java_prolog(state);
+        }
+    }
+
+    rc = interface_declaration(state);
+
+    if (state->file != org_file) {
+        java_epilog(state);
+        fclose(state->file);
+        free(state->real_outname);
+        state->file = org_file;
+        state->real_outname = org_name;
+        state->priv = org_priv;
+    }
+    return rc;
+}
+#endif /* VBOX_XPIDL_EMULATE_GENJIFACES */
+
+static gboolean
+xpcom_to_java_type (TreeState *state)
 {
     if (!state->tree) {
@@ -249,15 +384,36 @@
 
         case IDL_INTEGER_TYPE_SHORT:
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+            if (IDL_TYPE_INTEGER(state->tree).f_signed)
+                fputs("short", state->file);
+            else
+                fputs("int", state->file);
+#else
             fputs("short", state->file);
+#endif
             break;
 
         case IDL_INTEGER_TYPE_LONG:
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+            if (IDL_TYPE_INTEGER(state->tree).f_signed)
+                fputs("int", state->file);
+            else
+                fputs("long", state->file);
+#else
             fputs("int", state->file);
+#endif
             break;
 
         case IDL_INTEGER_TYPE_LONGLONG:
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+            if (IDL_TYPE_INTEGER(state->tree).f_signed)
+                fputs("long", state->file);
+            else
+                fputs("double", state->file);
+#else
             fputs("long", state->file);
+#endif
             break;
-	    
+
         default:
             g_error("   Unknown integer type: %d\n",
@@ -285,5 +441,9 @@
 
     case IDLN_TYPE_OCTET:
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+        fputs("short", state->file);
+#else
         fputs("byte", state->file);
+#endif
         break;
 
@@ -298,5 +458,5 @@
             fputs("double", state->file);
             break;
-	    
+
         default:
             g_error("    Unknown floating point typ: %d\n",
@@ -312,5 +472,9 @@
             const char *user_type = IDL_NATIVE(IDL_NODE_UP(state->tree)).user_type;
             if (strcmp(user_type, "void") == 0) {
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+                fputs("nsISupports", state->file);
+#else
                 fputs("Object", state->file);
+#endif
             }
             else if (strcmp(user_type, "nsID") == 0 ||
@@ -319,9 +483,17 @@
                 /* XXX: s.b test for "iid" attribute */
                 /* XXX: special class for nsIDs */
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+                fputs("String", state->file);
+#else
                 fputs("nsID", state->file);
+#endif
             }
             else {
                 /* XXX: special class for opaque types */
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+                fputs("String", state->file);
+#else
                 fputs("OpaqueValue", state->file);
+#endif
             }
         } else {
@@ -329,4 +501,27 @@
 
             /* XXX: big kludge; s.b. way to match to typedefs */
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+            if (strcmp(ident_str, "PRInt8") == 0) {
+                fputs("byte", state->file);
+            }
+            else if (strcmp(ident_str, "PRInt16") == 0 ||
+                     strcmp(ident_str, "PRUint8") == 0) {
+                fputs("short", state->file);
+            }
+            else if (strcmp(ident_str, "PRInt32") == 0 ||
+                     strcmp(ident_str, "PRUint16") == 0) {
+                fputs("int", state->file);
+            }
+            else if (strcmp(ident_str, "PRInt64") == 0 ||
+                     strcmp(ident_str, "PRUint32") == 0 ||
+                     strcmp(ident_str, "PRThreadPriority") == 0 ||
+                     strcmp(ident_str, "PRThreadScope")    == 0 ||
+                     strcmp(ident_str, "PRThreadState")    == 0) {
+                fputs("long", state->file);
+            }
+            else if (strcmp(ident_str, "PRUint64") == 0) {
+                fputs("double", state->file);
+            }
+#else
             if (strcmp(ident_str, "PRInt8") == 0 ||
                 strcmp(ident_str, "PRUint8") == 0) {
@@ -345,4 +540,5 @@
                 fputs("long", state->file);
             }
+#endif
             else if (strcmp(ident_str, "PRBool") == 0) {
                 fputs("boolean", state->file);
@@ -351,6 +547,21 @@
                 fputs("int", state->file);
             }
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+            /* XXX: Use find_underlying_type instead? */
+            else if (   strcmp(ident_str, "nsresult") == 0
+                     || strcmp(ident_str, "size_t") == 0) {
+                fputs("long", state->file);
+            }
+            else if (   strcmp(ident_str, "PRTime") == 0) {
+                fputs("double", state->file);
+            }
+            /* In Javaconnect, we handle weak references internally; no need for the
+              |nsIWeakReference| interface.  So just return |nsISupports|. */
+            else if (strcmp(ident_str, "nsIWeakReference") == 0) {
+                fputs("nsISupports", state->file);
+            }
+#endif
             else {
-                IDL_tree real_type = 
+                IDL_tree real_type =
                     g_hash_table_lookup(TYPEDEFS(state), ident_str);
 
@@ -384,5 +595,9 @@
 
 static gboolean
-xpcom_to_java_param(TreeState *state) 
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+xpcom_to_java_param(TreeState *state, unsigned nparam)
+#else
+xpcom_to_java_param(TreeState *state)
+#endif
 {
     IDL_tree param = state->tree;
@@ -402,22 +617,63 @@
      */
 
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    /* XXX: Causes nsILineInputStream::readLine(String[] arg1) where genjifaces drops the []. */
+#endif
     if (IDL_PARAM_DCL(param).attr != IDL_PARAM_IN) {
         fputs("[]", state->file);
     }
-
-    /*
-     * Put in name of parameter 
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    /*XXX: nsIConsoleService::getMessageArray ends up with [][] arg1... */
+    /*else*/ if (IDL_tree_property_get(IDL_PARAM_DCL(param).simple_declarator, "array")) {
+        fputs("[]", state->file);
+    }
+#endif
+
+    /*
+     * Put in name of parameter
      */
 
     fputc(' ', state->file);
 
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    fprintf(state->file, "arg%u", nparam+1);
+#else
     fputs(IDL_IDENT(IDL_PARAM_DCL(param).simple_declarator).str, state->file);
-
-    return TRUE;
-}
-
-
-static gboolean
-type_declaration(TreeState *state) 
+#endif
+
+    return TRUE;
+}
+
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+static gboolean is_java_keyword(char ch0, const char *name)
+{
+    static const char * const kJavaKeywords[] = {
+        "abstract", "default", "if"        , "private"     , "this"     ,
+        "boolean" , "do"     , "implements", "protected"   , "throw"    ,
+        "break"   , "double" , "import",     "public"      , "throws"   ,
+        "byte"    , "else"   , "instanceof", "return"      , "transient",
+        "case"    , "extends", "int"       , "short"       , "try"      ,
+        "catch"   , "final"  , "interface" , "static"      , "void"     ,
+        "char"    , "finally", "long"      , "strictfp"    , "volatile" ,
+        "class"   , "float"  , "native"    , "super"       , "while"    ,
+        "const"   , "for"    , "new"       , "switch"      ,
+        "continue", "goto"   , "package"   , "synchronized",
+        "assert"  ,  /* added in Java 1.4 */
+        "enum"    ,  /* added in Java 5.0 */
+        "clone"   ,  /* clone is a member function of java.lang.Object */
+        "finalize"   /* finalize is a member function of java.lang.Object */
+    };
+    unsigned i;
+    for (i = 0; i < sizeof(kJavaKeywords) / sizeof(kJavaKeywords[0]); i++) {
+        if (kJavaKeywords[i][0] == ch0 && !strcmp(&kJavaKeywords[i][1], &name[1])) {
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
+#endif
+
+static gboolean
+type_declaration(TreeState *state)
 {
     /*
@@ -439,26 +695,44 @@
 
 static gboolean
-method_declaration(TreeState *state) 
+method_declaration(TreeState *state)
 {
     /* IDL_tree method_tree = state->tree; */
     struct _IDL_OP_DCL *method = &IDL_OP_DCL(state->tree);
-    gboolean method_notxpcom = 
+    gboolean method_notxpcom =
         (IDL_tree_property_get(method->ident, "notxpcom") != NULL);
-    gboolean method_noscript = 
+    gboolean method_noscript =
         (IDL_tree_property_get(method->ident, "noscript") != NULL);
     IDL_tree iterator = NULL;
     IDL_tree retval_param = NULL;
     const char *method_name = IDL_IDENT(method->ident).str;
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    unsigned nparam = 0;
+#endif
 
     if (!verify_method_declaration(state->tree))
         return FALSE;
 
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    /*
+     * Skip most (todo) non-scriptable and not-xpcom methods.
+     */
+    if (method_noscript || method_notxpcom) {
+        return TRUE;
+    }
+#endif
+
     fputc('\n', state->file);
+#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
     xpidl_write_comment(state, 4);
+#endif
 
     /*
      * Write beginning of method declaration
      */
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    fputs("  ", state->file);
+#else
     fputs("    ", state->file);
+#endif
     if (!method_noscript) {
         /* Nonscriptable methods become package-protected */
@@ -468,5 +742,5 @@
     /*
      * Write return type
-     * Unlike C++ headers, Java interfaces return the declared 
+     * Unlike C++ headers, Java interfaces return the declared
      * return value; an exception indicates XPCOM method failure.
      */
@@ -478,5 +752,5 @@
     } else {
         /* Check for retval attribute */
-        for (iterator = method->parameter_dcls; iterator != NULL; 
+        for (iterator = method->parameter_dcls; iterator != NULL;
              iterator = IDL_LIST(iterator).next) {
 
@@ -485,5 +759,5 @@
             state->tree = IDL_LIST(iterator).data;
 
-            if (IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator, 
+            if (IDL_tree_property_get(IDL_PARAM_DCL(state->tree).simple_declarator,
                                       "retval")) {
                 retval_param = iterator;
@@ -498,4 +772,9 @@
                     return FALSE;
                 }
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+                if (IDL_tree_property_get(IDL_PARAM_DCL(IDL_LIST(iterator).data).simple_declarator, "array")) {
+                    fputs("[]", state->file);
+                }
+#endif
             }
 
@@ -507,14 +786,22 @@
         }
     }
- 
+
     /*
      * Write method name
      */
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    if (is_java_keyword(tolower(method_name[0]), method_name)) {
+        fprintf(state->file, " %c%s_(", tolower(method_name[0]), method_name + 1);
+    } else {
+        fprintf(state->file, " %c%s(", tolower(method_name[0]), method_name + 1);
+    }
+#else
     fprintf(state->file, " %c%s(", tolower(method_name[0]), method_name + 1);
+#endif
 
     /*
      * Write parameters
      */
-    for (iterator = method->parameter_dcls; iterator != NULL; 
+    for (iterator = method->parameter_dcls; iterator != NULL;
          iterator = IDL_LIST(iterator).next) {
 
@@ -527,8 +814,12 @@
             fputs(", ", state->file);
         }
-        
+
         state->tree = IDL_LIST(iterator).data;
 
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+        if (!xpcom_to_java_param(state, nparam++)) {
+#else
         if (!xpcom_to_java_param(state)) {
+#endif
             return FALSE;
         }
@@ -555,5 +846,5 @@
 
     return TRUE;
-    
+
 }
 
@@ -565,4 +856,7 @@
     const char *name = IDL_IDENT(declaration->ident).str;
     IDL_tree real_type;
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    IDL_tree saved_tree;
+#endif
 
     if (!verify_const_declaration(state->tree))
@@ -574,10 +868,55 @@
 
     fputc('\n', state->file);
+#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
     xpidl_write_comment(state, 4);
-
+#endif
+
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+/* XXX: We get the WRONG signedness of stuff here. PRInt32 -> unsigned long and stuff like that. */
+    fputs("  public static final ", state->file);
+    switch(IDL_NODE_TYPE(real_type)) {
+
+    case IDLN_TYPE_INTEGER: {
+        switch(IDL_TYPE_INTEGER(real_type).f_type) {
+
+        case IDL_INTEGER_TYPE_SHORT:
+            if (IDL_TYPE_INTEGER(real_type).f_signed)
+                fprintf(state->file, "int %s = %d;\n", name, (int)IDL_INTEGER(declaration->const_exp).value);
+            else
+                fprintf(state->file, "int %s = %u;\n", name, (unsigned)IDL_INTEGER(declaration->const_exp).value);
+            break;
+
+        case IDL_INTEGER_TYPE_LONG:
+            if (IDL_TYPE_INTEGER(state->tree).f_signed)
+                fprintf(state->file, "int %s = %d;\n", name, (int)IDL_INTEGER(declaration->const_exp).value);
+            else
+                fprintf(state->file, "long %s = %uL;\n", name, (unsigned)IDL_INTEGER(declaration->const_exp).value);
+            break;
+
+        case IDL_INTEGER_TYPE_LONGLONG:
+            if (IDL_TYPE_INTEGER(state->tree).f_signed)
+                fprintf(state->file, "long %lldL;\n", name, (long long)IDL_INTEGER(declaration->const_exp).value);
+            else
+                fprintf(state->file, "double %lluL;\n", name, (unsigned long long)IDL_INTEGER(declaration->const_exp).value);
+            break;
+
+        default:
+            g_error("   Unknown integer type: %d\n",
+                    IDL_TYPE_INTEGER(state->tree).f_type);
+            return FALSE;
+
+        }
+        break;
+    }
+    default:
+        g_error("   Unknown constant type: %d\n", IDL_NODE_TYPE(real_type));
+        return FALSE;
+    }
+#else
     fprintf(state->file, "    public static final %s %s = %d;\n",
             (IDL_TYPE_INTEGER(real_type).f_type == IDL_INTEGER_TYPE_LONG
              ? "long" : "short"),
             name, (int) IDL_INTEGER(declaration->const_exp).value);
+#endif
 
     return TRUE;
@@ -596,6 +935,15 @@
     char *attribute_name = ATTR_IDENT(state->tree).str;
 
-    gboolean method_noscript = 
+    gboolean method_noscript =
         (IDL_tree_property_get(ATTR_PROPS(state->tree), "noscript") != NULL);
+
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    /*
+     * Skip most non-scriptable attributes.
+     */
+    if (method_noscript) {
+        return TRUE;
+    }
+#endif
 
 #if 0
@@ -610,5 +958,7 @@
     /* Comment */
     fputc('\n', state->file);
+#ifndef VBOX_XPIDL_EMULATE_GENJIFACES
     xpidl_write_comment(state, 4);
+#endif
 
     state->tree = ATTR_TYPE_DECL(state->tree);
@@ -617,5 +967,9 @@
      * Write access permission ("public" unless nonscriptable)
      */
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+    fputs("  ", state->file);
+#else
     fputs("    ", state->file);
+#endif
     if (!method_noscript) {
         fputs("public ", state->file);
@@ -628,5 +982,5 @@
         return FALSE;
     }
-    
+
     /*
      * Write the name of the accessor ("get") method.
@@ -638,5 +992,9 @@
     if (!read_only) {
         /* Nonscriptable methods become package-protected */
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+        fputs("\n  ", state->file);
+#else
         fputs("    ", state->file);
+#endif
         if (!method_noscript) {
             fputs("public ", state->file);
@@ -647,7 +1005,7 @@
          */
         fprintf(state->file, "void set%c%s(",
-                toupper(attribute_name[0]), 
+                toupper(attribute_name[0]),
                 attribute_name+1);
-        
+
         /*
          * Write the proper Java type for the set operation
@@ -660,5 +1018,9 @@
          * Write the name of the formal parameter.
          */
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+        fputs(" arg1);\n", state->file);
+#else
         fputs(" value);\n", state->file);
+#endif
     }
 
@@ -687,5 +1049,9 @@
 
     if (!initialized) {
+#ifdef VBOX_XPIDL_EMULATE_GENJIFACES
+        table[IDLN_INTERFACE] = interface_declaration_wrapper;
+#else
         table[IDLN_INTERFACE] = interface_declaration;
+#endif
         table[IDLN_LIST] = process_list;
 
@@ -705,2 +1071,3 @@
     return &result;
 }
+
