From fb123f93f9f5ce42c8e5785d2f8e0edaf951740e Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Wed, 26 Mar 2014 19:21:20 +0000 Subject: Imported from /home/lorry/working-area/delta_VirtualBox/VirtualBox-4.3.10.tar.bz2. --- src/VBox/Main/glue/glue-java.xsl | 3113 ++++++++++++++++++++++---------------- 1 file changed, 1794 insertions(+), 1319 deletions(-) (limited to 'src/VBox/Main/glue/glue-java.xsl') diff --git a/src/VBox/Main/glue/glue-java.xsl b/src/VBox/Main/glue/glue-java.xsl index 0bcc4398..a1f47fc8 100644 --- a/src/VBox/Main/glue/glue-java.xsl +++ b/src/VBox/Main/glue/glue-java.xsl @@ -1,8 +1,8 @@ + xmlns:xsl='http://www.w3.org/1999/XSL/Transform' + xmlns:vbox="http://www.virtualbox.org/" + xmlns:exsl="http://exslt.org/common" + extension-element-prefixes="exsl"> - - - - + + + + - + /* - * Copyright (C) 2010-2011 Oracle Corporation + * Copyright (C) 2010-2014 Oracle Corporation * - * This file is part of the VirtualBox SDK, as available from - * http://www.virtualbox.org. This library is free software; you can - * redistribute it and/or modify it under the terms of the GNU Lesser General - * Public License as published by the Free Software Foundation, in version 2.1 - * as it comes in the "COPYING.LIB" file of the VirtualBox SDK distribution. - * This library is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. + * This file is part of the VirtualBox SDK, as available from + * http://www.virtualbox.org. This library is free software; you can + * redistribute it and/or modify it under the terms of the GNU Lesser General + * Public License as published by the Free Software Foundation, in version 2.1 + * as it comes in the "COPYING.LIB" file of the VirtualBox SDK distribution. + * This library is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. * - + * * DO NOT EDIT! This is a generated file. @@ -75,39 +74,48 @@ - - - - + + + + + + - - + + - - - - + + + import org.mozilla.interfaces.*; + - - - - + + import com.jacob.com.*; + import com.jacob.activeX.ActiveXComponent; + - - - + + import javax.xml.ws.*; + + + + + + + + - - - + - - + + + + @@ -115,15 +123,23 @@ + - - + + - - - - - + + + + + + + + + + + + @@ -131,6 +147,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -160,18 +218,24 @@ - + + + + + + + - + - + @@ -214,14 +278,14 @@ - + {@link @@ -231,10 +295,15 @@ - + + + + + + - + @@ -254,13 +323,13 @@ - + - + # @@ -268,26 +337,26 @@ - + - + - + - + - + @@ -298,12 +367,12 @@ + Should be replaced in the xidl by multiple without nested tag --> @@ -317,18 +386,18 @@ - /** + /** - + @@ -337,7 +406,7 @@ @@ -347,10 +416,10 @@ <tr> - + - + <td> @@ -363,17 +432,15 @@ - + @@ -386,7 +453,7 @@ @@ -400,11 +467,11 @@ - */ + */ @@ -422,7 +489,7 @@ @@ -438,7 +505,7 @@ @@ -458,7 +525,7 @@ @@ -471,7 +538,7 @@ @@ -480,7 +547,7 @@ @@ -497,47 +564,55 @@ - - - - - - - - - , - - - ; - - - - - - private final int value; - - - value = v; - } - - public int value() { - return value; - } - - - - if (c.value == (int)v) { - return c; - } - } - throw new IllegalArgumentException(Long.toString(v)); - } - - - - + + + + { + + + + + + + , + + + ; + + + - } + + private final int value; + + + { + value = v; + } + + public int value() + { + return value; + } + + + { + + { + if (c.value == (int)v) + { + return c; + } + } + throw new IllegalArgumentException(Long.toString(v)); + } + + + { + + } + } + @@ -546,32 +621,39 @@ - - - + try + { - - - + } + catch (org.mozilla.xpcom.XPCOMException e) + { + throw new VBoxException(e.getMessage(), e); + } - - - + } + catch (com.jacob.com.ComException e) + { + throw new VBoxException(e.getMessage(), e); + } - - - - - + } + catch (InvalidObjectFaultMsg e) + { + throw new VBoxException(e.getMessage(), e, this.port); + } + catch (RuntimeFaultMsg e) + { + throw new VBoxException(e.getMessage(), e, this.port); + } @@ -587,15 +669,15 @@ - + - + com.jacob.com.Dispatch - + String @@ -611,19 +693,20 @@ - - - - - - - - + + + + + + + + + - - + + @@ -636,14 +719,14 @@ - + List - + < - + @@ -664,11 +747,11 @@ - + > - + [] @@ -687,43 +770,43 @@ - + long - + long - + int - + int - + short - + byte - + boolean - + nsISupports - + String - + String @@ -739,7 +822,7 @@ - + long @@ -750,27 +833,27 @@ - + [] - + Variant - + List< - + String - + String @@ -783,51 +866,51 @@ - + /*base64*/String - + Long - + Long - + Integer - + Integer - + Short - + Boolean - + String - + String - + - + > @@ -875,16 +958,16 @@ - + - + - + @@ -893,12 +976,12 @@ - + - + - + @@ -907,7 +990,7 @@ - + @@ -943,54 +1026,54 @@ - + - + - + - + - + - - + + - + - - + + - + - + - + - + @@ -1035,19 +1118,19 @@ - + - + - + - + - + @@ -1055,7 +1138,7 @@ - + @@ -1085,15 +1168,15 @@ - + - + - + @@ -1177,21 +1260,21 @@ - + - + - - + + - + - + @@ -1199,10 +1282,10 @@ - + - + @@ -1216,19 +1299,19 @@ - + - + - + - + - + @@ -1283,21 +1366,21 @@ - + - + - - + + - + - + @@ -1305,10 +1388,10 @@ - + - + @@ -1316,10 +1399,10 @@ - + - + @@ -1327,10 +1410,10 @@ - + - + @@ -1339,10 +1422,10 @@ - + - + @@ -1350,10 +1433,10 @@ - + - + @@ -1361,16 +1444,16 @@ - + - + - + @@ -1407,49 +1490,49 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1496,150 +1579,150 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + null + + + + + null, + + + + + + + + + + + + - - - - - + + + + + + + + + + + , + - + ); - + - + - + , - - - - - - - - - - - - - + + + + + + + + + + + + + - + ); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + obj + + + + + + + + + + + , + + + + + + + + + + + + + + + + + + + + + + + , + + + + + + + + + + + + + + + + + + + + + + , + + + + + ); + @@ -1657,35 +1740,33 @@ + + + + null + + ); + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -1695,104 +1776,111 @@ - - - + + + - - - + + + - + - - - - - - - - + + + + + + + - - + + private VboxPortType port; - + + { + this.real = real; + this.port = port; + } - - - - - - + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + - - - - - + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + { + + + + + + + + + + } + @@ -1805,9 +1893,10 @@ - - - + + + + @@ -1830,10 +1919,10 @@ - + retVal.value - + retVal @@ -1856,10 +1945,11 @@ - + , - + ) + { @@ -1873,13 +1963,13 @@ - + - + - + @@ -1904,7 +1994,7 @@ '>(); ')"/> - + @@ -1916,18 +2006,18 @@ - + - + - + - + @@ -1943,7 +2033,7 @@ - + @@ -1959,7 +2049,7 @@ - + } @@ -1972,9 +2062,7 @@ - - - + @@ -2013,7 +2101,7 @@ , - + ); @@ -2023,7 +2111,8 @@ - + + { @@ -2031,9 +2120,9 @@ - - - + nsISupports nsobj = obj != null ? (nsISupports)obj.getWrapped() : null; + if (nsobj == null) return null; + @@ -2053,7 +2142,7 @@ - + } @@ -2063,9 +2152,7 @@ - - - + @@ -2102,7 +2189,7 @@ - + @@ -2111,7 +2198,8 @@ , - + ) + { @@ -2121,8 +2209,8 @@ - - + Variant _args[]) + { @@ -2130,16 +2218,15 @@ - + - - - - - - + + + + + @@ -2165,50 +2252,50 @@ - + - - - - - - - - - - - - - - - - - + + + + + + + + + + - - - - - + + + + + + + + + + + , + - + ); - + - + - + - + @@ -2224,7 +2311,7 @@ - + } @@ -2242,20 +2329,23 @@ - - - + + { + super(wrapped, port); + } - - - + + { + super(wrapped); + } - - - + + { + + } @@ -2268,12 +2358,14 @@ - - + + + + @@ -2303,7 +2395,8 @@ - + + { @@ -2315,11 +2408,11 @@ - + - - + } + @@ -2331,7 +2424,8 @@ - + + { @@ -2340,7 +2434,7 @@ - + } @@ -2375,41 +2469,46 @@ - import java.util.List; + + import java.util.List; - + - - - - - - - + + + + { + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + { + + + + { + + + + + + + + + + + + - - + + } + @@ -2429,7 +2528,8 @@ import java.util.List; - + + { @@ -2439,7 +2539,7 @@ - + } @@ -2461,19 +2561,22 @@ - + + { - + + { - - - + + { + this.sink = sink; + } @@ -2483,7 +2586,7 @@ - + } @@ -2492,298 +2595,376 @@ - + - + { - public T value; - - public Holder() - { - } - public Holder(T value) - { - this.value = value; - } -} -]]> - - - - - - - - - + public T value; - + - - - - - + + + - + - + + - - - + + + - - - - + + + + - + wrap(byte[] vals) { - if (vals==null) +public class Helper +{ + public static List wrap(byte[] values) + { + if (values == null) return null; - List ret = new ArrayList(vals.length); - for (short v : vals) { - ret.add(v); + List ret = new ArrayList(values.length); + for (short v : values) + { + ret.add(v); } return ret; } - public static List wrap(int[] vals) { - if (vals==null) - return null; + public static List wrap(short[] values) + { + if (values == null) + return null; - List ret = new ArrayList(vals.length); - for (int v : vals) { - ret.add(v); + List ret = new ArrayList(values.length); + for (short v : values) + { + ret.add(v); } return ret; } - public static List wrap(long[] vals) { - if (vals==null) - return null; + public static List wrap(int[] values) + { + if (values == null) + return null; - List ret = new ArrayList(vals.length); - for (long v : vals) { - ret.add(v); + List ret = new ArrayList(values.length); + for (int v : values) + { + ret.add(v); } return ret; } - public static List wrap(String[] vals) { - if (vals==null) + public static List wrap(long[] values) + { + if (values == null) return null; - List ret = new ArrayList(vals.length); - for (String v : vals) { + + List ret = new ArrayList(values.length); + for (long v : values) + { ret.add(v); } return ret; } - public static List wrap(Class wrapperClass, T[] thisPtrs) { - if (thisPtrs==null) - return null; + public static List wrap(boolean[] values) + { + if (values == null) + return null; - List ret = new ArrayList(thisPtrs.length); - for (T thisPtr : thisPtrs) { - ret.add(thisPtr); + List ret = new ArrayList(values.length); + for (boolean v: values) + { + ret.add(v); } return ret; } - public static List wrapEnum(Class wrapperClass, long values[]) { - try { - if (values==null) - return null; - Constructor c = wrapperClass.getConstructor(int.class); + public static List wrap(String[] values) + { + if (values == null) + return null; + + List ret = new ArrayList(values.length); + for (String v : values) + { + ret.add(v); + } + return ret; + } + + public static List wrap(Class wrapperClass, T[] values) + { + if (values == null) + return null; + + List ret = new ArrayList(values.length); + for (T v : values) + { + ret.add(v); + } + return ret; + } + + @SuppressWarnings( "unchecked") + public static List wrapEnum(Class wrapperClass, long values[]) + { + try + { + if (values == null) + return null; + //// This code is questionable, as it invokes a private constructor + //// (all enums only have default constructors), and we don't really + //// know what to pass as the name, and the ordinal may or may not + //// be sensible, especially if the long was abused as a bitset. + //Constructor c = wrapperClass.getDeclaredConstructor(String.class, int.class, int.class); + //c.setAccessible(true); // make it callable + //List ret = new ArrayList(values.length); + //for (long v : values) + //{ + // T convEnum = c.newInstance("unknown", (int)v, (int)v); + // ret.add(convEnum); + //} + + // Alternative implementation: use the fromValue method, which is + // what the code handling single enums will do. I see no reason to + // use the above very ugly hack if there are better alternatives, + // which as a bonus complain about unknown values. This variant is + // slower, but also orders of magnitude safer. + java.lang.reflect.Method fromValue = wrapperClass.getMethod("fromValue", long.class); List ret = new ArrayList(values.length); - for (long v : values) { - ret.add(c.newInstance(v)); + for (long v : values) + { + T convEnum = (T)fromValue.invoke(null, v); + ret.add(convEnum); } return ret; - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch (InstantiationException e) { + } + catch (NoSuchMethodException e) + { throw new AssertionError(e); - } catch (IllegalAccessException e) { + } + //catch (InstantiationException e) + //{ + // throw new AssertionError(e); + //} + catch (IllegalAccessException e) + { throw new AssertionError(e); - } catch (InvocationTargetException e) { + } + catch (InvocationTargetException e) + { throw new AssertionError(e); } } - public static short[] unwrapUShort(List vals) { - if (vals==null) - return null; + public static short[] unwrapUShort(List values) + { + if (values == null) + return null; - short[] ret = new short[vals.size()]; + short[] ret = new short[values.size()]; int i = 0; - for (short l : vals) { - ret[i++] = l; + for (short l : values) + { + ret[i++] = l; } return ret; } - public static int[] unwrapInteger(List vals) { - if (vals == null) - return null; + public static int[] unwrapInteger(List values) + { + if (values == null) + return null; - int[] ret = new int[vals.size()]; + int[] ret = new int[values.size()]; int i = 0; - for (int l : vals) { - ret[i++] = l; + for (int l : values) + { + ret[i++] = l; } return ret; } - public static long[] unwrapULong(List vals) { - if (vals == null) - return null; + public static long[] unwrapULong(List values) + { + if (values == null) + return null; - long[] ret = new long[vals.size()]; + long[] ret = new long[values.size()]; int i = 0; - for (long l : vals) { - ret[i++] = l; + for (long l : values) + { + ret[i++] = l; } return ret; } - public static boolean[] unwrapBoolean(List vals) { - if (vals==null) - return null; + public static boolean[] unwrapBoolean(List values) + { + if (values == null) + return null; - boolean[] ret = new boolean[vals.size()]; + boolean[] ret = new boolean[values.size()]; int i = 0; - for (boolean l : vals) { - ret[i++] = l; + for (boolean l : values) + { + ret[i++] = l; } return ret; } - public static String[] unwrapStr(List vals) { - if (vals==null) + public static String[] unwrapStr(List values) + { + if (values == null) return null; - String[] ret = new String[vals.size()]; + String[] ret = new String[values.size()]; int i = 0; - for (String l : vals) { - ret[i++] = l; + for (String l : values) + { + ret[i++] = l; } return ret; } - public static > long[] unwrapEnum(Class enumClass, List values) { - if (values == null) return null; + public static > long[] unwrapEnum(Class enumClass, List values) + { + if (values == null) + return null; long result[] = new long[values.size()]; - try { - java.lang.reflect.Method valueM = enumClass.getMethod("value"); - int i = 0; - for (T v : values) { - result[i++] = (Integer)valueM.invoke(v); - } - return result; - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch(SecurityException e) { - throw new AssertionError(e); - } catch (IllegalAccessException e) { - throw new AssertionError(e); - } catch (IllegalArgumentException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - throw new AssertionError(e); + try + { + java.lang.reflect.Method valueM = enumClass.getMethod("value"); + int i = 0; + for (T v : values) + { + result[i++] = (Integer)valueM.invoke(v); + } + return result; + } + catch (NoSuchMethodException e) + { + throw new AssertionError(e); + } + catch(SecurityException e) + { + throw new AssertionError(e); + } + catch (IllegalAccessException e) + { + throw new AssertionError(e); + } + catch (IllegalArgumentException e) + { + throw new AssertionError(e); + } + catch (InvocationTargetException e) + { + throw new AssertionError(e); } } - public static List wrap2(Class wrapperClass1, Class wrapperClass2, T2[] thisPtrs) { - try { - if (thisPtrs==null) + public static List wrap2(Class wrapperClass1, Class wrapperClass2, T2[] values) + { + try + { + if (values == null) return null; Constructor c = wrapperClass1.getConstructor(wrapperClass2); - List ret = new ArrayList(thisPtrs.length); - for (T2 thisPtr : thisPtrs) { - ret.add(c.newInstance(thisPtr)); + List ret = new ArrayList(values.length); + for (T2 v : values) + { + ret.add(c.newInstance(v)); } return ret; - } catch (NoSuchMethodException e) { + } + catch (NoSuchMethodException e) + { throw new AssertionError(e); - } catch (InstantiationException e) { + } + catch (InstantiationException e) + { throw new AssertionError(e); - } catch (IllegalAccessException e) { + } + catch (IllegalAccessException e) + { throw new AssertionError(e); - } catch (InvocationTargetException e) { + } + catch (InvocationTargetException e) + { throw new AssertionError(e); } } @SuppressWarnings( "unchecked") - public static T[] unwrap(Class wrapperClass, List thisPtrs) { - if (thisPtrs==null) + public static T[] unwrap(Class wrapperClass, List values) + { + if (values == null) return null; - if (thisPtrs.size() == 0) + if (values.size() == 0) return null; - return (T[])thisPtrs.toArray((T[])Array.newInstance(wrapperClass, thisPtrs.size())); + return (T[])values.toArray((T[])Array.newInstance(wrapperClass, values.size())); } @SuppressWarnings( "unchecked" ) @@ -2794,40 +2975,112 @@ public class Helper { public static Object queryInterface(Object obj, String uuid) { - try { + try + { /* Kind of ugly, but does the job of casting */ org.mozilla.xpcom.Mozilla moz = org.mozilla.xpcom.Mozilla.getInstance(); long xpobj = moz.wrapJavaObject(obj, uuid); return moz.wrapXPCOMObject(xpobj, uuid); - } catch (Exception e) { - return null; - } + } + catch (Exception e) + { + return null; + } } @SuppressWarnings("unchecked") - public static T2[] unwrap2(Class wrapperClass1, Class wrapperClass2, List thisPtrs) { - if (thisPtrs==null) return null; + public static T2[] unwrap2(Class wrapperClass1, Class wrapperClass2, List values) + { + if (values == null) + return null; - T2 ret[] = (T2[])Array.newInstance(wrapperClass2, thisPtrs.size()); + T2 ret[] = (T2[])Array.newInstance(wrapperClass2, values.size()); int i = 0; - for (T1 obj : thisPtrs) { - ret[i++] = (T2)obj.getWrapped(); + for (T1 obj : values) + { + ret[i++] = (T2)obj.getWrapped(); } return ret; } } ]]> + + + + + + + + + + + + + +import org.mozilla.xpcom.*; + +public class VBoxException extends RuntimeException +{ + private int resultCode; + private IVirtualBoxErrorInfo errorInfo; - - - + public VBoxException(String message) + { + super(message); + resultCode = -1; + errorInfo = null; + } + + public VBoxException(String message, Throwable cause) + { + super(message, cause); + if (cause instanceof org.mozilla.xpcom.XPCOMException) + { + resultCode = (int)((org.mozilla.xpcom.XPCOMException)cause).errorcode; + try + { + Mozilla mozilla = Mozilla.getInstance(); + nsIServiceManager sm = mozilla.getServiceManager(); + nsIExceptionService es = (nsIExceptionService)sm.getServiceByContractID("@mozilla.org/exceptionservice;1", nsIExceptionService.NS_IEXCEPTIONSERVICE_IID); + nsIExceptionManager em = es.getCurrentExceptionManager(); + nsIException ex = em.getCurrentException(); + errorInfo = new IVirtualBoxErrorInfo((org.mozilla.interfaces.IVirtualBoxErrorInfo)ex.queryInterface(org.mozilla.interfaces.IVirtualBoxErrorInfo.IVIRTUALBOXERRORINFO_IID)); + } + catch (NullPointerException e) + { + e.printStackTrace(); + // nothing we can do + errorInfo = null; + } + } + else + resultCode = -1; + } + + public int getResultCode() + { + return resultCode; + } + + public IVirtualBoxErrorInfo getVirtualBoxErrorInfo() + { + return errorInfo; + } +} + + + + + + - + - + = end) - return false; - } - - return true; - } - - public boolean startVm(String name, String type, int timeout) - { - IMachine m = vbox.findMachine(name); - if (m == null) - return false; - ISession session = getSessionObject(); - - if (type == null) - type = "gui"; - IProgress p = m.launchVMProcess(session, type, ""); - progressBar(p, timeout); - session.unlockMachine(); - return true; - } - public void waitForEvents(long tmo) { mozilla.waitForEvents(tmo); } } ]]> + - - - + + + - - - - + + + + - + - - - - - - - - - - - + + + + + + + + + + + + + - - +]]> + + + + - + - + + - - - + + + - - - - + + + + - + wrap(short[] vals) { - if (vals==null) return null; - if (vals.length == 0) return Collections.emptyList(); +public class Helper +{ + public static List wrap(short[] values) + { + if (values == null) + return null; + if (values.length == 0) + return Collections.emptyList(); - List ret = new ArrayList(vals.length); - for (short v : vals) { - ret.add(v); + List ret = new ArrayList(values.length); + for (short v : values) + { + ret.add(v); } return ret; } - public static List wrap(int[] vals) { - if (vals == null) return null; - if (vals.length == 0) return Collections.emptyList(); + public static List wrap(int[] values) + { + if (values == null) + return null; + if (values.length == 0) + return Collections.emptyList(); - List ret = new ArrayList(vals.length); - for (int v : vals) { - ret.add(v); + List ret = new ArrayList(values.length); + for (int v : values) + { + ret.add(v); } return ret; } - public static List wrap(long[] vals) { - if (vals==null) return null; - if (vals.length == 0) return Collections.emptyList(); + public static List wrap(long[] values) + { + if (values == null) + return null; + if (values.length == 0) + return Collections.emptyList(); - List ret = new ArrayList(vals.length); - for (long v : vals) { - ret.add(v); + List ret = new ArrayList(values.length); + for (long v : values) + { + ret.add(v); } return ret; } - public static List wrap(String[] vals) { - if (vals==null) return null; - if (vals.length == 0) return Collections.emptyList(); + public static List wrap(String[] values) + { + if (values == null) + return null; + if (values.length == 0) + return Collections.emptyList(); - List ret = new ArrayList(vals.length); - for (String v : vals) { - ret.add(v); + List ret = new ArrayList(values.length); + for (String v : values) + { + ret.add(v); } return ret; } public static T wrapDispatch(Class wrapperClass, Dispatch d) { - try { - if (d == null || d.m_pDispatch == 0) - return null; - Constructor c = wrapperClass.getConstructor(Dispatch.class); - return (T)c.newInstance(d); - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch (InstantiationException e) { - throw new AssertionError(e); - } catch (IllegalAccessException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - throw new AssertionError(e); - } + try + { + if (d == null || d.m_pDispatch == 0) + return null; + Constructor c = wrapperClass.getConstructor(Dispatch.class); + return (T)c.newInstance(d); + } + catch (NoSuchMethodException e) + { + throw new AssertionError(e); + } + catch (InstantiationException e) + { + throw new AssertionError(e); + } + catch (IllegalAccessException e) + { + throw new AssertionError(e); + } + catch (InvocationTargetException e) + { + throw new AssertionError(e); + } } @SuppressWarnings("unchecked") public static Object wrapVariant(Class wrapperClass, Variant v) { - if (v == null) - return null; - - short vt = v.getvt(); - switch (vt) - { - case Variant.VariantNull: - return null; - case Variant.VariantBoolean: - return v.getBoolean(); - case Variant.VariantByte: - return v.getByte(); - case Variant.VariantShort: - return v.getShort(); - case Variant.VariantInt: - return v.getInt(); - case Variant.VariantLongInt: - return v.getLong(); - case Variant.VariantString: - return v.getString(); - case Variant.VariantDispatch: - return wrapDispatch(wrapperClass, v.getDispatch()); - default: - throw new RuntimeException("unhandled variant type "+vt); - } + if (v == null) + return null; + + short vt = v.getvt(); + switch (vt) + { + case Variant.VariantNull: + return null; + case Variant.VariantBoolean: + return v.getBoolean(); + case Variant.VariantByte: + return v.getByte(); + case Variant.VariantShort: + return v.getShort(); + case Variant.VariantInt: + return v.getInt(); + case Variant.VariantLongInt: + return v.getLong(); + case Variant.VariantString: + return v.getString(); + case Variant.VariantDispatch: + return wrapDispatch(wrapperClass, v.getDispatch()); + default: + throw new VBoxException("unhandled variant type " + vt); + } } - public static byte[] wrapBytes(SafeArray sa) { - if (sa==null) return null; + public static byte[] wrapBytes(SafeArray sa) + { + if (sa == null) + return null; int saLen = sa.getUBound() - sa.getLBound() + 1; @@ -3186,168 +3457,229 @@ public class Helper { int j = 0; for (int i = sa.getLBound(); i <= sa.getUBound(); i++) { - Variant v = sa.getVariant(i); - // come upo with more effective approach!!! - ret[j++] = v.getByte(); + Variant v = sa.getVariant(i); + // come up with more effective approach!!! + ret[j++] = v.getByte(); } return ret; } @SuppressWarnings("unchecked") - public static List wrap(Class wrapperClass, SafeArray sa) { - if (sa==null) return null; + public static List wrap(Class wrapperClass, SafeArray sa) + { + if (sa == null) + return null; int saLen = sa.getUBound() - sa.getLBound() + 1; - if (saLen == 0) return Collections.emptyList(); + if (saLen == 0) + return Collections.emptyList(); List ret = new ArrayList(saLen); for (int i = sa.getLBound(); i <= sa.getUBound(); i++) { - Variant v = sa.getVariant(i); - ret.add((T)wrapVariant(wrapperClass, v)); + Variant v = sa.getVariant(i); + ret.add((T)wrapVariant(wrapperClass, v)); } return ret; } - public static List wrapEnum(Class wrapperClass, SafeArray sa) { - try { - if (sa==null) return null; - - int saLen = sa.getUBound() - sa.getLBound() + 1; - if (saLen == 0) return Collections.emptyList(); - List ret = new ArrayList(saLen); - Constructor c = wrapperClass.getConstructor(int.class); - for (int i = sa.getLBound(); i <= sa.getUBound(); i++) - { - Variant v = sa.getVariant(i); - ret.add(c.newInstance(v.getInt())); - } - return ret; - } catch (NoSuchMethodException e) { + public static List wrapEnum(Class wrapperClass, SafeArray sa) + { + try + { + if (sa == null) + return null; + + int saLen = sa.getUBound() - sa.getLBound() + 1; + if (saLen == 0) + return Collections.emptyList(); + List ret = new ArrayList(saLen); + Constructor c = wrapperClass.getConstructor(int.class); + for (int i = sa.getLBound(); i <= sa.getUBound(); i++) + { + Variant v = sa.getVariant(i); + ret.add(c.newInstance(v.getInt())); + } + return ret; + } + catch (NoSuchMethodException e) + { throw new AssertionError(e); - } catch (InstantiationException e) { + } + catch (InstantiationException e) + { throw new AssertionError(e); - } catch (IllegalAccessException e) { + } + catch (IllegalAccessException e) + { throw new AssertionError(e); - } catch (InvocationTargetException e) { + } + catch (InvocationTargetException e) + { throw new AssertionError(e); } } - public static SafeArray unwrapInt(List vals) { - if (vals==null) return null; - SafeArray ret = new SafeArray(Variant.VariantInt, vals.size()); + public static SafeArray unwrapInt(List values) + { + if (values == null) + return null; + SafeArray ret = new SafeArray(Variant.VariantInt, values.size()); int i = 0; - for (int l : vals) { - ret.setInt(i++, l); + for (int l : values) + { + ret.setInt(i++, l); } return ret; } - public static SafeArray unwrapLong(List vals) { - if (vals==null) return null; - SafeArray ret = new SafeArray(Variant.VariantLongInt, vals.size()); + public static SafeArray unwrapLong(List values) + { + if (values == null) + return null; + SafeArray ret = new SafeArray(Variant.VariantLongInt, values.size()); int i = 0; - for (long l : vals) { - ret.setLong(i++, l); + for (long l : values) + { + ret.setLong(i++, l); } return ret; } - public static SafeArray unwrapBool(List vals) { - if (vals==null) return null; + public static SafeArray unwrapBool(List values) + { + if (values == null) + return null; - SafeArray result = new SafeArray(Variant.VariantBoolean, vals.size()); + SafeArray result = new SafeArray(Variant.VariantBoolean, values.size()); int i = 0; - for (boolean l : vals) { - result.setBoolean(i++, l); + for (boolean l : values) + { + result.setBoolean(i++, l); } return result; } - public static SafeArray unwrapBytes(byte[] vals) { - if (vals==null) return null; + public static SafeArray unwrapBytes(byte[] values) + { + if (values == null) + return null; - SafeArray result = new SafeArray(Variant.VariantByte, vals.length); + SafeArray result = new SafeArray(Variant.VariantByte, values.length); int i = 0; - for (byte l : vals) { - result.setByte(i++, l); + for (byte l : values) + { + result.setByte(i++, l); } return result; } - public static > SafeArray unwrapEnum(Class enumClass, List values) { - if (values == null) return null; + public static > SafeArray unwrapEnum(Class enumClass, List values) + { + if (values == null) + return null; SafeArray result = new SafeArray(Variant.VariantInt, values.size()); - try { - java.lang.reflect.Method valueM = enumClass.getMethod("value"); - int i = 0; - for (T v : values) { - result.setInt(i++, (Integer)valueM.invoke(v)); - } - return result; - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch(SecurityException e) { - throw new AssertionError(e); - } catch (IllegalAccessException e) { - throw new AssertionError(e); - } catch (IllegalArgumentException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { - throw new AssertionError(e); + try + { + java.lang.reflect.Method valueM = enumClass.getMethod("value"); + int i = 0; + for (T v : values) + { + result.setInt(i++, (Integer)valueM.invoke(v)); + } + return result; + } + catch (NoSuchMethodException e) + { + throw new AssertionError(e); + } + catch(SecurityException e) + { + throw new AssertionError(e); + } + catch (IllegalAccessException e) + { + throw new AssertionError(e); + } + catch (IllegalArgumentException e) + { + throw new AssertionError(e); + } + catch (InvocationTargetException e) + { + throw new AssertionError(e); } } - public static SafeArray unwrapString(List vals) { - if (vals==null) - return null; - SafeArray result = new SafeArray(Variant.VariantString, vals.size()); + public static SafeArray unwrapString(List values) + { + if (values == null) + return null; + SafeArray result = new SafeArray(Variant.VariantString, values.size()); int i = 0; - for (String l : vals) { - result.setString(i++, l); + for (String l : values) + { + result.setString(i++, l); } return result; } - public static List wrap2(Class wrapperClass1, Class wrapperClass2, T2[] thisPtrs) { - try { - if (thisPtrs==null) return null; - if (thisPtrs.length == 0) return Collections.emptyList(); + public static List wrap2(Class wrapperClass1, Class wrapperClass2, T2[] values) + { + try + { + if (values == null) + return null; + if (values.length == 0) + return Collections.emptyList(); Constructor c = wrapperClass1.getConstructor(wrapperClass2); - List ret = new ArrayList(thisPtrs.length); - for (T2 thisPtr : thisPtrs) { - ret.add(c.newInstance(thisPtr)); + List ret = new ArrayList(values.length); + for (T2 v : values) + { + ret.add(c.newInstance(v)); } return ret; - } catch (NoSuchMethodException e) { + } + catch (NoSuchMethodException e) + { throw new AssertionError(e); - } catch (InstantiationException e) { + } + catch (InstantiationException e) + { throw new AssertionError(e); - } catch (IllegalAccessException e) { + } + catch (IllegalAccessException e) + { throw new AssertionError(e); - } catch (InvocationTargetException e) { + } + catch (InvocationTargetException e) + { throw new AssertionError(e); } } @SuppressWarnings("unchecked") - public static T[] unwrap(Class wrapperClass, List thisPtrs) { - if (thisPtrs==null) return null; - return (T[])thisPtrs.toArray((T[])Array.newInstance(wrapperClass, thisPtrs.size())); + public static T[] unwrap(Class wrapperClass, List values) + { + if (values == null) + return null; + return (T[])values.toArray((T[])Array.newInstance(wrapperClass, values.size())); } @SuppressWarnings("unchecked") - public static T2[] unwrap2(Class wrapperClass1, Class wrapperClass2, List thisPtrs) { - if (thisPtrs==null) return null; + public static T2[] unwrap2(Class wrapperClass1, Class wrapperClass2, List values) + { + if (values == null) + return null; - T2 ret[] = (T2[])Array.newInstance(wrapperClass2, thisPtrs.size()); + T2 ret[] = (T2[])Array.newInstance(wrapperClass2, values.size()); int i = 0; - for (T1 obj : thisPtrs) { - ret[i++] = (T2)obj.getWrapped(); + for (T1 obj : values) + { + ret[i++] = (T2)obj.getWrapped(); } return ret; } @@ -3359,18 +3691,72 @@ public class Helper { } } ]]> + + + + + + + + + + - - - + + +public class VBoxException extends RuntimeException +{ + private int resultCode; + private IVirtualBoxErrorInfo errorInfo; + + public VBoxException(String message) + { + super(message); + resultCode = -1; + errorInfo = null; + } + + public VBoxException(String message, Throwable cause) + { + super(message, cause); + if (cause instanceof com.jacob.com.ComException) + { + resultCode = ((com.jacob.com.ComException)cause).getHResult(); + // JACOB doesn't support calling GetErrorInfo, which + // means there is no way of getting an IErrorInfo reference, + // and that means no way of getting to IVirtualBoxErrorInfo. + errorInfo = null; + } + else + resultCode = -1; + } - + public int getResultCode() + { + return resultCode; + } + + public IVirtualBoxErrorInfo getVirtualBoxErrorInfo() + { + return errorInfo; + } +} + + + + + + + + + - + = end) - return false; - } - - return true; - } - - public boolean startVm(String name, String type, int timeout) - { - IMachine m = vbox.findMachine(name); - if (m == null) - return false; - ISession session = getSessionObject(); - if (type == null) - type = "gui"; - IProgress p = m.launchVMProcess(session, type, ""); - progressBar(p, timeout); - session.unlockMachine(); - return true; - } - public void waitForEvents(long tmo) { // what to do here? - try { + try + { Thread.sleep(tmo); - } catch (InterruptedException ie) { + } + catch (InterruptedException ie) + { } } } ]]> + - - - - + + + @@ -3500,55 +3862,63 @@ public class VirtualBoxManager - + + - - - + + + - - - - + + + + - + List wrap(Class wrapperClass, VboxPortType pt, List thisPtrs) { - try { - if(thisPtrs==null) return null; +public class Helper +{ + public static List wrap(Class wrapperClass, VboxPortType pt, List values) + { + try + { + if (values == null) + return null; Constructor c = wrapperClass.getConstructor(String.class, VboxPortType.class); - List ret = new ArrayList(thisPtrs.size()); - for (String thisPtr : thisPtrs) { - ret.add(c.newInstance(thisPtr,pt)); + List ret = new ArrayList(values.size()); + for (String v : values) + { + ret.add(c.newInstance(v, pt)); } return ret; - } catch (NoSuchMethodException e) { + } + catch (NoSuchMethodException e) + { throw new AssertionError(e); - } catch (InstantiationException e) { + } + catch (InstantiationException e) + { throw new AssertionError(e); - } catch (IllegalAccessException e) { + } + catch (IllegalAccessException e) + { throw new AssertionError(e); - } catch (InvocationTargetException e) { + } + catch (InvocationTargetException e) + { throw new AssertionError(e); } } - public static List wrap2(Class wrapperClass1, Class wrapperClass2, VboxPortType pt, List thisPtrs) { - try { - if(thisPtrs==null) return null; + public static List wrap2(Class wrapperClass1, Class wrapperClass2, VboxPortType pt, List values) + { + try + { + if (values == null) + return null; Constructor c = wrapperClass1.getConstructor(wrapperClass2, VboxPortType.class); - List ret = new ArrayList(thisPtrs.size()); - for (T2 thisPtr : thisPtrs) { - ret.add(c.newInstance(thisPtr,pt)); + List ret = new ArrayList(values.size()); + for (T2 v : values) + { + ret.add(c.newInstance(v, pt)); } return ret; - } catch (NoSuchMethodException e) { + } + catch (NoSuchMethodException e) + { throw new AssertionError(e); - } catch (InstantiationException e) { + } + catch (InstantiationException e) + { throw new AssertionError(e); - } catch (IllegalAccessException e) { + } + catch (IllegalAccessException e) + { throw new AssertionError(e); - } catch (InvocationTargetException e) { + } + catch (InvocationTargetException e) + { throw new AssertionError(e); } } - public static List unwrap(List thisPtrs) { - if (thisPtrs==null) return null; + public static List unwrap(List values) + { + if (values == null) + return null; - List ret = new ArrayList(thisPtrs.size()); - for (T obj : thisPtrs) { + List ret = new ArrayList(values.size()); + for (T obj : values) + { ret.add(obj.getWrapped()); } return ret; @@ -3614,22 +4012,25 @@ public class Helper { @SuppressWarnings("unchecked" ) public static , T2 extends Enum > List convertEnums(Class fromClass, Class toClass, - List values) { - try { - if (values==null) - return null; - java.lang.reflect.Method fromValue = toClass.getMethod("fromValue", String.class); + List values) + { + try + { + if (values == null) + return null; List ret = new ArrayList(values.size()); - for (T1 v : values) { - // static method is called with null this - ret.add((T2)fromValue.invoke(null, v.name())); + for (T1 v : values) + { + // Ordinal based enum conversion, as JAX-WS "invents" its own + // enum names and has string values with the expected content. + int enumOrdinal = v.ordinal(); + T2 convEnum = toClass.getEnumConstants()[enumOrdinal]; + ret.add(convEnum); } return ret; - } catch (NoSuchMethodException e) { - throw new AssertionError(e); - } catch (IllegalAccessException e) { - throw new AssertionError(e); - } catch (InvocationTargetException e) { + } + catch (ArrayIndexOutOfBoundsException e) + { throw new AssertionError(e); } } @@ -3645,7 +4046,7 @@ public class Helper { charToVal[i] = -1; for (int i = 0; i < valToChar.length; i++) - charToVal[valToChar[i]] = i; + charToVal[valToChar[i]] = i; charToVal['='] = 0; } @@ -3699,7 +4100,7 @@ public class Helper { break; } default: - throw new RuntimeException("bug!"); + throw new VBoxException("bug!"); } return new String(result); @@ -3735,7 +4136,7 @@ public class Helper { } if ((validChars * 3 % 4) != 0) - throw new RuntimeException("invalid encoded string "+str); + throw new VBoxException("invalid base64 encoded string " + str); int resultLength = validChars * 3 / 4 - padChars; byte[] result = new byte[resultLength]; @@ -3743,7 +4144,7 @@ public class Helper { int dataIndex = 0, stringIndex = 0; int quadraplets = validChars / 4; - for (int i=0; i + + + + + + + + + + + + + +public class VBoxException extends RuntimeException +{ + private int resultCode; + private IVirtualBoxErrorInfo errorInfo; - - - + public VBoxException(String message) + { + super(message); + resultCode = -1; + errorInfo = null; + } + + public VBoxException(String message, Throwable cause) + { + super(message, cause); + resultCode = -1; + errorInfo = null; + } + + public VBoxException(String message, Throwable cause, VboxPortType port) + { + super(message, cause); + if (cause instanceof RuntimeFaultMsg) + { + RuntimeFaultMsg m = (RuntimeFaultMsg)cause; + RuntimeFault f = m.getFaultInfo(); + resultCode = f.getResultCode(); + String retVal = f.getReturnval(); + errorInfo = (retVal.length() > 0) ? new IVirtualBoxErrorInfo(retVal, port) : null; + } + else + resultCode = -1; + } - + public int getResultCode() + { + return resultCode; + } + + public IVirtualBoxErrorInfo getVirtualBoxErrorInfo() + { + return errorInfo; + } +} + + + + + + + + - + -import java.net.URL; + + import java.net.URL; import java.math.BigInteger; import java.util.List; import java.util.Map; @@ -3788,10 +4249,10 @@ import javax.xml.ws.WebServiceException; class PortPool { - private final static String wsdlFile = ; - - known; + private final static String wsdlFile = + + known; private boolean initStarted; private VboxService svc; @@ -3801,32 +4262,35 @@ private Map known; if (usePreinit) { - new Thread(new Runnable() - { - public void run() - { - // need to sync on something else but 'this' - synchronized (known) + new Thread(new Runnable() + { + public void run() { - initStarted = true; - known.notify(); + // need to sync on something else but 'this' + synchronized (known) + { + initStarted = true; + known.notify(); + } + + preinit(); } + }).start(); - preinit(); - } - }).start(); - - synchronized (known) - { - while (!initStarted) - { - try { - known.wait(); - } catch (InterruptedException e) { - break; - } - } - } + synchronized (known) + { + while (!initStarted) + { + try + { + known.wait(); + } + catch (InterruptedException e) + { + break; + } + } + } } } @@ -3854,10 +4318,11 @@ private Map known; if (port == null) { - if (svc == null) { + if (svc == null) + { URL wsdl = PortPool.class.getClassLoader().getResource(wsdlFile); if (wsdl == null) - throw new LinkageError(wsdlFile+" not found, but it should have been in the jar"); + throw new LinkageError(wsdlFile + " not found, but it should have been in the jar"); svc = new VboxService(wsdl, new QName("http://www.virtualbox.org/Service", "vboxService")); @@ -3901,7 +4366,7 @@ public class VirtualBoxManager private static PortPool pool = new PortPool(true); protected VboxPortType port; - private IVirtualBox vbox; + private IVirtualBox vbox; private VirtualBoxManager() { @@ -3918,18 +4383,22 @@ public class VirtualBoxManager public void connect(String url, String username, String passwd) { this.port = pool.getPort(); - try { + try + { ((BindingProvider)port).getRequestContext(). put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); String handle = port.iWebsessionManagerLogon(username, passwd); this.vbox = new IVirtualBox(handle, port); - } catch (Throwable t) { - if (this.port != null && pool != null) { + } + catch (Throwable t) + { + if (this.port != null && pool != null) + { pool.releasePort(this.port); this.port = null; } // we have to throw smth derived from RuntimeException - throw new VBoxException(t, t.getMessage()); + throw new VBoxException(t.getMessage(), t, this.port); } } @@ -3938,7 +4407,8 @@ public class VirtualBoxManager { this.port = pool.getPort(); - try { + try + { ((BindingProvider)port).getRequestContext(); if (requestContext != null) ((BindingProvider)port).getRequestContext().putAll(requestContext); @@ -3950,27 +4420,41 @@ public class VirtualBoxManager put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); String handle = port.iWebsessionManagerLogon(username, passwd); this.vbox = new IVirtualBox(handle, port); - } catch (Throwable t) { - if (this.port != null && pool != null) { + } + catch (Throwable t) + { + if (this.port != null && pool != null) + { pool.releasePort(this.port); this.port = null; } // we have to throw smth derived from RuntimeException - throw new VBoxException(t, t.getMessage()); + throw new VBoxException(t.getMessage(), t, this.port); } } public void disconnect() { - try { - if (this.vbox != null) - port.iWebsessionManagerLogoff(this.vbox.getWrapped()); - } catch (InvalidObjectFaultMsg e) { - throw new VBoxException(e, e.getMessage()); - } catch (RuntimeFaultMsg e) { - throw new VBoxException(e, e.getMessage()); - } finally { - if (this.port != null) { + if (this.port == null) + return; + + try + { + if (this.vbox != null && port != null) + port.iWebsessionManagerLogoff(this.vbox.getWrapped()); + } + catch (InvalidObjectFaultMsg e) + { + throw new VBoxException(e.getMessage(), e, this.port); + } + catch (RuntimeFaultMsg e) + { + throw new VBoxException(e.getMessage(), e, this.port); + } + finally + { + if (this.port != null) + { pool.releasePort(this.port); this.port = null; } @@ -3985,14 +4469,19 @@ public class VirtualBoxManager public ISession getSessionObject() { if (this.vbox == null) - throw new RuntimeException("connect first"); - try { - String handle = port.iWebsessionManagerGetSessionObject(this.vbox.getWrapped()); - return new ISession(handle, port); - } catch (InvalidObjectFaultMsg e) { - throw new VBoxException(e, e.getMessage()); - } catch (RuntimeFaultMsg e) { - throw new VBoxException(e, e.getMessage()); + throw new VBoxException("connect first"); + try + { + String handle = port.iWebsessionManagerGetSessionObject(this.vbox.getWrapped()); + return new ISession(handle, port); + } + catch (InvalidObjectFaultMsg e) + { + throw new VBoxException(e.getMessage(), e, this.port); + } + catch (RuntimeFaultMsg e) + { + throw new VBoxException(e.getMessage(), e, this.port); } } @@ -4016,63 +4505,40 @@ public class VirtualBoxManager public IEventListener createListener(Object sink) { - throw new RuntimeException("no active listeners here"); + throw new VBoxException("no active listeners here"); } + public void cleanup() { disconnect(); deinitPerThread(); } - public boolean progressBar(IProgress p, int wait) - { - long end = System.currentTimeMillis() + wait; - while (!p.getCompleted()) - { - p.waitForCompletion(wait); - if (System.currentTimeMillis() >= end) - return false; - } - - return true; - } - - public boolean startVm(String name, String type, int timeout) - { - IMachine m = vbox.findMachine(name); - if (m == null) - return false; - ISession session = getSessionObject(); - - if (type == null) - type = "gui"; - IProgress p = m.launchVMProcess(session, type, ""); - progressBar(p, timeout); - session.unlockMachine(); - return true; - } - public void waitForEvents(long tmo) { } - - protected void finalize() throws Throwable + + protected void finalize() throws Throwable { - try { + try + { cleanup(); - } catch(Exception e) { } - finally { + catch(Exception e) + { + } + finally + { super.finalize(); } } } ]]> + - - - - + + + @@ -4084,6 +4550,10 @@ public class VirtualBoxManager + + + + @@ -4122,7 +4592,7 @@ public class VirtualBoxManager - + @@ -4142,5 +4612,10 @@ public class VirtualBoxManager + + + + + -- cgit v1.2.1