1 | <xsl:stylesheet version = '1.0'
|
---|
2 | xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
|
---|
3 | xmlns:vbox="http://www.virtualbox.org/">
|
---|
4 |
|
---|
5 | <!--
|
---|
6 |
|
---|
7 | websrv-php.xsl:
|
---|
8 | XSLT stylesheet that generates vboxServiceWrappers.php from
|
---|
9 | VirtualBox.xidl. This PHP file represents our
|
---|
10 | web service API. Depends on WSDL file for actual SOAP bindings.
|
---|
11 |
|
---|
12 | Contributed by James Lucas (mjlucas at eng.uts.edu.au).
|
---|
13 |
|
---|
14 | Copyright (C) 2009 Sun Microsystems, Inc.
|
---|
15 |
|
---|
16 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
17 | available from http://www.virtualbox.org. This file is free software;
|
---|
18 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
19 | General Public License (GPL) as published by the Free Software
|
---|
20 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
21 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
22 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
23 |
|
---|
24 | Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
25 | Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
26 | additional information or have any questions.
|
---|
27 | -->
|
---|
28 |
|
---|
29 |
|
---|
30 | <xsl:output
|
---|
31 | method="text"
|
---|
32 | version="1.0"
|
---|
33 | encoding="utf-8"
|
---|
34 | indent="no"/>
|
---|
35 |
|
---|
36 | <xsl:include href="websrv-shared.inc.xsl" />
|
---|
37 |
|
---|
38 | <xsl:variable name="G_setSuppressedInterfaces"
|
---|
39 | select="//interface[@wsmap='suppress']" />
|
---|
40 |
|
---|
41 | <xsl:template name="emitOutParam">
|
---|
42 | <xsl:param name="type" />
|
---|
43 | <xsl:param name="value" />
|
---|
44 | <xsl:param name="safearray" />
|
---|
45 |
|
---|
46 | <xsl:choose>
|
---|
47 | <xsl:when test="$type='wstring' or $type='uuid'">(string)<xsl:value-of select="$value" /></xsl:when>
|
---|
48 | <xsl:when test="$type='boolean'">(bool)<xsl:value-of select="$value" /></xsl:when>
|
---|
49 | <xsl:when test="$type='long' or $type='unsigned long' or $type='long long' or $type='short' or $type='unsigned short' or $type='unsigned long long' or $type='result'">(int)<xsl:value-of select="$value" /></xsl:when>
|
---|
50 | <xsl:when test="$type='double' or $type='float'">(float)<xsl:value-of select="$value" /></xsl:when>
|
---|
51 | <xsl:when test="$type='octet'"><xsl:value-of select="$value" /></xsl:when>
|
---|
52 | <xsl:otherwise>
|
---|
53 | <xsl:choose>
|
---|
54 | <xsl:when test="$safearray='yes'">
|
---|
55 | <xsl:text>new </xsl:text><xsl:value-of select="$type" />Collection ($this->connection, <xsl:value-of select="$value"/><xsl:text>)</xsl:text>
|
---|
56 | </xsl:when>
|
---|
57 | <xsl:otherwise>
|
---|
58 | <xsl:text>new </xsl:text><xsl:value-of select="$type" /> ($this->connection, <xsl:value-of select="$value"/><xsl:text>)</xsl:text>
|
---|
59 | </xsl:otherwise>
|
---|
60 | </xsl:choose>
|
---|
61 | </xsl:otherwise>
|
---|
62 | </xsl:choose>
|
---|
63 | </xsl:template>
|
---|
64 |
|
---|
65 | <xsl:template name="emitGetAttribute">
|
---|
66 | <xsl:param name="ifname" />
|
---|
67 | <xsl:param name="attrname" />
|
---|
68 | <xsl:param name="attrtype" />
|
---|
69 | <xsl:param name="attrsafearray" />
|
---|
70 | <xsl:variable name="fname"><xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template> </xsl:variable>
|
---|
71 | public function <xsl:value-of select="$fname"/>() {
|
---|
72 | $request = new stdClass();
|
---|
73 | $request->_this = $this->handle;
|
---|
74 | $response = $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request));
|
---|
75 | <xsl:text>return </xsl:text>
|
---|
76 | <xsl:call-template name="emitOutParam">
|
---|
77 | <xsl:with-param name="type" select="$attrtype" />
|
---|
78 | <xsl:with-param name="value" select="concat('$response->','returnval')" />
|
---|
79 | <xsl:with-param name="safearray" select="@safearray"/>
|
---|
80 | </xsl:call-template><xsl:text>;</xsl:text>
|
---|
81 | }
|
---|
82 | </xsl:template>
|
---|
83 |
|
---|
84 | <xsl:template name="emitSetAttribute">
|
---|
85 | <xsl:param name="ifname" />
|
---|
86 | <xsl:param name="attrname" />
|
---|
87 | <xsl:param name="attrtype" />
|
---|
88 | <xsl:param name="attrsafearray" />
|
---|
89 | <xsl:variable name="fname"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template></xsl:variable>
|
---|
90 | public function <xsl:value-of select="$fname"/>($value) {
|
---|
91 | $request = stdClass();
|
---|
92 | $request->_this = $this->handle;
|
---|
93 | if (is_int($value) || is_string($value) || is_bool($value)) {
|
---|
94 | $request-><xsl:value-of select="$attrname"/> = $value;
|
---|
95 | }
|
---|
96 | else
|
---|
97 | {
|
---|
98 | $request-><xsl:value-of select="$attrname"/> = $value->handle;
|
---|
99 | }
|
---|
100 | $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request));
|
---|
101 | }
|
---|
102 | </xsl:template>
|
---|
103 |
|
---|
104 | <xsl:template name="interface">
|
---|
105 | <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
106 | <xsl:variable name="wsmap"><xsl:value-of select="@wsmap" /></xsl:variable>
|
---|
107 | <xsl:variable name="extends"><xsl:value-of select="@extends" /></xsl:variable>
|
---|
108 | <xsl:text>
|
---|
109 | /**
|
---|
110 | * Generated VBoxWebService Interface Wrapper
|
---|
111 | */
|
---|
112 | </xsl:text>
|
---|
113 | <xsl:choose>
|
---|
114 | <xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')">
|
---|
115 | <xsl:value-of select="concat('class ', $ifname, ' extends VBox_ManagedObject { ')" />
|
---|
116 | </xsl:when>
|
---|
117 | <xsl:when test="//interface[@name=$extends]">
|
---|
118 | <xsl:value-of select="concat('class ', $ifname, ' extends ', $extends, ' { ')" />
|
---|
119 | </xsl:when>
|
---|
120 | </xsl:choose>
|
---|
121 | <xsl:for-each select="method">
|
---|
122 | <xsl:if test="not((param[@type=($G_setSuppressedInterfaces/@name)])
|
---|
123 | or (param[@mod='ptr']))" >
|
---|
124 | <xsl:call-template name="method">
|
---|
125 | <xsl:with-param name="wsmap" select="$wsmap" />
|
---|
126 | </xsl:call-template>
|
---|
127 | </xsl:if>
|
---|
128 | </xsl:for-each>
|
---|
129 | <xsl:for-each select="attribute">
|
---|
130 | <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
131 | <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
|
---|
132 | <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
|
---|
133 | <!-- skip this attribute if it has parameters of a type that has wsmap="suppress" -->
|
---|
134 | <xsl:choose>
|
---|
135 | <xsl:when test="( $attrtype=($G_setSuppressedInterfaces/@name) )">
|
---|
136 | <xsl:comment><xsl:value-of select="concat('skipping attribute ', $attrtype, ' for it is of a suppressed type')" /></xsl:comment>
|
---|
137 | </xsl:when>
|
---|
138 | <xsl:otherwise>
|
---|
139 | <xsl:choose>
|
---|
140 | <xsl:when test="@readonly='yes'">
|
---|
141 | <xsl:comment> readonly attribute <xsl:copy-of select="$ifname" />::<xsl:copy-of select="$attrname" /> </xsl:comment>
|
---|
142 | </xsl:when>
|
---|
143 | <xsl:otherwise>
|
---|
144 | <xsl:comment> read/write attribute <xsl:copy-of select="$ifname" />::<xsl:copy-of select="$attrname" /> </xsl:comment>
|
---|
145 | </xsl:otherwise>
|
---|
146 | </xsl:choose>
|
---|
147 | <!-- aa) get method: emit request and result -->
|
---|
148 | <xsl:call-template name="emitGetAttribute">
|
---|
149 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
150 | <xsl:with-param name="attrname" select="$attrname" />
|
---|
151 | <xsl:with-param name="attrtype" select="$attrtype" />
|
---|
152 | </xsl:call-template>
|
---|
153 | <!-- bb) emit a set method if the attribute is read/write -->
|
---|
154 | <xsl:if test="not($attrreadonly='yes')">
|
---|
155 | <xsl:call-template name="emitSetAttribute">
|
---|
156 | <xsl:with-param name="ifname" select="$ifname" />
|
---|
157 | <xsl:with-param name="attrname" select="$attrname" />
|
---|
158 | <xsl:with-param name="attrtype" select="$attrtype" />
|
---|
159 | </xsl:call-template>
|
---|
160 | </xsl:if>
|
---|
161 | </xsl:otherwise>
|
---|
162 | </xsl:choose>
|
---|
163 | </xsl:for-each>
|
---|
164 | <xsl:text>}
|
---|
165 | </xsl:text>
|
---|
166 | </xsl:template>
|
---|
167 |
|
---|
168 | <xsl:template name="collection">
|
---|
169 | <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
170 | <xsl:text>
|
---|
171 | /**
|
---|
172 | * Generated VBoxWebService Managed Object Collection
|
---|
173 | */</xsl:text>
|
---|
174 | class <xsl:value-of select="$ifname"/>Collection extends VBox_ManagedObjectCollection {
|
---|
175 | protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
|
---|
176 | }
|
---|
177 | </xsl:template>
|
---|
178 |
|
---|
179 | <xsl:template name="interfacestruct">
|
---|
180 | <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
|
---|
181 | <xsl:text>
|
---|
182 | /**
|
---|
183 | * Generated VBoxWebService Struct
|
---|
184 | */</xsl:text>
|
---|
185 | class <xsl:value-of select="$ifname"/> extends VBox_Struct {
|
---|
186 | <xsl:for-each select="attribute">
|
---|
187 | protected $<xsl:value-of select="@name"/>;
|
---|
188 | </xsl:for-each>
|
---|
189 | public function __construct($connection, $handle) {
|
---|
190 | <xsl:for-each select="attribute">
|
---|
191 | $this-><xsl:value-of select="@name"/> = $handle-><xsl:value-of select="@name"/><xsl:text>;</xsl:text>
|
---|
192 | </xsl:for-each>
|
---|
193 | }
|
---|
194 |
|
---|
195 | <xsl:for-each select="attribute">
|
---|
196 | public function <xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="@name"/></xsl:call-template>() {
|
---|
197 | return $this-><xsl:value-of select="@name"/>;
|
---|
198 | }
|
---|
199 | </xsl:for-each>
|
---|
200 |
|
---|
201 | }
|
---|
202 | </xsl:template>
|
---|
203 |
|
---|
204 | <xsl:template name="genreq">
|
---|
205 | <xsl:param name="wsmap" />
|
---|
206 | <xsl:text>$request = new stdClass()</xsl:text>;
|
---|
207 | <xsl:if test="$wsmap='managed'">
|
---|
208 | $request->_this = $this->handle;
|
---|
209 | </xsl:if>
|
---|
210 | <xsl:for-each select="param[@dir='in']">
|
---|
211 | $request-><xsl:value-of select="@name" /> = $arg_<xsl:value-of select="@name" /><xsl:text>;</xsl:text>
|
---|
212 | </xsl:for-each>
|
---|
213 | $response = $this->connection->__soapCall('<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>', array((array)$request));
|
---|
214 | <!-- return needs to be the first one -->
|
---|
215 | return <xsl:if test="param[@dir='out']">
|
---|
216 | <xsl:text>array(</xsl:text>
|
---|
217 | </xsl:if>
|
---|
218 | <xsl:for-each select="param[@dir='return']">
|
---|
219 | <xsl:call-template name="emitOutParam">
|
---|
220 | <xsl:with-param name="type" select="@type" />
|
---|
221 | <xsl:with-param name="value" select="concat('$response->','returnval')" />
|
---|
222 | <xsl:with-param name="safearray" select="@safearray"/>
|
---|
223 | </xsl:call-template>
|
---|
224 | <xsl:if test="../param[@dir='out']">
|
---|
225 | <xsl:text>, </xsl:text>
|
---|
226 | </xsl:if>
|
---|
227 | </xsl:for-each>
|
---|
228 | <xsl:for-each select="param[@dir='out']">
|
---|
229 | <xsl:if test="not(position()=1)">
|
---|
230 | <xsl:text>, </xsl:text>
|
---|
231 | </xsl:if>
|
---|
232 | <xsl:call-template name="emitOutParam">
|
---|
233 | <xsl:with-param name="type" select="@type" />
|
---|
234 | <xsl:with-param name="value" select="concat('$response->',@name)" />
|
---|
235 | <xsl:with-param name="safearray" select="@safearray"/>
|
---|
236 | </xsl:call-template>
|
---|
237 | </xsl:for-each>
|
---|
238 | <xsl:if test="param[@dir='out']">
|
---|
239 | <xsl:text>)</xsl:text>
|
---|
240 | </xsl:if>
|
---|
241 | <xsl:text>; </xsl:text>
|
---|
242 | </xsl:template>
|
---|
243 |
|
---|
244 | <xsl:template name="method" >
|
---|
245 | <xsl:param name="wsmap" />
|
---|
246 | public function <xsl:value-of select="@name"/><xsl:text>(</xsl:text>
|
---|
247 | <xsl:for-each select="param[@dir='in']">
|
---|
248 | <xsl:if test="not(position()=1)">
|
---|
249 | <xsl:text>, </xsl:text>
|
---|
250 | </xsl:if>
|
---|
251 | <xsl:value-of select="concat('$arg_',@name)"/>
|
---|
252 | </xsl:for-each><xsl:text>) { </xsl:text>
|
---|
253 | <xsl:call-template name="genreq"><xsl:with-param name="wsmap" select="$wsmap" /></xsl:call-template>
|
---|
254 | <xsl:text> } </xsl:text>
|
---|
255 | </xsl:template>
|
---|
256 |
|
---|
257 | <xsl:template name="enum">
|
---|
258 | <xsl:text>
|
---|
259 | /**
|
---|
260 | * Generated VBoxWebService ENUM
|
---|
261 | */</xsl:text>
|
---|
262 | class <xsl:value-of select="@name"/> extends VBox_Enum {
|
---|
263 | public $NameMap = array(<xsl:for-each select="const"><xsl:if test="not(@wsmap='suppress')"><xsl:value-of select="@value"/> => '<xsl:value-of select="@name"/>'<xsl:if test="not(position()=last())">, </xsl:if></xsl:if></xsl:for-each>);
|
---|
264 | public $ValueMap = array(<xsl:for-each select="const"><xsl:if test="not(@wsmap='suppress')">'<xsl:value-of select="@name"/>' => <xsl:value-of select="@value"/><xsl:if test="not(position()=last())">, </xsl:if></xsl:if></xsl:for-each>);
|
---|
265 | }
|
---|
266 | </xsl:template>
|
---|
267 |
|
---|
268 | <xsl:template match="/">
|
---|
269 | <xsl:text><?php
|
---|
270 |
|
---|
271 | /*
|
---|
272 | * Copyright (C) 2009 Sun Microsystems, Inc.
|
---|
273 | *
|
---|
274 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
275 | * available from http://www.virtualbox.org. This file is free software;
|
---|
276 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
277 | * General Public License (GPL) as published by the Free Software
|
---|
278 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
279 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
280 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
281 | *
|
---|
282 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
283 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
284 | * additional information or have any questions.
|
---|
285 | *
|
---|
286 | * This file is autogenerated from VirtualBox.xidl, DO NOT EDIT!
|
---|
287 | */
|
---|
288 |
|
---|
289 | abstract class VBox_ManagedObject
|
---|
290 | {
|
---|
291 | protected $connection;
|
---|
292 | protected $handle;
|
---|
293 |
|
---|
294 | public function __construct($soap, $handle = null)
|
---|
295 | {
|
---|
296 | $this->connection = $soap;
|
---|
297 | $this->handle = $handle;
|
---|
298 | }
|
---|
299 |
|
---|
300 | public function __toString()
|
---|
301 | {
|
---|
302 | return (string)$this->handle;
|
---|
303 | }
|
---|
304 |
|
---|
305 | public function __set($attr, $value)
|
---|
306 | {
|
---|
307 | $methodName = "set" . $attr;
|
---|
308 | if (method_exists($this, $methodName))
|
---|
309 | $this->$methodName($value);
|
---|
310 | else
|
---|
311 | throw new Exception("Attribute does not exist");
|
---|
312 | }
|
---|
313 |
|
---|
314 | public function __get($attr)
|
---|
315 | {
|
---|
316 | $methodName = "get" . $attr;
|
---|
317 | if (method_exists($this, $methodName))
|
---|
318 | return $this->$methodName();
|
---|
319 | else
|
---|
320 | throw new Exception("Attribute does not exist");
|
---|
321 | }
|
---|
322 |
|
---|
323 | public function getHandle()
|
---|
324 | {
|
---|
325 | return $this->handle;
|
---|
326 | }
|
---|
327 |
|
---|
328 | public function releaseRemote()
|
---|
329 | {
|
---|
330 | try
|
---|
331 | {
|
---|
332 | $request = new stdClass();
|
---|
333 | $request->_this = $this->handle;
|
---|
334 | $this->connection->__soapCall('IManagedObjectRef_release', array((array)$request));
|
---|
335 | } catch (Exception $ex) {}
|
---|
336 | }
|
---|
337 | }
|
---|
338 |
|
---|
339 | abstract class VBox_ManagedObjectCollection implements Iterator {
|
---|
340 | protected $connection;
|
---|
341 | protected $handles;
|
---|
342 | protected $_interfaceName = null;
|
---|
343 |
|
---|
344 | public function __construct($soap, array $handles = array())
|
---|
345 | {
|
---|
346 | $this->connection = $soap;
|
---|
347 | $this->handles = $handles;
|
---|
348 | }
|
---|
349 |
|
---|
350 | public function rewind() {
|
---|
351 | reset($this->handles);
|
---|
352 | }
|
---|
353 |
|
---|
354 | public function current() {
|
---|
355 | $handle = current($this->handles);
|
---|
356 | if ($handle !== false && !$handle instanceof $this->_interfaceName) {
|
---|
357 | $handle = new $this->_interfaceName($this->connection, $handle);
|
---|
358 | }
|
---|
359 | return $handle;
|
---|
360 | }
|
---|
361 |
|
---|
362 | public function key() {
|
---|
363 | $handle = key($this->handles);
|
---|
364 | return $handle;
|
---|
365 | }
|
---|
366 |
|
---|
367 | public function next() {
|
---|
368 | $handle = next($this->handles);
|
---|
369 | return $handle;
|
---|
370 | }
|
---|
371 |
|
---|
372 | public function valid() {
|
---|
373 | $handle = $this->current() !== false;
|
---|
374 | return $handle;
|
---|
375 | }
|
---|
376 | }
|
---|
377 |
|
---|
378 | abstract class VBox_Struct {
|
---|
379 | public function __get($attr)
|
---|
380 | {
|
---|
381 | $methodName = "get" . $attr;
|
---|
382 | if (method_exists($this, $methodName))
|
---|
383 | return $this->$methodName();
|
---|
384 | else
|
---|
385 | throw new Exception("Attribute does not exist");
|
---|
386 | }
|
---|
387 | }
|
---|
388 |
|
---|
389 | abstract class VBox_Enum {
|
---|
390 | protected $handle;
|
---|
391 |
|
---|
392 | public function __construct($connection, $handle)
|
---|
393 | {
|
---|
394 | if (is_string($handle))
|
---|
395 | $this->handle = $this->ValueMap[$handle];
|
---|
396 | else
|
---|
397 | $this->handle = $handle;
|
---|
398 | }
|
---|
399 |
|
---|
400 | public function __toString()
|
---|
401 | {
|
---|
402 | return (string)$this->NameMap[$this->handle];
|
---|
403 | }
|
---|
404 | }
|
---|
405 |
|
---|
406 | </xsl:text>
|
---|
407 | <xsl:for-each select="//interface[@wsmap='managed' or @wsmap='global']">
|
---|
408 | <xsl:call-template name="interface"/>
|
---|
409 | <xsl:call-template name="collection"/>
|
---|
410 | </xsl:for-each>
|
---|
411 | <xsl:for-each select="//interface[@wsmap='struct']">
|
---|
412 | <xsl:call-template name="interfacestruct"/>
|
---|
413 | <xsl:call-template name="collection"/>
|
---|
414 | </xsl:for-each>
|
---|
415 | <xsl:for-each select="//enum">
|
---|
416 | <xsl:call-template name="enum"/>
|
---|
417 | </xsl:for-each>
|
---|
418 |
|
---|
419 | </xsl:template>
|
---|
420 |
|
---|
421 | </xsl:stylesheet>
|
---|