/* * 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. * * * DO NOT EDIT! This is a generated file. * Generated from: src/VBox/Main/idl/VirtualBox.xidl (VirtualBox's interface definitions in XML) * Generator: src/VBox/Main/glue/glue-java.xsl */ import org.mozilla.interfaces.*; import com.jacob.com.*; import com.jacob.activeX.ActiveXComponent; import javax.xml.ws.*; ( , Holder ) () {@link } # NOTE: @see /** Expected result codes: <table> <tr> <td> </td><tr> </table> Interface ID: <tt>{ }</tt> */ @return */ @param value */ */ @return @param Interface ID: <tt>{ }</tt> */ */ { , ; private final int value; { value = v; } public int value() { return value; } { { if (c.value == (int)v) { return c; } } throw new IllegalArgumentException(Long.toString(v)); } { } } 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); } com.jacob.com.Dispatch String List < IUnknown > [] long long int int short byte boolean nsISupports String String long [] Variant List< String String /*base64*/String Long Long Integer Integer Short Boolean String String > null null, , ); , ); obj , , , ); null ); private VboxPortType port; { this.real = real; this.port = port; } { } void retVal.value retVal , ) { } void , ); { nsISupports nsobj = obj != null ? (nsISupports)obj.getWrapped() : null; if (nsobj == null) return null; } void , ) { Variant _args[]) { , ); } { super(wrapped, port); } { super(wrapped); } { } { } { } import java.util.List; { { { } import java.util.List; { } import java.util.List; { { { this.sink = sink; } } { public T value; public Holder() { } public Holder(T value) { this.value = value; } } ]]> wrap(byte[] values) { if (values == null) return null; List ret = new ArrayList(values.length); for (short v : values) { ret.add(v); } return ret; } public static List wrap(short[] values) { if (values == null) return null; List ret = new ArrayList(values.length); for (short v : values) { ret.add(v); } return ret; } public static List wrap(int[] values) { if (values == null) return null; List ret = new ArrayList(values.length); for (int v : values) { ret.add(v); } return ret; } public static List wrap(long[] values) { if (values == null) return null; List ret = new ArrayList(values.length); for (long v : values) { ret.add(v); } return ret; } public static List wrap(boolean[] values) { if (values == null) return null; List ret = new ArrayList(values.length); for (boolean v: values) { ret.add(v); } return ret; } 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) { T convEnum = (T)fromValue.invoke(null, v); ret.add(convEnum); } return ret; } 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); } } public static short[] unwrapUShort(List values) { if (values == null) return null; short[] ret = new short[values.size()]; int i = 0; for (short l : values) { ret[i++] = l; } return ret; } public static int[] unwrapInteger(List values) { if (values == null) return null; int[] ret = new int[values.size()]; int i = 0; for (int l : values) { ret[i++] = l; } return ret; } public static long[] unwrapULong(List values) { if (values == null) return null; long[] ret = new long[values.size()]; int i = 0; for (long l : values) { ret[i++] = l; } return ret; } public static boolean[] unwrapBoolean(List values) { if (values == null) return null; boolean[] ret = new boolean[values.size()]; int i = 0; for (boolean l : values) { ret[i++] = l; } return ret; } public static String[] unwrapStr(List values) { if (values == null) return null; String[] ret = new String[values.size()]; int i = 0; for (String l : values) { ret[i++] = l; } return ret; } 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); } } 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(values.length); for (T2 v : values) { ret.add(c.newInstance(v)); } return ret; } 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 T[] unwrap(Class wrapperClass, List values) { if (values == null) return null; if (values.size() == 0) return null; return (T[])values.toArray((T[])Array.newInstance(wrapperClass, values.size())); } @SuppressWarnings( "unchecked" ) public static T queryInterface(Object obj, String uuid, Class iface) { return (T)queryInterface(obj, uuid); } public static Object queryInterface(Object obj, String uuid) { 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; } } @SuppressWarnings("unchecked") public static T2[] unwrap2(Class wrapperClass1, Class wrapperClass2, List values) { if (values == null) return null; T2 ret[] = (T2[])Array.newInstance(wrapperClass2, values.size()); int i = 0; 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; } } wrap(short[] values) { if (values == null) return null; List ret = new ArrayList(values.length); for (short v : values) { ret.add(v); } return ret; } public static List wrap(int[] values) { if (values == null) return null; List ret = new ArrayList(values.length); for (int v : values) { ret.add(v); } return ret; } public static List wrap(long[] values) { if (values == null) return null; List ret = new ArrayList(values.length); for (long v : values) { ret.add(v); } return ret; } 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 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); } } @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 IllegalArgumentException("unhandled variant type " + vt); } } public static byte[] wrapBytes(SafeArray sa) { if (sa == null) return null; int saLen = sa.getUBound() - sa.getLBound() + 1; byte[] ret = new byte[saLen]; int j = 0; for (int i = sa.getLBound(); i <= sa.getUBound(); i++) { 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; int saLen = sa.getUBound() - sa.getLBound() + 1; 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)); } 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) { 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); } } 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 : values) { ret.setInt(i++, l); } return ret; } 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 : values) { ret.setLong(i++, l); } return ret; } public static SafeArray unwrapBool(List values) { if (values == null) return null; SafeArray result = new SafeArray(Variant.VariantBoolean, values.size()); int i = 0; for (boolean l : values) { result.setBoolean(i++, l); } return result; } public static SafeArray unwrapBytes(byte[] values) { if (values == null) return null; SafeArray result = new SafeArray(Variant.VariantByte, values.length); int i = 0; for (byte l : values) { result.setByte(i++, l); } return result; } 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); } } 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 : values) { result.setString(i++, l); } return result; } 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(values.length); for (T2 v : values) { ret.add(c.newInstance(v)); } return ret; } 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 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 values) { if (values == null) return null; T2 ret[] = (T2[])Array.newInstance(wrapperClass2, values.size()); int i = 0; for (T1 obj : values) { ret[i++] = (T2)obj.getWrapped(); } return ret; } /* We have very long invoke lists sometimes */ public static Variant invoke(Dispatch d, String method, Object ... args) { return Dispatch.callN(d, method, args); } } ]]> 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; } } 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(values.size()); for (String v : values) { ret.add(c.newInstance(v, pt)); } return ret; } 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); } } 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(values.size()); for (T2 v : values) { ret.add(c.newInstance(v, pt)); } return ret; } 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); } } public static List unwrap(List values) { if (values == null) return null; List ret = new ArrayList(values.size()); for (T obj : values) { ret.add(obj.getWrapped()); } return ret; } @SuppressWarnings("unchecked" ) public static , T2 extends Enum > List convertEnums(Class fromClass, Class toClass, List values) { try { if (values == null) return null; List ret = new ArrayList(values.size()); 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 (ArrayIndexOutOfBoundsException e) { throw new AssertionError(e); } } /* Pretty naive Base64 encoder/decoder. */ private static final char[] valToChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray(); private static final int[] charToVal = new int[256]; /* Initialize recoding alphabet. */ static { for (int i = 0; i < charToVal.length; i++) charToVal[i] = -1; for (int i = 0; i < valToChar.length; i++) charToVal[valToChar[i]] = i; charToVal['='] = 0; } public static String encodeBase64(byte[] data) { if (data == null) return null; if (data.length == 0) return ""; int fullTriplets = data.length / 3; int resultLen = ((data.length - 1) / 3 + 1) * 4; char[] result = new char[resultLen]; int dataIndex = 0, stringIndex = 0; for (int i = 0; i < fullTriplets; i++) { int ch1 = data[dataIndex++] & 0xff; result[stringIndex++] = valToChar[ch1 >> 2]; int ch2 = data[dataIndex++] & 0xff; result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)]; int ch3 = data[dataIndex++] & 0xff; result[stringIndex++] = valToChar[((ch2 << 2) & 0x3f) | (ch3 >> 6)]; result[stringIndex++] = valToChar[ch3 & 0x3f]; } switch (data.length - dataIndex) { case 0: // do nothing break; case 1: { int ch1 = data[dataIndex++] & 0xff; result[stringIndex++] = valToChar[ch1 >> 2]; result[stringIndex++] = valToChar[(ch1 << 4) & 0x3f]; result[stringIndex++] = '='; result[stringIndex++] = '='; break; } case 2: { int ch1 = data[dataIndex++] & 0xff; result[stringIndex++] = valToChar[ch1 >> 2]; int ch2 = data[dataIndex++] & 0xff; result[stringIndex++] = valToChar[((ch1 << 4) & 0x3f) | (ch2 >> 4)]; result[stringIndex++] = valToChar[(ch2 << 2) & 0x3f]; result[stringIndex++] = '='; break; } default: throw new VBoxException("bug!"); } return new String(result); } private static int skipInvalid(String str, int stringIndex) { while (charToVal[str.charAt(stringIndex)] < 0) stringIndex++; return stringIndex; } public static byte[] decodeBase64(String str) { if (str == null) return null; int stringLength = str.length(); if (stringLength == 0) return new byte[0]; int validChars = 0, padChars = 0; for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (charToVal[ch] >= 0) validChars++; if (ch == '=') padChars++; } if ((validChars * 3 % 4) != 0) throw new VBoxException("invalid base64 encoded string " + str); int resultLength = validChars * 3 / 4 - padChars; byte[] result = new byte[resultLength]; int dataIndex = 0, stringIndex = 0; int quadraplets = validChars / 4; for (int i = 0; i < quadraplets; i++) { stringIndex = skipInvalid(str, stringIndex); int ch1 = str.charAt(stringIndex++); stringIndex = skipInvalid(str, stringIndex); int ch2 = str.charAt(stringIndex++); stringIndex = skipInvalid(str, stringIndex); int ch3 = str.charAt(stringIndex++); stringIndex = skipInvalid(str, stringIndex); int ch4 = str.charAt(stringIndex++); result[dataIndex++] = (byte)(((charToVal[ch1] << 2) | charToVal[ch2] >> 4) & 0xff); /* we check this to ensure that we don't override data with '=' padding. */ if (dataIndex < result.length) result[dataIndex++] = (byte)(((charToVal[ch2] << 4) | charToVal[ch3] >> 2) & 0xff); if (dataIndex < result.length) result[dataIndex++] = (byte)(((charToVal[ch3] << 6) | charToVal[ch4]) & 0xff); } return result; } } ]]> 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.math.BigInteger; import java.util.List; import java.util.Map; import java.util.HashMap; import javax.xml.namespace.QName; import javax.xml.ws.BindingProvider; import javax.xml.ws.Holder; import javax.xml.ws.WebServiceException; class PortPool { private final static String wsdlFile = known; private boolean initStarted; private VboxService svc; PortPool(boolean usePreinit) { known = new HashMap(); if (usePreinit) { new Thread(new Runnable() { public void run() { // need to sync on something else but 'this' synchronized (known) { initStarted = true; known.notify(); } preinit(); } }).start(); synchronized (known) { while (!initStarted) { try { known.wait(); } catch (InterruptedException e) { break; } } } } } private synchronized void preinit() { VboxPortType port = getPort(); releasePort(port); } synchronized VboxPortType getPort() { VboxPortType port = null; int ttl = 0; for (VboxPortType cur: known.keySet()) { int value = known.get(cur); if ((value & 0x10000) == 0) { port = cur; ttl = value & 0xffff; break; } } if (port == 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"); svc = new VboxService(wsdl, new QName("http://www.virtualbox.org/Service", "vboxService")); } port = svc.getVboxServicePort(); // reuse this object 0x10 times ttl = 0x10; } // mark as used known.put(port, new Integer(0x10000 | ttl)); return port; } synchronized void releasePort(VboxPortType port) { Integer val = known.get(port); if (val == null || val == 0) { // know you not return; } int v = val; int ttl = v & 0xffff; // decrement TTL, and throw away port if used too much times if (--ttl <= 0) { known.remove(port); } else { v = ttl; // set new TTL and clear busy bit known.put(port, v); } } } public class VirtualBoxManager { private static PortPool pool = new PortPool(true); protected VboxPortType port; private IVirtualBox vbox; private VirtualBoxManager() { } public static void initPerThread() { } public static void deinitPerThread() { } public void connect(String url, String username, String passwd) { this.port = pool.getPort(); 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) { pool.releasePort(this.port); this.port = null; } // we have to throw smth derived from RuntimeException throw new VBoxException(t.getMessage(), t, this.port); } } public void connect(String url, String username, String passwd, Map requestContext, Map responseContext) { this.port = pool.getPort(); try { ((BindingProvider)port).getRequestContext(); if (requestContext != null) ((BindingProvider)port).getRequestContext().putAll(requestContext); if (responseContext != null) ((BindingProvider)port).getResponseContext().putAll(responseContext); ((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) { pool.releasePort(this.port); this.port = null; } // we have to throw smth derived from RuntimeException throw new VBoxException(t.getMessage(), t, this.port); } } public void disconnect() { 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; } } } public IVirtualBox getVBox() { return this.vbox; } public ISession getSessionObject() { if (this.vbox == null) 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); } } public ISession openMachineSession(IMachine m) throws Exception { ISession s = getSessionObject(); m.lockMachine(s, LockType.Shared); return s; } public void closeMachineSession(ISession s) { if (s != null) s.unlockMachine(); } public static synchronized VirtualBoxManager createInstance(String home) { return new VirtualBoxManager(); } public IEventListener createListener(Object sink) { throw new VBoxException("no active listeners here"); } public void cleanup() { disconnect(); deinitPerThread(); } public void waitForEvents(long tmo) { } protected void finalize() throws Throwable { try { cleanup(); } catch(Exception e) { } finally { super.finalize(); } } } ]]>