VirtualBox

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

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

Webservice: add PHP bindings (still needs integration into build system)

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

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