VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

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