/** * Copyright (C) 2008-2009 Sun Microsystems, Inc. * * This file is part of a free software library; you can redistribute * it and/or modify it under the terms of the GNU Lesser General * Public License version 2.1 as published by the Free Software * Foundation and shipped in the "COPYING.LIB" file with this library. * The library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY of any kind. * * Sun LGPL Disclaimer: For the avoidance of doubt, except that if * any license choice other than GPL or LGPL is available it will * apply instead, Sun elects to use only the Lesser General Public * License version 2.1 (LGPLv2) at this time for any software where * a choice of LGPL license versions is made available with the * language indicating that LGPLv2 or any later version may be used, * or where a choice of which version of the LGPL is applied is * otherwise unspecified. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 USA or visit http://www.sun.com if you need * additional information or have any questions. * * * 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/webservice/glue-jaxws.xsl */ IUnknown String String } , package ; import .VboxPortType; import .VboxService; import .InvalidObjectFaultMsg; import .RuntimeFaultMsg; import javax.xml.ws.WebServiceException; List wrap(Class wrapperClass, VboxPortType pt, List thisPtrs) { try { if(thisPtrs==null) return Collections.emptyList(); Constructor c = wrapperClass.getConstructor(String.class, VboxPortType.class); List ret = new ArrayList(thisPtrs.size()); for (String thisPtr : thisPtrs) { ret.add(c.newInstance(thisPtr,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 thisPtrs) { try { if(thisPtrs==null) return Collections.emptyList(); Constructor c = wrapperClass1.getConstructor(wrapperClass2, VboxPortType.class); List ret = new ArrayList(thisPtrs.size()); for (T2 thisPtr : thisPtrs) { ret.add(c.newInstance(thisPtr,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 thisPtrs) { if (thisPtrs==null) return Collections.emptyList(); List ret = new ArrayList(); for (T obj : thisPtrs) { ret.add(obj.getRef()); } return ret; } } ]]> 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 IWebsessionManager { private static PortPool pool = new PortPool(true); protected VboxPortType port; public IWebsessionManager(URL url) { connect(url); } public IWebsessionManager(String url) { connect(url); } public IWebsessionManager(URL url, Map requestContext, Map responseContext) { connect(url.toExternalForm(), requestContext, responseContext); } public IWebsessionManager(String url, Map requestContext, Map responseContext) { connect(url, requestContext, responseContext); } public void connect(URL url) { connect(url.toExternalForm()); } public void connect(String url) { this.port = pool.getPort(); try { ((BindingProvider)port).getRequestContext(). put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); } catch (Throwable t) { if (this.port != null) pool.releasePort(this.port); // we have to throw smth derived from RuntimeException throw new WebServiceException(t); } } public void connect(String url, 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); } catch (Throwable t) { if (this.port != null) pool.releasePort(port); // we have to throw smth derived from RuntimeException throw new WebServiceException(t); } } public void disconnect(IVirtualBox refIVirtualBox) { try { logoff(refIVirtualBox); } finally { if (this.port != null) { pool.releasePort(this.port); this.port = null; } } } public void cleanupUnused() { System.gc(); Runtime.getRuntime().runFinalization(); } /* method IWebsessionManager::logon( [in] wstring username, [in] wstring password, [return] IVirtualBox return) */ public IVirtualBox logon(String username, String password) { try { String retVal = port.iWebsessionManagerLogon(username, password); return new IVirtualBox(retVal, port); } catch (InvalidObjectFaultMsg e) { throw new WebServiceException(e); } catch (RuntimeFaultMsg e) { throw new WebServiceException(e); } } /* method IWebsessionManager::getSessionObject( [in] IVirtualBox refIVirtualBox, [return] ISession return) */ public ISession getSessionObject(IVirtualBox refIVirtualBox) { try { String retVal = port.iWebsessionManagerGetSessionObject(((refIVirtualBox == null)?null:refIVirtualBox.getRef())); return new ISession(retVal, port); } catch (InvalidObjectFaultMsg e) { throw new WebServiceException(e); } catch (RuntimeFaultMsg e) { throw new WebServiceException(e); } } /* method IWebsessionManager::logoff( [in] IVirtualBox refIVirtualBox) */ public void logoff(IVirtualBox refIVirtualBox) { try { port.iWebsessionManagerLogoff(((refIVirtualBox == null)?null:refIVirtualBox.getRef())); } catch (InvalidObjectFaultMsg e) { throw new WebServiceException(e); } catch (RuntimeFaultMsg e) { throw new WebServiceException(e); } } } ]]> // ######## COLLECTIONS import java.util.ArrayList; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; @XmlAccessorType(XmlAccessType.FIELD) "array" }) protected List<String> array; public List<String> getArray() { if (array == null) { array = new ArrayList<String>(); } return this.array; } } // ######## ENUMS import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlEnumValue; import javax.xml.bind.annotation.XmlType; @XmlEnum , ; private final String value; value = v; } public String value() { return value; } if (c.value.equals(v)) { return c; } } throw new IllegalArgumentException(v); } } // ######## INTERFACES import java.math.BigInteger; import java.util.List; import javax.xml.ws.Holder; import javax.xml.ws.WebServiceException; > super(_this,port); } try { } catch (InvalidObjectFaultMsg e) { throw new WebServiceException(e); } catch (RuntimeFaultMsg e) { throw new WebServiceException(e); } } try { } catch (InvalidObjectFaultMsg e) { throw new WebServiceException(e); } catch (RuntimeFaultMsg e) { throw new WebServiceException(e); } } [] , ) */ void , ) { try { retVal = , retVal ); } catch (InvalidObjectFaultMsg e) { throw new WebServiceException(e); } catch (RuntimeFaultMsg e) { throw new WebServiceException(e); } } }