Source for file Client.inc

Documentation is available at Client.inc

  1. <?php /*-*- mode: php; tab-width:4 -*-*/
  2.  
  3.   /* java_Client.php -- parser callbacks for the PHP/Java Bridge.
  4.  
  5.   Copyright (C) 2003-2007 Jost Boekemeier
  6.  
  7.   This file is part of the PHP/Java Bridge.
  8.  
  9.   The PHP/Java Bridge ("the library") is free software; you can
  10.   redistribute it and/or modify it under the terms of the GNU General
  11.   Public License as published by the Free Software Foundation; either
  12.   version 2, or (at your option) any later version.
  13.  
  14.   The library is distributed in the hope that it will be useful, but
  15.   WITHOUT ANY WARRANTY; without even the implied warranty of
  16.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17.   General Public License for more details.
  18.  
  19.   You should have received a copy of the GNU General Public License
  20.   along with the PHP/Java Bridge; see the file COPYING.  If not, write to the
  21.   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  22.   02111-1307 USA.
  23.  
  24.   Linking this file statically or dynamically with other modules is
  25.   making a combined work based on this library.  Thus, the terms and
  26.   conditions of the GNU General Public License cover the whole
  27.   combination.
  28.  
  29.   As a special exception, the copyright holders of this library give you
  30.   permission to link this library with independent modules to produce an
  31.   executable, regardless of the license terms of these independent
  32.   modules, and to copy and distribute the resulting executable under
  33.   terms of your choice, provided that you also meet, for each linked
  34.   independent module, the terms and conditions of the license of that
  35.   module.  An independent module is a module which is not derived from
  36.   or based on this library.  If you modify this library, you may extend
  37.   this exception to your version of the library, but you are not
  38.   obligated to do so.  If you do not wish to do so, delete this
  39.   exception statement from your version. */
  40.  
  41. require_once("${JAVA_BASE}/JavaProxy.inc");
  42. require_once("${JAVA_BASE}/Parser.inc");
  43. require_once("${JAVA_BASE}/Protocol.inc");
  44. require_once("${JAVA_BASE}/GlobalRef.inc");
  45.  
  46. /**
  47.  * @access private
  48.  */
  49. class java_SimpleFactory {
  50.   public $client;
  51.   function java_SimpleFactory($client{
  52.     $this->client $client;
  53.   }
  54.   function getProxy($result$signature$wrap{
  55.     if (false$signature $signature$wrap $wrap}
  56.       return $result;
  57.   }
  58.   function checkResult($result{
  59.       if (false$result $result;
  60.   }
  61. }
  62. /**
  63.  * @access private
  64.  */
  65. class java_ProxyFactory extends java_SimpleFactory {
  66.   function java_ProxyFactory($client{
  67.     parent::java_SimpleFactory($client);
  68.   }
  69.   function create($result$signature{
  70.     return new java_JavaProxy($result$signature);
  71.   }
  72.   function createInternal($proxy{
  73.     return new java_InternalJava($proxy);
  74.   }
  75.   function getProxy($result$signature$wrap{
  76.     $proxy $this->create($result$signature);
  77.     if($wrap$proxy $this->createInternal($proxy);
  78.     return $proxy;
  79.   }
  80. }
  81. /**
  82.  * @access private
  83.  */
  84. class java_ArrayProxyFactory extends java_ProxyFactory {
  85.   function java_ArrayProxyFactory($client{
  86.     parent::java_ProxyFactory($client);
  87.   }
  88.   function create($result$signature{
  89.     return new java_ArrayProxy($result$signature);
  90.   }    
  91. }
  92. /**
  93.  * @access private
  94.  */
  95. class java_IteratorProxyFactory extends java_ProxyFactory {
  96.   function java_IteratorProxyFactory($client{
  97.     parent::java_ProxyFactory($client);
  98.   }
  99.   function create($result$signature{
  100.     return new java_IteratorProxy($result$signature);
  101.   }    
  102. }
  103. /**
  104.  * @access private
  105.  */
  106. class java_ExceptionProxyFactory extends java_SimpleFactory {
  107.   function java_ExceptionProxyFactory($client{
  108.     parent::java_SimpleFactory($client);
  109.   }
  110.   function create($result$signature{
  111.     return new java_ExceptionProxy($result$signature);
  112.   }
  113.   function getProxy($result$signature$wrap{
  114.     $proxy $this->create($result$signature);
  115.     if($wrap$proxy new java_InternalException($proxy);
  116.     return $proxy;
  117.   }
  118. }
  119. /**
  120.  * @access private
  121.  */
  122. class java_ThrowExceptionProxyFactory extends java_ExceptionProxyFactory {
  123.   function java_ThrowExceptionProxyFactory($client{
  124.     parent::java_ExceptionProxyFactory($client);
  125.   }
  126.   function getProxy($result$signature$wrap{
  127.     if (false$wrap $wrap;
  128.       $proxy $this->create($result$signature);
  129.     // don't check for $wrap, which may be wrong (type Java instead of
  130.     // JavaException) when the user has managed to create an exception
  131.     // from a Java constructor, e.g.: new Java("java.lang.String",
  132.     // null). Since we'll discard the possibly wrong type anyway, we
  133.     // can create a fresh proxy without any further checks:
  134.     $proxy new java_InternalException($proxy);
  135.     return $proxy;
  136.   }
  137.   function checkResult($result{
  138.     throw $result;
  139.   }
  140. }
  141.  
  142. /**
  143.  * @access private
  144.  */
  145. class java_CacheEntry {
  146.   public $fmt$signature$factory$java;
  147.   public $resultVoid;
  148.  
  149.   function java_CacheEntry($fmt$signature$factory$resultVoid{
  150.     $this->fmt $fmt;
  151.     $this->signature $signature;
  152.     $this->factory $factory;
  153.     $this->resultVoid $resultVoid;
  154.   }
  155. }
  156.  
  157. /**
  158.  * @access private
  159.  */
  160. class java_Arg {
  161.   public $client;
  162.   public $exception;                 // string representation for php4
  163.   public $factory$val;
  164.   public $signature// class type
  165.   
  166.   function java_Arg($client{
  167.     $this->client $client;
  168.     $this->factory $client->simpleFactory;
  169.   }
  170.   function linkResult(&$val{
  171.     $this->val &$val;
  172.   }
  173.   function setResult($val{
  174.     $this->val &$val;
  175.   }
  176.   function getResult($wrap{
  177.     $rc $this->factory->getProxy($this->val$this->signature$wrap);
  178.     $factory $this->factory;
  179.  
  180.     $this->factory $this->client->simpleFactory;
  181.     $factory->checkResult($rc);
  182.     return $rc;
  183.   }
  184.   function setFactory($factory{
  185.     $this->factory $factory;
  186.   }
  187.   function setException($string{
  188.     $this->exception $string;
  189.   }
  190.   function setVoidSignature({
  191.     $this->signature "@V";
  192.     // update cache
  193.     $key $this->client->currentCacheKey;
  194.     if($key && $key[0]!='~'{            // don't cache array(...) or non-java objects
  195.       $this->client->currentArgumentsFormat[6]="3";
  196.       if(JAVA_DEBUG{
  197.         echo "ignore further results:";  echo "\n";
  198.       }
  199.       if(JAVA_DEBUG{
  200.         echo "updating cache $keyargformat: {$this->client->currentArgumentsFormat}classType: {$this->signature}\n";
  201.       }
  202.       $cacheEntry = new java_CacheEntry($this->client->currentArgumentsFormat$this->signature$this->factorytrue);
  203.       $this->client->methodCache[$key]=$cacheEntry;
  204.     }
  205.   }
  206.   function setSignature($signature) {
  207.     $this->signature = $signature;
  208.     // update cache
  209.     $key = $this->client->currentCacheKey;
  210.     if($key && $key[0]!='~') {            // don't cache array(...) or non-java objects
  211.       if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {
  212.         echo "updating cache $keyargformat: {$this->client->currentArgumentsFormat}classType: {$this->signature}\n";
  213.       }
  214.       $cacheEntry = new java_CacheEntry($this->client->currentArgumentsFormat, $this->signature, $this->factory, false);
  215.       $this->client->methodCache[$key]=$cacheEntry;
  216.     }
  217.   }
  218. }
  219. /**
  220.  * @access private
  221.  */
  222. class java_CompositeArg extends java_Arg {
  223.   public $parentArg;
  224.   public $idx;                        // position within $val;
  225.   public $type;                    // for A and X
  226.   public $counter;
  227.  
  228.   function java_CompositeArg($client, $type) {
  229.     parent::java_Arg($client);
  230.     $this->type = $type;
  231.     $this->val = array();
  232.     $this->counter = 0;
  233.   }
  234.   function setNextIndex() {
  235.     $this->idx = $this->counter++;
  236.   }
  237.   function setIndex($val) {
  238.     $this->idx = $val;
  239.   }
  240.   function linkResult(&$val) {
  241.     $this->val[$this->idx]=&$val;
  242.   }
  243.   function setResult($val) {
  244.     $this->val[$this->idx]=$this->factory->getProxy($val, $this->signature, true);
  245.     $this->factory = $this->client->simpleFactory;
  246.   }
  247. }
  248. /**
  249.  * @access private
  250.  */
  251. class java_ApplyArg extends java_CompositeArg {
  252.   public $m, $p, $v, $n;             // see PROTOCOL.TXT
  253.   function java_ApplyArg($client, $type, $m, $p, $v, $n) {
  254.     parent::java_CompositeArg($client, $type);
  255.     $this->m = $m;
  256.     $this->p = $p;
  257.     $this->v = $v;
  258.     $this->n = $n;
  259.   }
  260. }
  261.  
  262. /**
  263.  * @access private
  264.  */
  265. class java_Client /* implements IDocHandler */ {
  266.   public $RUNTIME;
  267.  
  268.   public $result, $exception;
  269.   public $parser;
  270.  
  271.   public $simpleArg, $compositeArg;
  272.   public $simpleFactory, 
  273.     $proxyFactory, $iteratorProxyFacroty, 
  274.     $arrayProxyFactory, $exceptionProxyFactory, $throwExceptionProxyFactory;
  275.   
  276.   public $arg;
  277.   public $asyncCtx, $cancelProxyCreationCounter;
  278.   public $globalRef;
  279.  
  280.   public $stack;
  281.  
  282.   // the cache
  283.   public $defaultCache = array(), $asyncCache = array(), $methodCache;
  284.   public $isAsync = 0;
  285.   public $currentCacheKey, $currentArgumentsFormat;
  286.   public $cachedJavaPrototype;
  287.   
  288.   
  289.   // send buffer
  290.   public $sendBuffer, $preparedToSendBuffer;
  291.  
  292.   function java_Client() {
  293.     $this->RUNTIME = array();
  294.     // named pipes are enabled if shared memory is accessible
  295.     if(JAVA_PIPE_DIR && function_exists("posix_mkfifo")) 
  296.       $this->RUNTIME['PIPE_DIR']=<a href="../Java/_Options.inc.html#defineJAVA_PIPE_DIR">JAVA_PIPE_DIR</a>;
  297.     else
  298.       $this->RUNTIME['PIPE_DIR']=null;
  299.  
  300.     $this->parser = new java_Parser($this);
  301.     $this->protocol = new java_Protocol($this);
  302.  
  303.     $this->simpleFactory = new java_SimpleFactory($this);
  304.     $this->proxyFactory = new java_ProxyFactory($this);
  305.     $this->arrayProxyFactory = new java_ArrayProxyFactory($this);
  306.     $this->iteratorProxyFactory = new java_IteratorProxyFactory($this);
  307.     $this->exceptionProxyFactory = new java_ExceptionProxyFactory($this);
  308.     $this->throwExceptionProxyFactory = new java_ThrowExceptionProxyFactory($this);
  309.  
  310.     $this->cachedJavaPrototype=new java_JavaProxyProxy($this);
  311.  
  312.     $this->simpleArg = new java_Arg($this);
  313.  
  314.     $this->globalRef = new java_GlobalRef($this);
  315.  
  316.     $this->asyncCtx = $this->cancelProxyCreationCounter = 0;
  317.     
  318.     $this->methodCache = $this->defaultCache;
  319.   }
  320.  
  321.   function __destruct() { 
  322.     if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) echo "the client destroyed\n";
  323.     if ($this->sendBuffer) $this->protocol->flush();
  324.     $this->protocol->keepAlive();
  325.   }
  326.  
  327.   function read($size) {
  328.     return $this->protocol->read($size);
  329.   }
  330.  
  331.   function setDefaultHandler() {
  332.     $this->methodCache = $this->defaultCache;
  333.   }
  334.  
  335.   function setAsyncHandler() {
  336.     $this->methodCache = $this->asyncCache;
  337.   }
  338.  
  339.  
  340.   function handleRequests() {
  341.     do {
  342.       $tail_call = false;
  343.       $this->stack=array($this->arg=$this->simpleArg);
  344.       $this->idx = 0;
  345.       $this->parser->parse();
  346.  
  347.       /* pull off A, if any */
  348.       if((count($this->stack)) > 1) {
  349.         $arg = array_pop($this->stack);
  350.         $this->apply($arg);
  351.         $tail_call = 1;            // we don't expect a result
  352.       } else {
  353.         $tail_call = 0;
  354.       }
  355.  
  356.       $this->stack=null;
  357.     } while($tail_call);
  358.     return 1;
  359.   }
  360.  
  361.   function getWrappedResult($wrap) {
  362.     return $this->simpleArg->getResult($wrap);
  363.   }
  364.   function getInternalResult() {
  365.     return $this->getWrappedResult(false);
  366.   }
  367.   function getResult() {
  368.     return $this->getWrappedResult(true);
  369.   }
  370.   function getProxyFactory($type) {
  371.     switch($type[0]) {
  372.     case 'E':
  373.       $factory = $this->exceptionProxyFactory;
  374.       break;
  375.     case 'C':
  376.       $factory = $this->iteratorProxyFactory;
  377.       break;
  378.     case 'A':
  379.       $factory = $this->arrayProxyFactory;
  380.       break;
  381.     case 'O':
  382.       $factory = $this->proxyFactory;
  383.     }
  384.     return $factory;
  385.   }
  386.   function link(&$arg, &$newArg) {
  387.     $arg->linkResult($newArg->val);
  388.     $newArg->parentArg = $arg;
  389.   }
  390.   function getExact($str) {
  391.     return hexdec($str);
  392.   }
  393.   function getInexact($str) {
  394.     $val = null;
  395.       sscanf($str, "%e", $val);
  396.     return $val;
  397.   }
  398.   function begin($name, $st) {
  399.     $arg = $this->arg;
  400.     switch($name[0]) {
  401.     case 'A':                        /* receive apply args as normal array */
  402.       $object = $this->globalRef->get($this->getExact($st['v']));
  403.       $newArg = new java_ApplyArg($this, 'A',
  404.                                   $this->parser->getData($st['m']),
  405.                                   $this->parser->getData($st['p']),
  406.                                   $object,
  407.                                   $this->getExact($st['n']));
  408.       $this->link($arg, $newArg);
  409.       array_push($this->stack, $this->arg = $newArg);
  410.       break;
  411.     case 'X'
  412.       $newArg = new java_CompositeArg($this, $st['t']);
  413.       $this->link($arg, $newArg);
  414.       array_push($this->stack, $this->arg = $newArg);
  415.       break;
  416.     case 'P':
  417.       if($arg->type=='H') { /* hash table */
  418.         $s = $st['t'];
  419.         if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "setresult prepare hash:"; echo sprintf("%s", $st['t']); echo "\n";}
  420.         if($s[0]=='N') { /* number */
  421.           $arg->setIndex($this->getExact($st['v']));
  422.           if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "setresult array: index:"; echo sprintf("%s", $st['v']); echo "\n";}
  423.         } else {
  424.           $arg->setIndex($this->parser->getData($st['v']));
  425.           if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "setresult hash: index:"; echo sprintf("%s", $this->parser->getData($st['v'])); echo "\n";}
  426.         }
  427.       } else {                    /* array */
  428.         $arg->setNextIndex();
  429.       }
  430.       break;
  431.     case 'S':
  432.       $arg->setResult($this->parser->getData($st['v']));
  433.       if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "setresult string:"; echo sprintf("%s", $this->parser->getData($st['v'])); echo "\n";}
  434.       break;
  435.     case 'B':
  436.       $s=$st['v'];
  437.       $arg->setResult($s[0]=='T');
  438.       if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "setresult bool:"; echo sprintf("%s", $st['v']); echo "\n";}
  439.       break;
  440.     case 'L':                    // unsigned long
  441.       $sign = $st['p'];
  442.       $val = $this->getExact($st['v']);
  443.       if($sign[0]=='A') $val*=-1;
  444.       $arg->setResult($val);
  445.       if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "setresult long:"; echo sprintf("%s, sign: %s", $st['v'], $st['p']); echo "\n";}
  446.       break;
  447.     case 'D':
  448.       $arg->setResult($this->getInexact($st['v']));
  449.       if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "setresult double:"; echo sprintf("%s", $st['v']); echo "\n";}
  450.       break;
  451.     case 'V':
  452.       if ($st['n']!='T') {
  453.         if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "setresult VOID:"; echo "\n";}
  454.         $arg->setVoidSignature();
  455.       }
  456.       // fall through
  457.     case 'N':
  458.       $arg->setResult(null);
  459.       if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "setresult null\n"; }
  460.       break;
  461.     case 'F':
  462.       if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "comm. end\n"; }
  463.       break;
  464.     case 'O'
  465.       $arg->setFactory($this->getProxyFactory($st['p']));
  466.       $arg->setResult($this->asyncCtx=$this->getExact($st['v']));
  467.       if($st['n']!='T') $arg->setSignature($st['m']);
  468.       if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "setresult object:"; echo sprintf("%x", $this->asyncCtx); echo "\n";}
  469.       break;
  470.     case 'E':
  471.       $arg->setFactory($this->throwExceptionProxyFactory);
  472.       $arg->setResult($this->asyncCtx=$this->getExact($st['v']));
  473.       if(<a href="../Java/_Options.inc.html#defineJAVA_DEBUG">JAVA_DEBUG</a>) {echo "setresult exception:"; echo sprintf("%x", $this->asyncCtx); echo "\n";}
  474.       $arg->setException($st['m']);
  475.       break;
  476.     default
  477.       $this->parser->parserError();
  478.     }
  479.   }
  480.   function end($name) {
  481.     switch($name[0]) {
  482.     case 'X':
  483.       $frame = array_pop($this->stack);
  484.       $this->arg = $frame->parentArg;
  485.       break;
  486.     }
  487.   }
  488.   function createParserString() {
  489.     return new java_ParserString();
  490.   }
  491.   
  492.   function writeArg($arg) {
  493.     if(is_string($arg)) {
  494.       $this->protocol->writeString($arg);
  495.     } else if(is_object($arg)) {
  496.       if (!$arg instanceof <a href="../Java/java_JavaType.html">java_JavaType</a>) throw new java_IllegalArgumentException($arg);
  497.       $this->protocol->writeObject($arg->__java);
  498.       return $arg;
  499.     } else if(is_null($arg)) {
  500.       $this->protocol->writeObject(null);
  501.     } else if(is_bool($arg)) {
  502.       $this->protocol->writeBoolean($arg);
  503.     } else if(is_integer($arg)) {
  504.       $this->protocol->writeLong($arg);
  505.     } else if(is_float($arg)) {
  506.       $this->protocol->writeDouble($arg);
  507.     } else if(is_array($arg)) {
  508.       $wrote_begin=false;
  509.       foreach($arg as $key=>$val) {
  510.         if(is_string($key)) {
  511.           if(!$wrote_begin) {
  512.             $wrote_begin=1;
  513.             $this->protocol->writeCompositeBegin_h();         
  514.           }
  515.           $this->protocol->writePairBegin_s($key);
  516.           $this->writeArg($val);
  517.           $this->protocol->writePairEnd();
  518.         } else {
  519.           if(!$wrote_begin) {
  520.             $wrote_begin=1;
  521.             $this->protocol->writeCompositeBegin_h();
  522.           }
  523.           $this->protocol->writePairBegin_n($key);
  524.           $this->writeArg($val);
  525.           $this->protocol->writePairEnd();
  526.         }
  527.       }
  528.       if(!$wrote_begin) {
  529.         $this->protocol->writeCompositeBegin_a();
  530.       }
  531.       $this->protocol->writeCompositeEnd();
  532.     }
  533.     return null;
  534.   }
  535.   function writeArgs($args) {
  536.     $n = count($args);
  537.     for($i=0; $i<$n; $i++) {
  538.       $this->writeArg($args[$i]);
  539.     }
  540.   }
  541.   function createObject($name, $args) {
  542.     $this->protocol->createObjectBegin($name);
  543.     $this->writeArgs($args);
  544.     $this->protocol->createObjectEnd();
  545.     $val = $this->getInternalResult();
  546.     return $val;
  547.   }
  548.   function referenceObject($name, $args) {
  549.     $this->protocol->referenceBegin($name);
  550.     $this->writeArgs($args);
  551.     $this->protocol->referenceEnd();
  552.     $val = $this->getInternalResult();
  553.     return $val;
  554.   }
  555.   function getProperty($object, $property) {
  556.     $this->protocol->propertyAccessBegin($object, $property);
  557.     $this->protocol->propertyAccessEnd();
  558.     return $this->getResult();
  559.   }
  560.   function setProperty($object, $property, $arg) {
  561.     $this->protocol->propertyAccessBegin($object, $property);
  562.     $this->writeArg($arg);
  563.     $this->protocol->propertyAccessEnd();
  564.     $this->getResult();
  565.   }
  566.   function invokeMethod($object, $method, $args) {
  567.     $this->protocol->invokeBegin($object, $method);
  568.     $this->writeArgs($args);
  569.     $this->protocol->invokeEnd();
  570.     $val = $this->getResult();
  571.     return $val;
  572.   }
  573.   function unref($object) {
  574.     $this->protocol->writeUnref($object);
  575.   }
  576.   function apply($arg) {
  577.     $name = $arg->p;
  578.     $object = $arg->v;
  579.     $ob = $object ? array(&$object, $name) : $name;
  580.  
  581.     // save the current state
  582.     $isAsync                = $this->isAsync;
  583.     $methodCache            = $this->methodCache;
  584.     $currentArgumentsFormat = $this->currentArgumentsFormat;
  585.     // the currentCacheKey is destroyed when the result is received
  586.     // so that apply calls are not cached
  587.         
  588.     try {
  589.       $res = $arg->getResult(true);
  590.       if((!$object && !function_exists($name)) || ($object && !method_exists($object, $name))) throw new <a href="../Java/JavaException.html">JavaException</a>("java.lang.NoSuchMethodException", "$name");
  591.       
  592.       $res = call_user_func_array($ob, $res);
  593.  
  594.       $this->protocol->resultBegin();
  595.       $this->writeArg($res);
  596.       $this->protocol->resultEnd();
  597.     } catch (JavaException $e) {
  598.       $trace = $e->getTraceAsString();
  599.       $this->protocol->resultBegin();
  600.       $this->protocol->writeException($e->__java, $trace);
  601.       $this->protocol->resultEnd();
  602.     } catch(Exception $ex) {
  603.        die ($ex);
  604.     }      
  605.  
  606.     // restore the state
  607.     $this->isAsync                = $isAsync;
  608.     $this->methodCache            = $methodCache;
  609.     $this->currentArgumentsFormat = $currentArgumentsFormat;
  610.   }
  611.   function cast($object, $type) {
  612.     switch($type[0]) {
  613.     case 'S'case 's':
  614.       return $this->invokeMethod(0, "castToString", array($object));
  615.     case 'B'case 'b':
  616.       return $this->invokeMethod(0, "castToBoolean", array($object));
  617.     case 'L'case 'I'case 'l'case 'i':
  618.       return $this->invokeMethod(0, "castToExact", array($object));
  619.     case 'D'case 'd'case 'F'case 'f':
  620.       return $this->invokeMethod(0, "castToInExact", array($object));
  621.     case 'N'case 'n':
  622.       return null;
  623.     case 'A'case 'a':
  624.       return $this->invokeMethod(0, "castToArray", array($object));
  625.     case 'O'case 'o':            // eh?
  626.       return $object;
  627.     default
  628.       throw new java_RuntimeException("$type illegal");
  629.     }
  630.   }
  631.   function getContext() {
  632.     return $this->invokeMethod(0, "getContext", array());
  633.   }
  634.   function getSession($args) {
  635.     return $this->invokeMethod(0, "getSession", $args);
  636.   }
  637.   function getServerName() {
  638.     return $this->protocol->getServerName();
  639.   }
  640. }

Documentation generated on Sun, 16 Mar 2008 19:11:39 +0100 by phpDocumentor 1.4.0a2