Changeset 43546 in vbox for trunk/src/VBox
- Timestamp:
- Oct 4, 2012 4:28:57 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/webservice/websrv-php.xsl
r43103 r43546 12 12 Contributed by James Lucas (mjlucas at eng.uts.edu.au). 13 13 14 Copyright (C) 2008-201 0Oracle Corporation14 Copyright (C) 2008-2012 Oracle Corporation 15 15 16 16 This file is part of VirtualBox Open Source Edition (OSE), as … … 120 120 <xsl:param name="attrsafearray" /> 121 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 } 122 public function <xsl:value-of select="$fname"/>() 123 { 124 $request = new stdClass(); 125 $request->_this = $this->handle; 126 $response = $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request)); 127 <xsl:text>return </xsl:text> 128 <xsl:call-template name="emitOutParam"> 129 <xsl:with-param name="type" select="$attrtype" /> 130 <xsl:with-param name="value" select="concat('$response->','returnval')" /> 131 <xsl:with-param name="safearray" select="@safearray"/> 132 </xsl:call-template><xsl:text>;</xsl:text> 133 } 133 134 </xsl:template> 134 135 … … 139 140 <xsl:param name="attrsafearray" /> 140 141 <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_null($value) || is_scalar($value)) { 142 public function <xsl:value-of select="$fname"/>($value) 143 { 144 $request = new stdClass(); 145 $request->_this = $this->handle; 146 <xsl:choose> 147 <xsl:when test="$attrsafearray='yes'"> if (is_array($value) || is_null($value) || is_scalar($value))</xsl:when> 148 <xsl:otherwise> if (is_null($value) || is_scalar($value))</xsl:otherwise> 149 </xsl:choose> 150 { 145 151 $request-><xsl:value-of select="$attrname"/> = $value; 146 }147 else148 {152 } 153 else 154 { 149 155 $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 }156 } 157 $this->connection->__soapCall('<xsl:value-of select="$ifname"/>_<xsl:value-of select="$fname"/>', array((array)$request)); 158 } 153 159 </xsl:template> 154 160 … … 159 165 <xsl:text> 160 166 /** 161 * Generated VBoxWebService Interface Wrapper162 */167 * Generated VBoxWebService Interface Wrapper 168 */ 163 169 </xsl:text> 164 170 <xsl:choose> 165 171 <xsl:when test="($extends = '$unknown') or ($extends = '$dispatched') or ($extends = '$errorinfo')"> 166 <xsl:value-of select="concat('class ', $ifname, ' extends VBox_ManagedObject 172 <xsl:value-of select="concat('class ', $ifname, ' extends VBox_ManagedObject { ')" /> 167 173 </xsl:when> 168 174 <xsl:when test="//interface[@name=$extends]"> 169 <xsl:value-of select="concat('class ', $ifname, ' extends ', $extends, ' 175 <xsl:value-of select="concat('class ', $ifname, ' extends ', $extends, ' { ')" /> 170 176 </xsl:when> 171 177 </xsl:choose> … … 182 188 <xsl:variable name="attrtype"><xsl:value-of select="@type" /></xsl:variable> 183 189 <xsl:variable name="attrreadonly"><xsl:value-of select="@readonly" /></xsl:variable> 190 <xsl:variable name="attrsafearray"><xsl:value-of select="@safearray" /></xsl:variable> 184 191 <!-- skip this attribute if it has parameters of a type that has wsmap="suppress" --> 185 192 <xsl:choose> … … 201 208 <xsl:with-param name="attrname" select="$attrname" /> 202 209 <xsl:with-param name="attrtype" select="$attrtype" /> 210 <xsl:with-param name="attrsafearray" select="$attrsafearray" /> 203 211 </xsl:call-template> 204 212 <!-- bb) emit a set method if the attribute is read/write --> … … 208 216 <xsl:with-param name="attrname" select="$attrname" /> 209 217 <xsl:with-param name="attrtype" select="$attrtype" /> 218 <xsl:with-param name="attrsafearray" select="$attrsafearray" /> 210 219 </xsl:call-template> 211 220 </xsl:if> … … 214 223 </xsl:for-each> 215 224 <xsl:text>} 216 225 </xsl:text> 217 226 </xsl:template> 218 227 … … 221 230 <xsl:text> 222 231 /** 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"/>"; 232 * Generated VBoxWebService Managed Object Collection 233 */</xsl:text> 234 class <xsl:value-of select="$ifname"/>Collection extends VBox_ManagedObjectCollection 235 { 236 protected $_interfaceName = "<xsl:value-of select="$ifname"/>"; 227 237 } 228 238 </xsl:template> … … 232 242 <xsl:text> 233 243 /** 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>() { 244 * Generated VBoxWebService Struct 245 */</xsl:text> 246 class <xsl:value-of select="$ifname"/> extends VBox_Struct 247 { 248 <xsl:for-each select="attribute"> protected $<xsl:value-of select="@name"/>; 249 </xsl:for-each> 250 public function __construct($connection, $values) 251 { 252 $this->connection = $connection; 253 <xsl:for-each select="attribute"> $this-><xsl:value-of select="@name"/> = $values-><xsl:value-of select="@name"/>; 254 </xsl:for-each> } 255 256 <xsl:for-each select="attribute"> public function <xsl:call-template name="makeGetterName"><xsl:with-param name="attrname" select="@name"/></xsl:call-template>() 257 { 249 258 <xsl:text>return </xsl:text> 250 259 <xsl:call-template name="emitOutParam"> … … 254 263 </xsl:call-template>; 255 264 } 256 </xsl:for-each> 257 258 } 265 </xsl:for-each>} 259 266 </xsl:template> 260 267 … … 263 270 <xsl:text> 264 271 /** 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"/>"; 272 * Generated VBoxWebService Struct Collection 273 */</xsl:text> 274 class <xsl:value-of select="$ifname"/>Collection extends VBox_StructCollection 275 { 276 protected $_interfaceName = "<xsl:value-of select="$ifname"/>"; 269 277 } 270 278 </xsl:template> 271 279 272 280 <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> 281 <xsl:param name="wsmap" /> 282 <xsl:text> $request = new stdClass(); 283 </xsl:text> 284 <xsl:if test="$wsmap='managed'"> $request->_this = $this->handle;</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 <xsl:if test="param[@dir='out']"> 290 <xsl:text>array(</xsl:text> 291 </xsl:if> 286 292 <xsl:for-each select="param[@dir='return']"> 287 293 <xsl:call-template name="emitOutParam"> … … 311 317 312 318 <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>319 <xsl:param name="wsmap" /> 320 public function <xsl:value-of select="@name"/><xsl:text>(</xsl:text> 321 <xsl:for-each select="param[@dir='in']"> 322 <xsl:if test="not(position()=1)"> 323 <xsl:text>, </xsl:text> 324 </xsl:if> 325 <xsl:value-of select="concat('$arg_',@name)"/> 326 </xsl:for-each> <xsl:text>) { </xsl:text> 327 <xsl:call-template name="genreq"><xsl:with-param name="wsmap" select="$wsmap" /></xsl:call-template> 328 <xsl:text> } </xsl:text> 323 329 </xsl:template> 324 330 … … 326 332 <xsl:text> 327 333 /** 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>); 334 * Generated VBoxWebService ENUM 335 */</xsl:text> 336 class <xsl:value-of select="@name"/> extends VBox_Enum 337 { 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>); 333 340 } 334 341 </xsl:template> … … 338 345 <xsl:text> 339 346 /** 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"/>"; 347 * Generated VBoxWebService Enum Collection 348 */</xsl:text> 349 class <xsl:value-of select="$ifname"/>Collection extends VBox_EnumCollection 350 { 351 protected $_interfaceName = "<xsl:value-of select="$ifname"/>"; 344 352 } 345 353 </xsl:template> 346 354 347 355 <xsl:template name="comResultCodes"> 348 const <xsl:value-of select="@name"/> = <xsl:value-of select="@value"/>;356 const <xsl:value-of select="@name"/> = <xsl:value-of select="@value"/>; 349 357 </xsl:template> 350 358 … … 353 361 354 362 /* 355 * Copyright (C) 2008-201 0Oracle Corporation363 * Copyright (C) 2008-2012 Oracle Corporation 356 364 * 357 365 * This file is part of a free software library; you can redistribute … … 408 416 } 409 417 410 public function getHandle() 411 { 412 return $this->handle; 413 } 414 415 public function cast($class) 416 { 417 if (is_subclass_of($class, 'VBox_ManagedObject')) 418 { 419 return new $class($this->connection, $this->handle); 420 } 421 throw new Exception('Cannot cast VBox_ManagedObject to non-child class VBox_ManagedObject'); 422 } 423 424 public function releaseRemote() 425 { 426 try 427 { 428 $request = new stdClass(); 429 $request->_this = $this->handle; 430 $this->connection->__soapCall('IManagedObjectRef_release', array((array)$request)); 431 } catch (Exception $ex) {} 432 } 433 } 434 435 abstract class VBox_Collection implements ArrayAccess, Iterator, Countable { 418 public function getHandle() 419 { 420 return $this->handle; 421 } 422 423 public function cast($class) 424 { 425 if (is_subclass_of($class, 'VBox_ManagedObject')) 426 { 427 return new $class($this->connection, $this->handle); 428 } 429 throw new Exception('Cannot cast VBox_ManagedObject to non-child class VBox_ManagedObject'); 430 } 431 432 public function releaseRemote() 433 { 434 try 435 { 436 $request = new stdClass(); 437 $request->_this = $this->handle; 438 $this->connection->__soapCall('IManagedObjectRef_release', array((array)$request)); 439 } 440 catch (Exception $ex) 441 { 442 } 443 } 444 } 445 446 abstract class VBox_Collection implements ArrayAccess, Iterator, Countable 447 { 436 448 protected $_connection; 437 449 protected $_values; … … 439 451 protected $_interfaceName; 440 452 441 public function __construct($soap, array $values = array()) { 453 public function __construct($soap, array $values = array()) 454 { 442 455 $this->_connection = $soap; 443 456 $this->_values = $values; … … 445 458 } 446 459 447 protected function _soapToObject() { 460 protected function _soapToObject() 461 { 448 462 $this->_objects = array(); 449 463 foreach($this->_values as $value) … … 454 468 455 469 /** ArrayAccess Functions **/ 456 public function offsetSet($offset, $value) { 470 public function offsetSet($offset, $value) 471 { 457 472 if ($value instanceof $this->_interfaceName) 458 473 { … … 472 487 } 473 488 474 public function offsetExists($offset) { 489 public function offsetExists($offset) 490 { 475 491 return isset($this->_objects[$offset]); 476 492 } 477 493 478 public function offsetUnset($offset) { 494 public function offsetUnset($offset) 495 { 479 496 unset($this->_objects[$offset]); 480 497 } 481 498 482 public function offsetGet($offset) { 499 public function offsetGet($offset) 500 { 483 501 return isset($this->_objects[$offset]) ? $this->_objects[$offset] : null; 484 502 } 485 503 486 504 /** Iterator Functions **/ 487 public function rewind() { 505 public function rewind() 506 { 488 507 reset($this->_objects); 489 508 } 490 509 491 public function current() { 510 public function current() 511 { 492 512 return current($this->_objects); 493 513 } 494 514 495 public function key() { 515 public function key() 516 { 496 517 return key($this->_objects); 497 518 } 498 519 499 public function next() { 520 public function next() 521 { 500 522 return next($this->_objects); 501 523 } 502 524 503 public function valid() { 525 public function valid() 526 { 504 527 return ($this->current() !== false); 505 528 } 506 529 507 530 /** Countable Functions **/ 508 public function count() { 531 public function count() 532 { 509 533 return count($this->_objects); 510 534 } 511 535 } 512 536 513 class VBox_ManagedObjectCollection extends VBox_Collection { 537 class VBox_ManagedObjectCollection extends VBox_Collection 538 { 514 539 protected $_interfaceName = 'VBox_ManagedObject'; 515 540 516 541 // Result is undefined if this is called AFTER any call to VBox_Collection::offsetSet or VBox_Collection::offsetUnset 517 public function setInterfaceName($interface) { 518 if (!is_subclass_of($interface, 'VBox_ManagedObject')) 519 { 520 throw new Exception('Cannot set collection interface to non-child class of VBox_ManagedObject'); 521 } 522 $this->_interfaceName = $interface; 523 $this->_soapToObject(); 524 } 525 } 526 527 abstract class VBox_Struct { 542 public function setInterfaceName($interface) 543 { 544 if (!is_subclass_of($interface, 'VBox_ManagedObject')) 545 { 546 throw new Exception('Cannot set collection interface to non-child class of VBox_ManagedObject'); 547 } 548 $this->_interfaceName = $interface; 549 $this->_soapToObject(); 550 } 551 } 552 553 abstract class VBox_Struct 554 { 528 555 protected $connection; 529 556 … … 538 565 } 539 566 540 abstract class VBox_StructCollection extends VBox_Collection { 567 abstract class VBox_StructCollection extends VBox_Collection 568 { 541 569 542 570 public function __construct($soap, array $values = array()) … … 550 578 } 551 579 552 abstract class VBox_Enum { 553 protected $_handle; 554 555 public function __construct($connection, $handle) 556 { 557 if (is_string($handle)) 558 $this->_handle = $this->ValueMap[$handle]; 559 else 560 $this->_handle = $handle; 561 } 562 563 public function __toString() 564 { 565 return (string)$this->NameMap[$this->_handle]; 566 } 567 } 568 569 abstract class VBox_EnumCollection extends VBox_Collection { 580 abstract class VBox_Enum 581 { 582 protected $_handle; 583 584 public function __construct($connection, $handle) 585 { 586 if (is_string($handle)) 587 $this->_handle = $this->ValueMap[$handle]; 588 else 589 $this->_handle = $handle; 590 } 591 592 public function __toString() 593 { 594 return (string)$this->NameMap[$this->_handle]; 595 } 596 } 597 598 abstract class VBox_EnumCollection extends VBox_Collection 599 { 570 600 } 571 601 … … 574 604 <xsl:text> 575 605 /** 576 * VirtualBox COM result codes 577 */ 578 class VirtualBox_COM_result_codes { 606 * VirtualBox COM result codes 607 */ 608 class VirtualBox_COM_result_codes 609 { 579 610 </xsl:text> 580 611 <xsl:for-each select="/idl/library/result"> … … 588 619 <xsl:call-template name="collection"/> 589 620 </xsl:for-each> 590 621 <xsl:for-each select="//interface[@wsmap='struct']"> 591 622 <xsl:call-template name="interfacestruct"/> 592 623 <xsl:call-template name="structcollection"/>
Note:
See TracChangeset
for help on using the changeset viewer.