Source for file JavaBridge.inc

Documentation is available at JavaBridge.inc

  1. <?php /*-*- mode: php; tab-width:4 -*-*/
  2.  
  3.   /* java_JavaBridge.php -- provides the PHP/Java Bridge PHP API.
  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. if(!function_exists("java_get_base")) {
  42.   $version phpversion();
  43.   if ((version_compare("5.1.2"$version">"))) {
  44.     $msg "<br><strong>PHP $version too old.</strong><br>\nFor PHP versions < 5.1.4 install the java.so or php_java.dll from the php-java-bridge-legacy download.<br>\nOr set the path to the PHP executablesee php_exec in the WEB-INF/web.xml";
  45.     die($msg);
  46.   }
  47.   /**
  48.    * @access private
  49.    */
  50.   function java_get_base({
  51.     $ar get_required_files();
  52.     $arLen sizeof($ar);
  53.     if($arLen>0{
  54.       $thiz $ar[$arLen-1];
  55.       return dirname($thiz);
  56.     else {
  57.       return "java/";
  58.     }
  59.   }
  60.   $JAVA_BASE=java_get_base();
  61.   require_once("${JAVA_BASE}/JavaProxy.inc");
  62.  
  63.   /**
  64.    * @access private
  65.    */
  66.   class java_RuntimeException extends Exception {};
  67.   /**
  68.    * @access private
  69.    */
  70.   class java_IllegalStateException extends java_RuntimeException {};
  71.   /**
  72.    * @access private
  73.    */
  74.   class java_IllegalArgumentException extends java_RuntimeException {
  75.     function __construct($ob{
  76.       parent::__construct("illegal argument: ".gettype($ob));
  77.     }
  78.   };
  79.  
  80.  
  81.   /**
  82.    * @access private
  83.    */
  84.   function java_autoload_function($x{
  85.     $str=str_replace("_""."$x);
  86.     $client=__javaproxy_Client_getClient();
  87.     if(!($client->invokeMethod(0"typeExists"array($str)))) return false;
  88.     $instance "class ${x} extends Java {".
  89.       "static function type(\$sub=null){if(\$sub) \$sub='\$'.\$subreturn java('${str}'.\"\$sub\");}".
  90.       'function __construct() {$args = func_get_args();'.
  91.       'array_unshift($args, '."'$str'".'); parent::__construct($args);}}';
  92.     eval ("$instance");
  93.     return true;
  94.   }
  95.  
  96.   /**
  97.    * Load a set of java libraries and make them available in the current name space.
  98.    * Available since php 5.2.0. Example:
  99.    * <code>
  100.    * java_autoload("itext.jar;log4j.jar");
  101.    * $byte = java_lang_Byte::type()->TYPE;
  102.    * $reader = new com_lowagie_text_pdf_PdfReader("mypdf.pdf");
  103.    * ...
  104.    *</code>
  105.    * @param $libs The libraries separated by a semicolon
  106.    * @access public
  107.    */
  108.   function java_autoload($libs=null{
  109.     static $once false;
  110.     if($once
  111.       throw new java_IllegalStateException("java_autoload called more than once");
  112.     $once true;
  113.     java_require($libs);
  114.     if(function_exists("spl_autoload_register")) {
  115.       spl_autoload_register("java_autoload_function");
  116.     else {
  117.       function __autoload($x{
  118.         return java_autoload_function($x);
  119.       }
  120.     }
  121.   }
  122.  
  123.   /**
  124.    * Access the java type with the given name.
  125.    *
  126.    * Example: <code> java("java.lang.System")->getProperties(); </code>
  127.    *
  128.    * @access public
  129.    * @param $name The type name
  130.    */
  131.   function Java($name
  132.     static $classMap array();
  133.     if(array_key_exists($name$classMap)) return $classMap[$name];
  134.     return $classMap[$name]=new JavaClass($name);
  135.   }
  136.   /**
  137.    * Alias for java_closure();
  138.    * @access private
  139.    * @see #java_closure();
  140.    */
  141.   function java_get_closure({return java_closure_array(func_get_args());}
  142.   
  143.   /**
  144.    * Alias for java_values();
  145.    * @access private
  146.    * @see #java_values();
  147.    */
  148.   function java_get_values($argreturn java_values($arg)}
  149.  
  150.   /**
  151.    * Alias for java_session();
  152.    * @access private
  153.    * @see #java_session();
  154.    */
  155.   function java_get_session({return java_session_array(func_get_args());}
  156.  
  157.   /**
  158.    * Alias for java_context();
  159.    * @access private
  160.    * @see #java_context();
  161.    */
  162.   function java_get_context({return java_context()}
  163.  
  164.   /**
  165.    * Alias for java_server_name();
  166.    * @access private
  167.    * @see #java_server_name();
  168.    */
  169.   function java_get_server_name(return java_server_name()}
  170.  
  171.   /**
  172.    * Alias for java_is_null();
  173.    * @access private
  174.    * @see #java_is_null();
  175.    */
  176.   function java_isnull($valuereturn is_null (java_values ($value))}
  177.  
  178.   /**
  179.    * Checks whether a value is null or not.
  180.    *
  181.    * Example: <code> java_is_null(java("java.lang.System")->;getProperty("foo")) </code>
  182.    *
  183.    * @access public
  184.    * @param $value A Java object or a PHP value
  185.    * @return true if $value is the PHP or Java null value.
  186.    */
  187.   function java_is_null($valuereturn is_null (java_values ($value))}
  188.  
  189.   /**
  190.    * Alias for java_set_file_encoding();
  191.    * @access private
  192.    * @see #java_set_file_encoding();
  193.    */
  194.   function java_set_encoding($encreturn java_set_file_encoding ($enc)}
  195.  
  196.   /**
  197.    * @deprecated: Use java_require() instead.
  198.    * @access private
  199.    * @see #java_require();
  200.    */
  201.   function java_set_library_path($argreturn java_require($arg)}
  202.  //!java_defined  DO NOT REMOVE THIS LINE
  203. ?>

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