VirtualBox

source: vbox/trunk/src/VBox/Main/webservice/websrv-php.xsl@ 28775

Last change on this file since 28775 was 28775, checked in by vboxsync, 15 years ago

Webservice: refreshed PHP bindings from James Lucas

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 20.8 KB
Line 
1<xsl:stylesheet version = '1.0'
2 xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
3 xmlns:vbox="http://www.215389.xyz/">
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.215389.xyz. 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'">
48 <xsl:call-template name="emitPrimitive">
49 <xsl:with-param name="type">string</xsl:with-param>
50 <xsl:with-param name="value" select="$value" />
51 <xsl:with-param name="safearray" select="$safearray"/>
52 </xsl:call-template>
53 </xsl:when>
54 <xsl:when test="$type='boolean'">
55 <xsl:call-template name="emitPrimitive">
56 <xsl:with-param name="type">bool</xsl:with-param>
57 <xsl:with-param name="value" select="$value" />
58 <xsl:with-param name="safearray" select="$safearray"/>
59 </xsl:call-template>
60 </xsl:when>
61 <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'">
62 <xsl:call-template name="emitPrimitive">
63 <xsl:with-param name="type">int</xsl:with-param>
64 <xsl:with-param name="value" select="$value" />
65 <xsl:with-param name="safearray" select="$safearray"/>
66 </xsl:call-template>
67 </xsl:when>
68 <xsl:when test="$type='double' or $type='float'">
69 <xsl:call-template name="emitPrimitive">
70 <xsl:with-param name="type">float</xsl:with-param>
71 <xsl:with-param name="value" select="$value" />
72 <xsl:with-param name="safearray" select="$safearray"/>
73 </xsl:call-template>
74 </xsl:when>
75 <xsl:when test="$type='octet'">
76 <xsl:call-template name="emitPrimitive">
77 <xsl:with-param name="type">octet</xsl:with-param>
78 <xsl:with-param name="value" select="$value" />
79 <xsl:with-param name="safearray" select="$safearray"/>
80 </xsl:call-template>
81 </xsl:when>
82 <xsl:when test="$type='$unknown'">
83 <xsl:call-template name="emitObject">
84 <xsl:with-param name="type">VBox_ManagedObject</xsl:with-param>
85 <xsl:with-param name="value" select="$value" />
86 <xsl:with-param name="safearray" select="$safearray"/>
87 </xsl:call-template>
88 </xsl:when>
89 <xsl:otherwise>
90 <xsl:call-template name="emitObject">
91 <xsl:with-param name="type" select="$type" />
92 <xsl:with-param name="value" select="$value" />
93 <xsl:with-param name="safearray" select="$safearray"/>
94 </xsl:call-template>
95 </xsl:otherwise>
96 </xsl:choose>
97</xsl:template>
98
99<xsl:template name="emitObject">
100 <xsl:param name="type" />
101 <xsl:param name="value" />
102 <xsl:param name="safearray" />
103 <xsl:choose>
104 <xsl:when test="$safearray='yes'">
105 <xsl:text>new </xsl:text><xsl:value-of select="$type" />Collection ($this->connection, (array)<xsl:value-of select="$value"/><xsl:text>)</xsl:text>
106 </xsl:when>
107 <xsl:otherwise>
108 <xsl:text>new </xsl:text><xsl:value-of select="$type" /> ($this->connection, <xsl:value-of select="$value"/><xsl:text>)</xsl:text>
109 </xsl:otherwise>
110 </xsl:choose>
111</xsl:template>
112
113<xsl:template name="emitPrimitive">
114 <xsl:param name="type" />
115 <xsl:param name="value" />
116 <xsl:param name="safearray" />
117 <xsl:choose>
118 <xsl:when test="$safearray='yes'">
119 <xsl:text>(array)</xsl:text><xsl:value-of select="$value"/>
120 </xsl:when>
121 <xsl:otherwise>
122 <xsl:text>(</xsl:text><xsl:value-of select="$type" /><xsl:text>)</xsl:text><xsl:value-of select="$value"/>
123 </xsl:otherwise>
124 </xsl:choose>
125</xsl:template>
126
127<xsl:template name="emitGetAttribute">
128 <xsl:param name="ifname" />
129 <xsl:param name="attrname" />
130 <xsl:param name="attrtype" />
131 <xsl:param name="attrsafearray" />
132 <xsl:variable name="fname"><xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template> </xsl:variable>
133 public function <xsl:value-of select="$fname"/>() {
134 $request = new stdClass();
135 $request->_this = $this->handle;
136 $response = $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request));
137 <xsl:text>return </xsl:text>
138 <xsl:call-template name="emitOutParam">
139 <xsl:with-param name="type" select="$attrtype" />
140 <xsl:with-param name="value" select="concat('$response->','returnval')" />
141 <xsl:with-param name="safearray" select="@safearray"/>
142 </xsl:call-template><xsl:text>;</xsl:text>
143 }
144</xsl:template>
145
146<xsl:template name="emitSetAttribute">
147 <xsl:param name="ifname" />
148 <xsl:param name="attrname" />
149 <xsl:param name="attrtype" />
150 <xsl:param name="attrsafearray" />
151 <xsl:variable name="fname"><xsl:call-template name="makeSetterName"><xsl:with-param name="attrname" select="$attrname"/></xsl:call-template></xsl:variable>
152 public function <xsl:value-of select="$fname"/>($value) {
153 $request = new stdClass();
154 $request->_this = $this->handle;
155 if (is_int($value) || is_string($value) || is_bool($value)) {
156 $request-><xsl:value-of select="$attrname"/> = $value;
157 }
158 else
159 {
160 $request-><xsl:value-of select="$attrname"/> = $value->handle;
161 }
162 $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request));
163 }
164</xsl:template>
165
166<xsl:template name="interface">
167 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
168 <xsl:variable name="wsmap"><xsl:value-of select="@wsmap" /></xsl:variable>
169 <xsl:variable name="extends"><xsl:value-of select="@extends" /></xsl:variable>
170 <xsl:text>
171/**
172* Generated VBoxWebService Interface Wrapper
173*/
174</xsl:text>
175 <xsl:choose>
176 <xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')">
177 <xsl:value-of select="concat('class ', $ifname, ' extends VBox_ManagedObject {&#10;')" />
178 </xsl:when>
179 <xsl:when test="//interface[@name=$extends]">
180 <xsl:value-of select="concat('class ', $ifname, ' extends ', $extends, ' {&#10;')" />
181 </xsl:when>
182 </xsl:choose>
183 <xsl:for-each select="method">
184 <xsl:if test="not((param[@type=($G_setSuppressedInterfaces/@name)])
185 or (param[@mod='ptr']))" >
186 <xsl:call-template name="method">
187 <xsl:with-param name="wsmap" select="$wsmap" />
188 </xsl:call-template>
189 </xsl:if>
190 </xsl:for-each>
191 <xsl:for-each select="attribute">
192 <xsl:variable name="attrname"><xsl:value-of select="@name" /></xsl:variable>
193 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable>
194 <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable>
195 <!-- skip this attribute if it has parameters of a type that has wsmap="suppress" -->
196 <xsl:choose>
197 <xsl:when test="( $attrtype=($G_setSuppressedInterfaces/@name) )">
198 <xsl:comment><xsl:value-of select="concat('skipping attribute ', $attrtype, ' for it is of a suppressed type')" /></xsl:comment>
199 </xsl:when>
200 <xsl:otherwise>
201 <xsl:choose>
202 <xsl:when test="@readonly='yes'">
203 <xsl:comment> readonly attribute <xsl:copy-of select="$ifname" />::<xsl:copy-of select="$attrname" /> </xsl:comment>
204 </xsl:when>
205 <xsl:otherwise>
206 <xsl:comment> read/write attribute <xsl:copy-of select="$ifname" />::<xsl:copy-of select="$attrname" /> </xsl:comment>
207 </xsl:otherwise>
208 </xsl:choose>
209 <!-- aa) get method: emit request and result -->
210 <xsl:call-template name="emitGetAttribute">
211 <xsl:with-param name="ifname" select="$ifname" />
212 <xsl:with-param name="attrname" select="$attrname" />
213 <xsl:with-param name="attrtype" select="$attrtype" />
214 </xsl:call-template>
215 <!-- bb) emit a set method if the attribute is read/write -->
216 <xsl:if test="not($attrreadonly='yes')">
217 <xsl:call-template name="emitSetAttribute">
218 <xsl:with-param name="ifname" select="$ifname" />
219 <xsl:with-param name="attrname" select="$attrname" />
220 <xsl:with-param name="attrtype" select="$attrtype" />
221 </xsl:call-template>
222 </xsl:if>
223 </xsl:otherwise>
224 </xsl:choose>
225 </xsl:for-each>
226 <xsl:text>}
227 </xsl:text>
228</xsl:template>
229
230<xsl:template name="collection">
231 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
232 <xsl:text>
233/**
234* Generated VBoxWebService Managed Object Collection
235*/</xsl:text>
236class <xsl:value-of select="$ifname"/>Collection extends VBox_ManagedObjectCollection {
237 protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
238}
239</xsl:template>
240
241<xsl:template name="interfacestruct">
242 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
243 <xsl:text>
244/**
245* Generated VBoxWebService Struct
246*/</xsl:text>
247class <xsl:value-of select="$ifname"/> extends VBox_Struct {
248 <xsl:for-each select="attribute">
249 protected $<xsl:value-of select="@name"/>;
250 </xsl:for-each>
251 public function __construct($connection, $values) {
252 $this->connection = $connection;
253 <xsl:for-each select="attribute">
254 $this-><xsl:value-of select="@name"/> = $values-><xsl:value-of select="@name"/><xsl:text>;</xsl:text>
255 </xsl:for-each>
256 }
257
258 <xsl:for-each select="attribute">
259 public function <xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="@name"/></xsl:call-template>() {
260 <xsl:text>return </xsl:text>
261 <xsl:call-template name="emitOutParam">
262 <xsl:with-param name="type" select="@type" />
263 <xsl:with-param name="value" select="concat('$this->',@name)" />
264 <xsl:with-param name="safearray" select="@safearray"/>
265 </xsl:call-template>;
266 }
267 </xsl:for-each>
268
269}
270</xsl:template>
271
272<xsl:template name="structcollection">
273 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
274 <xsl:text>
275/**
276* Generated VBoxWebService Struct Collection
277*/</xsl:text>
278class <xsl:value-of select="$ifname"/>Collection extends VBox_StructCollection {
279 protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
280}
281</xsl:template>
282
283<xsl:template name="genreq">
284 <xsl:param name="wsmap" />
285 <xsl:text>$request = new stdClass()</xsl:text>;
286 <xsl:if test="$wsmap='managed'">
287 $request->_this = $this->handle;
288 </xsl:if>
289 <xsl:for-each select="param[@dir='in']">
290 $request-><xsl:value-of select="@name" /> = $arg_<xsl:value-of select="@name" /><xsl:text>;</xsl:text>
291 </xsl:for-each>
292 $response = $this->connection->__soapCall('<xsl:value-of select="../@name"/>_<xsl:value-of select="@name"/>', array((array)$request));
293 <!-- return needs to be the first one -->
294 return <xsl:if test="param[@dir='out']">
295 <xsl:text>array(</xsl:text>
296 </xsl:if>
297 <xsl:for-each select="param[@dir='return']">
298 <xsl:call-template name="emitOutParam">
299 <xsl:with-param name="type" select="@type" />
300 <xsl:with-param name="value" select="concat('$response->','returnval')" />
301 <xsl:with-param name="safearray" select="@safearray"/>
302 </xsl:call-template>
303 <xsl:if test="../param[@dir='out']">
304 <xsl:text>, </xsl:text>
305 </xsl:if>
306 </xsl:for-each>
307 <xsl:for-each select="param[@dir='out']">
308 <xsl:if test="not(position()=1)">
309 <xsl:text>, </xsl:text>
310 </xsl:if>
311 <xsl:call-template name="emitOutParam">
312 <xsl:with-param name="type" select="@type" />
313 <xsl:with-param name="value" select="concat('$response->',@name)" />
314 <xsl:with-param name="safearray" select="@safearray"/>
315 </xsl:call-template>
316 </xsl:for-each>
317 <xsl:if test="param[@dir='out']">
318 <xsl:text>)</xsl:text>
319 </xsl:if>
320 <xsl:text>;&#10;</xsl:text>
321</xsl:template>
322
323<xsl:template name="method" >
324 <xsl:param name="wsmap" />
325 public function <xsl:value-of select="@name"/><xsl:text>(</xsl:text>
326 <xsl:for-each select="param[@dir='in']">
327 <xsl:if test="not(position()=1)">
328 <xsl:text>, </xsl:text>
329 </xsl:if>
330 <xsl:value-of select="concat('$arg_',@name)"/>
331 </xsl:for-each><xsl:text>) { &#10; </xsl:text>
332 <xsl:call-template name="genreq"><xsl:with-param name="wsmap" select="$wsmap" /></xsl:call-template>
333 <xsl:text> }&#10;</xsl:text>
334</xsl:template>
335
336<xsl:template name="enum">
337 <xsl:text>
338/**
339* Generated VBoxWebService ENUM
340*/</xsl:text>
341class <xsl:value-of select="@name"/> extends VBox_Enum {
342 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>);
343 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>);
344}
345</xsl:template>
346
347<xsl:template name="enumcollection">
348 <xsl:variable name="ifname"><xsl:value-of select="@name" /></xsl:variable>
349 <xsl:text>
350/**
351* Generated VBoxWebService Enum Collection
352*/</xsl:text>
353class <xsl:value-of select="$ifname"/>Collection extends VBox_EnumCollection {
354 protected $_interfaceName = "<xsl:value-of select="$ifname"/>";
355}
356</xsl:template>
357
358<xsl:template match="/">
359<xsl:text>&lt;?php
360
361/*
362* Copyright (C) 2009 Sun Microsystems, Inc.
363*
364* This file is part of VirtualBox Open Source Edition (OSE), as
365* available from http://www.215389.xyz. This file is free software;
366* you can redistribute it and/or modify it under the terms of the GNU
367* General Public License (GPL) as published by the Free Software
368* Foundation, in version 2 as it comes in the "COPYING" file of the
369* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
370* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
371*
372* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
373* Clara, CA 95054 USA or visit http://www.sun.com if you need
374* additional information or have any questions.
375*
376* This file is autogenerated from VirtualBox.xidl, DO NOT EDIT!
377*/
378
379class VBox_ManagedObject
380{
381 protected $connection;
382 protected $handle;
383
384 public function __construct($soap, $handle = null)
385 {
386 $this->connection = $soap;
387 $this->handle = $handle;
388 }
389
390 public function __toString()
391 {
392 return (string)$this->handle;
393 }
394
395 public function __set($attr, $value)
396 {
397 $methodName = "set" . $attr;
398 if (method_exists($this, $methodName))
399 $this->$methodName($value);
400 else
401 throw new Exception("Attribute does not exist");
402 }
403
404 public function __get($attr)
405 {
406 $methodName = "get" . $attr;
407 if (method_exists($this, $methodName))
408 return $this->$methodName();
409 else
410 throw new Exception("Attribute does not exist");
411 }
412
413 public function getHandle()
414 {
415 return $this->handle;
416 }
417
418 public function cast($class)
419 {
420 if (is_subclass_of($class, 'VBox_ManagedObject'))
421 {
422 return new $class($this->connection, $this->handle);
423 }
424 throw new Exception('Cannot cast VBox_ManagedObject to non-child class VBox_ManagedObject');
425 }
426
427 public function releaseRemote()
428 {
429 try
430 {
431 $request = new stdClass();
432 $request->_this = $this->handle;
433 $this->connection->__soapCall('IManagedObjectRef_release', array((array)$request));
434 } catch (Exception $ex) {}
435 }
436}
437
438abstract class VBox_Collection implements ArrayAccess, Iterator, Countable {
439 protected $_connection;
440 protected $_values;
441 protected $_objects;
442 protected $_interfaceName;
443
444 public function __construct($soap, array $values = array()) {
445 $this->_connection = $soap;
446 $this->_values = $values;
447 $this->_soapToObject();
448 }
449
450 protected function _soapToObject() {
451 $this->_objects = array();
452 foreach($this->_values as $value)
453 {
454 $this->_objects[] = new $this->_interfaceName($this->_connection, $value);
455 }
456 }
457
458 /** ArrayAccess Functions **/
459 public function offsetSet($offset, $value) {
460 if ($value instanceof $this->_interfaceName)
461 {
462 if ($offset)
463 {
464 $this->_objects[$offset] = $value;
465 }
466 else
467 {
468 $this->_objects[] = $value;
469 }
470 }
471 else
472 {
473 throw new Exception("Value must be a instance of " . $this->_interfaceName);
474 }
475 }
476
477 public function offsetExists($offset) {
478 return isset($this->_objects[$offset]);
479 }
480
481 public function offsetUnset($offset) {
482 unset($this->_objects[$offset]);
483 }
484
485 public function offsetGet($offset) {
486 return isset($this->_objects[$offset]) ? $this->_objects[$offset] : null;
487 }
488
489 /** Iterator Functions **/
490 public function rewind() {
491 reset($this->_objects);
492 }
493
494 public function current() {
495 return current($this->_objects);
496 }
497
498 public function key() {
499 return key($this->_objects);
500 }
501
502 public function next() {
503 return next($this->_objects);
504 }
505
506 public function valid() {
507 return ($this->current() !== false);
508 }
509
510 /** Countable Functions **/
511 public function count() {
512 return count($this->_objects);
513 }
514}
515
516class VBox_ManagedObjectCollection extends VBox_Collection {
517 protected $_interfaceName = 'VBox_ManagedObject';
518
519 // Result is undefined if this is called AFTER any call to VBox_Collection::offsetSet or VBox_Collection::offsetUnset
520 public function setInterfaceName($interface) {
521 if (!is_subclass_of($interface, 'VBox_ManagedObject'))
522 {
523 throw new Exception('Cannot set collection interface to non-child class of VBox_ManagedObject');
524 }
525 $this->_interfaceName = $interface;
526 $this->_soapToObject();
527 }
528}
529
530abstract class VBox_Struct {
531 protected $connection;
532
533 public function __get($attr)
534 {
535 $methodName = "get" . $attr;
536 if (method_exists($this, $methodName))
537 return $this->$methodName();
538 else
539 throw new Exception("Attribute does not exist");
540 }
541}
542
543abstract class VBox_StructCollection extends VBox_Collection {
544
545 public function __construct($soap, array $values = array())
546 {
547 if (!(array_values($values) === $values))
548 {
549 $values = array((object)$values); //Fix for when struct return value only contains one list item (e.g. one medium attachment)
550 }
551 parent::__construct($soap, $values);
552 }
553}
554
555abstract class VBox_Enum {
556 protected $_handle;
557
558 public function __construct($connection, $handle)
559 {
560 if (is_string($handle))
561 $this->_handle = $this->ValueMap[$handle];
562 else
563 $this->_handle = $handle;
564 }
565
566 public function __toString()
567 {
568 return (string)$this->NameMap[$this->_handle];
569 }
570}
571
572abstract class VBox_EnumCollection extends VBox_Collection {
573}
574
575</xsl:text>
576 <xsl:for-each select="//interface[@wsmap='managed' or @wsmap='global']">
577 <xsl:call-template name="interface"/>
578 <xsl:call-template name="collection"/>
579 </xsl:for-each>
580 <xsl:for-each select="//interface[@wsmap='struct']">
581 <xsl:call-template name="interfacestruct"/>
582 <xsl:call-template name="structcollection"/>
583 </xsl:for-each>
584 <xsl:for-each select="//enum">
585 <xsl:call-template name="enum"/>
586 <xsl:call-template name="enumcollection"/>
587 </xsl:for-each>
588
589</xsl:template>
590
591</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette