function me() { $environment = java_closure(); $Proxy = new JavaClass("java.lang.reflect.Proxy"); $proc = $Proxy->getInvocationHandler($environment); $proc->invoke($environment, "fault", array()); }
function getClosure() { $cl = java_closure(new c()); $res = java_cast($cl, "S"); if ($res != "class c") { throw new JavaException("java.lang.Exception", "test failed"); } return $cl; }
function init() { $SWT = new JavaClass("org.eclipse.swt.SWT"); $shell = $this->shell = new java("org.eclipse.swt.widgets.Shell"); $shell->setSize(320, 200); $shell->setLayout(new java("org.eclipse.swt.layout.FillLayout")); $button = new Java("org.eclipse.swt.widgets.Button", $this->shell, $SWT->PUSH); $button->setText("Click here."); $button->addSelectionListener(java_closure($this, null, java("org.eclipse.swt.events.SelectionListener"))); $this->shell->open(); }
function createComponents() { $button = new java("javax.swing.JButton", "I'm a Swing button!"); $button->addActionListener(java_closure($this, new JavaClass("java.awt.event.ActionListener"))); $label->setLabelFor($button); $pane = new java("javax.swing.Jpanel", new java("javax.swing.GridLayout", 0, 1)); $pane->add(button); $pane->add(label); $BorderFactory = new JavaClass("javax.swing.BorderFactory"); $pane->setBorder($BorderFactory->createEmptyBorder(30, 30, 10, 30)); return $pane; }
function toString() { global $count; $s = new java("java.lang.String", "hello"); $v = new java("java.lang.String", "hello"); $t = new java("java.lang.String", "hello"); $s = $v = $t = null; if ($count < 10) { $c = $count++; return java_cast(java_closure(), "String") . "{$c}"; } return "leaf"; }
function toString() { global $count; $s = new java("java.lang.String", "hello"); $v = new java("java.lang.String", "hello"); $t = new java("java.lang.String", "hello"); $s = $v = $t = null; if ($count < 2) { $count++; return java_cast(java_closure(), "string"); } echo 'check the server log, it should contain a php.java.bridge.Request$AbortException'; exit(0); return "leaf"; }
#!/usr/bin/php <?php include_once "java/Java.inc"; function x1($s1, $o1) { echo "c1: {$s1}, {$o1}\n"; return 1; } function c2($b) { return !java_values($b); } $here = realpath(dirname($_SERVER["SCRIPT_FILENAME"])); if (!$here) { $here = getcwd(); } java_require("{$here}/../tests.php5/callback.jar"); $closure = java_closure(null, array("c1" => "x1"), java("Callback")); $callbackTest = new java('Callback$Test', $closure); if ($callbackTest->test()) { echo "test okay\n"; exit(0); } else { echo "test failed\n"; exit(1); }
function createHandler() { return java_closure(new HandlerBase(), null, getInterfaces()); }
<?php include_once "java/Java.inc"; $here = getcwd(); java_require("{$here}"); class cg { function toString() { return "cg"; } } class TestClosure { function f() { return new java("java.lang.String", "hello"); } } class TestClosure1 { function g() { return new cg(); } } $c1 = java_closure(new TestClosure(), null, java("TestClosure")); echo $c1->f(); $c1 = java_closure(new TestClosure1(), null, java("TestClosure1")); echo $c1->g();
* When the JavaBridgeRunner is used, there must be exactly one * JavaBridge runner with 6 ContextRunner and ContextFactories. * * In the standalone setup there must be 6 ContextRunner and * ContextFactories and 5 CGIRunners. */ include_once "java/Java.inc"; /* * Call the Java continuation from the PHP continuation. If that * failed, start main(). */ $IRunnable = java("java.lang.Runnable"); if (!java_values(java_context()->getAttribute("name", 100))) { main(); } else { java_context()->call(java_closure(new Runnable(), null, $IRunnable)); } /** * This class implements IRunnable. Its run method is called by each * of the 5 Java threads. Each PHP thread writes $nr to the filename * $name.out. */ class Runnable { function run() { $name = java_values(java_context()->getAttribute("name", 100)); // engine scope $out = new Java("java.io.FileOutputStream", "{$name}.out", true); $Thread = java("java.lang.Thread"); $nr = java_values(java_context()->getAttribute("nr", 100));
function java_call_with_continuation($kontinuation = null) { if (java_getHeader("X_JAVABRIDGE_INCLUDE", $_SERVER) && !java_getHeader("X_JAVABRIDGE_INCLUDE_ONLY", $_SERVER)) { if (is_null($kontinuation)) { java_context()->call(java_closure()); } elseif (is_string($kontinuation)) { java_context()->call(call_user_func($kontinuation)); } elseif ($kontinuation instanceof JavaType) { java_context()->call($kontinuation); } else { java_context()->call(java_closure($kontinuation)); } } }
throw new JavaException("java.lang.Exception", "bleh!"); // not reached echo "ERROR.\n"; exit(3); } function c2($b) { echo "c2: {$b}\n"; return $b; } function c3($e) { echo "c3: {$e}\n"; return 2; } } $here = realpath(dirname($_SERVER["SCRIPT_FILENAME"])); if (!$here) { $here = getcwd(); } java_require("{$here}/callback.jar"); $c = new c(); $closure = java_closure($c, null, java("Callback")); $callbackTest = new java('Callback$Test', $closure); if ($callbackTest->test()) { echo "test okay\n"; exit(0); } else { echo "test failed\n"; exit(1); }
#!/usr/bin/php <?php include_once "java/Java.inc"; function toString() { return "php top level environment"; } function hello($a, $b, $c) { $a = $a ? "true" : "false"; return "Hello java from php: {$a}, {$b}, {$c}"; } // close over the current environment and create a generic // proxy (i.e. a proxy which defines only toString(), equals() and // hashCode()). $environment = java_closure(); // access $environment's invocation handler and invoke hello() $Proxy = new JavaClass("java.lang.reflect.Proxy"); $proc = $Proxy->getInvocationHandler($environment); // implicit toString() should display "php top level environment" echo $environment->__toString(); // invoke java function "hello" which is backed by our php hello() // function echo "\ncalling " . $proc->__toString() . "->invoke(...);\n"; $val = $proc->invoke($environment, "hello", array(true, 7, 3.14)); // should display "Hello java from php" echo "=> " . $val->__toString() . "\n";
<?php include_once "java/Java.inc"; $here = getcwd(); java_require("{$here}/testClosureCache.jar"); function toString() { return "ccl"; } $tc = new Java("TestClosureCache"); "ichild::ccl" == $tc->proc1(java_closure(null, null, java('TestClosureCache$IChild'))) || die(1); "iface::ccl" == $tc->proc1(java_closure(null, null, java('TestClosureCache$IFace'))) || die(2); echo "test okay\n";
try { /* invoke java.lang.System.getProperties() */ $props = java("java.lang.System")->getProperties(); /* convert the result object into a PHP array */ $array = java_values($props); foreach ($array as $k => $v) { echo "{$k}=>{$v}"; echo "<br>\n"; } echo "<br>\n"; /* create a PHP class which implements the Java toString() method */ class MyClass { function toString() { return "hello PHP from Java!"; } } /* create a Java object from the PHP object */ $javaObject = java_closure(new MyClass()); echo "PHP says that Java says: "; echo $javaObject; echo "<br>\n"; echo "<br>\n"; echo java("php.java.bridge.Util")->VERSION; echo "<br>\n"; } catch (JavaException $ex) { echo "An exception occured: "; echo $ex; echo "<br>\n"; }
#!/usr/bin/php <?php include_once "java/Java.inc"; function x1() { echo "x1 called\n"; return true; } $here = realpath(dirname($_SERVER["SCRIPT_FILENAME"])); if (!$here) { $here = getcwd(); } java_require("{$here}/../tests.php5/callback.jar"); $closure = java_closure(null, "x1", java("Callback")); $callbackTest = new java('Callback$Test', $closure); if ($callbackTest->test()) { echo "test okay\n"; exit(0); } else { echo "test failed\n"; exit(1); }