VirtualBox

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

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

Webservice: updated sample headers, add PHP sample

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