Example #1
0
 /**
  *
  * @param Arg $arg
  * @throws JavaException
  */
 public function apply($arg)
 {
     $name = $arg->p;
     $object = $arg->v;
     $ob = $object == null ? $name : array(&$object, $name);
     $isAsync = $this->isAsync;
     $methodCache = $this->methodCache;
     $currentArgumentsFormat = $this->currentArgumentsFormat;
     try {
         $res = $arg->getResult(true);
         if ($object == null && !function_exists($name) || !($object == null) && !method_exists($object, $name)) {
             throw new Exception\JavaException("java.lang.NoSuchMethodError", "{$name}");
         }
         $res = call_user_func_array($ob, $res);
         if (is_object($res) && !$res instanceof JavaType) {
             trigger_error("object returned from {$name}() is not a Java object", E_USER_WARNING);
             $this->protocol->invokeBegin(0, "makeClosure");
             $this->protocol->writeULong($this->globalRef->add($res));
             $this->protocol->invokeEnd();
             $res = $this->getResult();
         }
         $this->protocol->resultBegin();
         $this->writeArg($res);
         $this->protocol->resultEnd();
     } catch (Exception\JavaException $e) {
         $trace = $e->getTraceAsString();
         $this->protocol->resultBegin();
         $this->protocol->writeException($e->__java, $trace);
         $this->protocol->resultEnd();
     } catch (\Exception $ex) {
         error_log($ex->__toString());
         trigger_error("Unchecked exception detected in callback", E_USER_ERROR);
         die(1);
     }
     $this->isAsync = $isAsync;
     $this->methodCache = $methodCache;
     $this->currentArgumentsFormat = $currentArgumentsFormat;
 }