#!/usr/bin/php <?php include_once "java/Java.inc"; $ar = array(1, 2, 3, 5, 7, 11, -13, -17.01, 19); unset($ar[1]); $v = new java("java.util.Vector", $ar); $Arrays = new java_class("java.util.Arrays"); $l = $Arrays->asList($ar); $v->add(1, null); $l2 = $v->sublist(0, $v->size()); echo java_cast($l, "S") . "\n" . java_cast($l2, "S") . "\n"; $res1 = java_values($l); $res2 = java_values($l2); $res3 = array(); $res4 = array(); $i = 0; foreach ($v as $key => $val) { $res3[$i++] = java_values($val); } for ($i = 0; $i < java_values($l2->size()); $i++) { $res4[$i] = java_values($l2[$i]); } if (!$l->equals($l2)) { echo "ERROR\n"; exit(1); } if (java_values($l[1]) != null || (string) $res3 != (string) $res1 || (string) $res4 != (string) $res1) { echo "ERROR\n"; exit(2); }
#!/usr/bin/php <?php include_once "java/Java.inc"; $here = realpath(dirname($_SERVER["SCRIPT_FILENAME"])); if (!$here) { $here = getcwd(); } $Array = new java_class("ArrayArray"); $arrayArray = $Array->create(10); $String = new java_class("java.lang.String"); for ($i = 0; $i < 10; $i++) { $ar = $arrayArray[$i]->array; echo java_cast($ar, "S") . " " . java_cast($ar[0], "S") . "\n"; } echo "\n"; foreach ($arrayArray as $value) { $ar = $value->array; echo java_cast($ar, "S") . " " . java_cast($ar[0], "S") . "\n"; }
#!/usr/bin/php <?php include_once "java/Java.inc"; $Object = new java_class("java.lang.Object"); $ObjectC = new JavaClass("java.lang.Object"); $object = $Object->newInstance(); // test __toString() // should display "class java.lang.Object" echo $Object; echo "\n"; // test cast to string // should display "class java.lang.Object" echo "" . $Object->__toString() . "\n"; echo "" . $ObjectC->__toString() . "\n"; echo $object->__toString() . "\n";
#!/usr/bin/php <?php include_once "java/Java.inc"; $j_tfClass = new java_class("javax.xml.transform.TransformerFactory"); $j_tf = $j_tfClass->newInstance(); // create a svg picture with an ellipse in it // and print it out $FactoryClass = new JavaClass("javax.xml.parsers.DocumentBuilderFactory"); $factory = $FactoryClass->newInstance(); $builder = $factory->newDocumentBuilder(); $myDocument = $builder->newDocument(); $svgElement = $myDocument->createElementNS("http://www.w3.org/2000/svg", "svg"); $myDocument->appendChild($svgElement); $svgElement->setAttribute("width", "4cm"); $svgElement->setAttribute("height", "8cm"); $ellipseElement = $myDocument->createElementNS("http://www.w3.org/2000/svg", "ellipse"); $ellipseElement->setAttribute("cx", "2cm"); $ellipseElement->setAttribute("cy", "4cm"); $ellipseElement->setAttribute("rx", "2cm"); $ellipseElement->setAttribute("ry", "1cm"); $svgElement->appendChild($ellipseElement); $TransformerFactory = new JavaClass("javax.xml.transform.TransformerFactory"); $transFactory = $TransformerFactory->newInstance(); $myTransformer = $transFactory->newTransformer(); $src = new java("javax.xml.transform.dom.DOMSource", $myDocument); // print the picture to a memory buffer and return the contents of the // buffer to the client. $memoryStream = new java("java.io.ByteArrayOutputStream"); $streamResult = new java("javax.xml.transform.stream.StreamResult", $memoryStream); $myTransformer->transform($src, $streamResult);
#!/usr/bin/php <?php include_once "java/Java.inc"; $Array = new java_class("java.lang.reflect.Array"); $String = new java_class("java.lang.String"); $entries = $Array->newInstance($String, 8); $entries[0] = "Jakob der Lügner, Jurek Becker 1937--1997"; $entries[1] = "Mutmassungen über Jakob, Uwe Johnson, 1934--1984"; $entries[2] = "Die Blechtrommel, Günter Grass, 1927--"; $entries[3] = "Die Verfolgung und Ermordung Jean Paul Marats dargestellt durch die Schauspielgruppe des Hospizes zu Charenton unter Anleitung des Herrn de Sade, Peter Weiss, 1916--1982"; $entries[4] = "Der Mann mit den Messern, Heinrich Böll, 1917--1985"; $entries[5] = "Biedermann und die Brandstifter, Max Frisch, 1911--1991"; $entries[6] = "Seelandschaft mit Pocahontas, Arno Schmidt, 1914--1979"; for ($i = 0; $i < java_values($Array->getLength($entries)); $i++) { echo "{$i}: {$entries[$i]}\n"; }
#!/usr/bin/php <?php include_once "java/Java.inc"; $class = new java_class("java.lang.Class"); $arr = java_get_values($class->getConstructors()); if (0 == sizeof($arr)) { echo "test okay\n"; exit(0); } echo "error\n"; exit(1);
#!/usr/bin/php <?php include_once "java/Java.inc"; ini_set("max_execution_time", 0); if ($argc < 2) { echo "No automatic test. Use php swing-button.php --force to run this test.\n"; exit(0); } $here = realpath(dirname($_SERVER["SCRIPT_FILENAME"])); if (!$here) { $here = getcwd(); } $Array = new java_class("ArrayArray"); $n = 60; $arrayArray = $Array->create($n); // Keep-Alive default is 15s, the following tests if the client // re-opens the connection (the test will dump core if not). $String = new java_class("java.lang.String"); for ($i = 0; $i < $n; $i++) { $ar = $arrayArray[$i]->array; echo $n - $i - 1 . " "; sleep(1); } echo "\n";
#!/usr/bin/php <?php include_once "java/Java.inc"; $here = realpath(dirname($_SERVER["SCRIPT_FILENAME"])); if (!$here) { $here = getcwd(); } $ArrayToString = new java_class("ArrayToString"); // create long array ... $length = 10; for ($i = 0; $i < $length; $i++) { $arr[$i] = $i; } // ... and post it to java. Should print integers print "integer array: " . java_values($ArrayToString->arrayToString($arr)) . "<br>\n"; // double for ($i = 0; $i < $length; $i++) { $arr[$i] = $i + 1.23; } // should print doubles print "double array: " . java_values($ArrayToString->arrayToString($arr)) . "<br>\n"; // boolean for ($i = 0; $i < $length; $i++) { $arr[$i] = $i % 2 ? true : false; } // should print booleans print "boolean array: " . java_values($ArrayToString->arrayToString($arr)) . "<br>\n";