Changeset 499

Show
Ignore:
Timestamp:
04/13/07 16:25:16 (1 year ago)
Author:
schst
Message:

First version of generated JS proxies

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docroot/jsonrpclab/json.rpc.Client.js

    r480 r499  
    4747    } 
    4848 
    49     var postUrl = this.serviceURL +'?processor=jsonrpc'
     49    var postUrl = this.serviceURL
    5050    var jsonRpcReq = { 
    5151      'method': classAndMethod, 
  • trunk/docroot/jsonrpclab/testBuddyQuoteService.php

    r481 r499  
    88  <script type="text/javascript" src="json.js"></script> 
    99  <script type="text/javascript" src="json.rpc.Client.js"></script> 
     10  <script type="text/javascript" src="<?php echo dirname($_SERVER['PHP_SELF']);?>/jsonrpc.php?processor=jsonrpc&__generateProxy=true"></script> 
    1011<script type="text/javascript"> 
    11  
    12 // This will later be generated 
    13 function BuddyQuoteService(clientObj) { 
    14  this.dispatcher = new stubbles.json.rpc.Client(clientObj, '<?php echo dirname($_SERVER['PHP_SELF']);?>/jsonrpc.php'); 
    15 } 
    16  
    17 BuddyQuoteService.prototype  = { 
    18   getQuote: function() { 
    19     return this.dispatcher.doCall('BuddyQuoteService.getQuote', arguments); 
    20   } 
    21 } 
    22  
    23  
    24 // This is application code... 
    2512var callbackObj = { 
    2613  callback__getQuote: function(id, result, error) { 
     14    alert(result); 
     15  }, 
     16  callback__getReversedQuote: function(id, result, error) { 
    2717    alert(result); 
    2818  } 
     
    3626  Quote (0-6) <input type="text" id="quoteId" size="3"/> 
    3727  <input type="button" onclick="bq.getQuote(document.getElementById('quoteId').value);" value="Get the quote!"/> 
     28  <input type="button" onclick="bq.getReversedQuote(document.getElementById('quoteId').value);" value="Get the reversed quote!"/> 
    3829</fieldset> 
    3930 
  • trunk/src/main/php/_test/BuddyQuoteService.php

    r496 r499  
    3131        return $this->buddyQuotes[$arrKey]; 
    3232    } 
     33 
     34    /** 
     35     * Get a quote in reversed order 
     36     * 
     37     * @WebMethod 
     38     * @param int $arrKey 
     39     * @return string 
     40     */ 
     41    public function getReversedQuote($arrKey) { 
     42        return strrev($this->buddyQuotes[$arrKey]); 
     43    } 
     44 
     45    /** 
     46     * This method will not be exported (no @WebMethod annotation) 
     47     * 
     48     * @return string 
     49     */ 
     50    public function fooBar() { 
     51        return 'OOOops!'; 
     52    } 
     53 
    3354} 
    3455?> 
  • trunk/src/main/php/net/stubbles/websites/processors/stubJsonRpcProcessor.php

    r497 r499  
    7373    public function doProcess() { 
    7474 
    75         switch ($this->request->getMethod()) { 
    76             case 'get': 
    77                 $this->doGET(); 
    78                 break; 
    79             case 'post': 
    80                 $this->doPOST(); 
    81                 break; 
    82         } 
     75        if ($this->request->hasValue('__generateProxy', stubRequest::SOURCE_PARAM)) { 
     76            $this->generateProxies(); 
     77        } elseif ($this->request->getMethod() === 'get') { 
     78            $this->doGET(); 
     79        } else { 
     80            $this->doPOST(); 
     81        } 
     82 
     83    } 
     84 
     85    /** 
     86     * Generate and send the generated javascript clients 
     87     * 
     88     * @param array        restrict to classes 
     89     * @todo  restrict to classes 
     90     */ 
     91    public function generateProxies($class = null) { 
     92        stubClassLoader::load('net.stubbles.service.jsonrpc.util.stubJsonRpcProxyGenerator'); 
     93        $jsCode = ''; 
     94        foreach ($this->classMap as $jsClass => $fqClass) { 
     95            $jsCode = stubJsonRpcProxyGenerator::generateJavascriptProxy($fqClass, $jsClass, $jsCode); 
     96        } 
     97        $this->response->write($jsCode); 
    8398    } 
    8499