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