/JavaProxy.inc

Description
Classes
Class Description
java_JavaType Implemented by JavaException and Java.
Java The Java proxy class.
JavaException The java exception proxy.
Includes
require_once ("${JAVA_BASE}/Client.inc") (line 41)
Functions
java_begin_document (line 492)

Enters stream mode (asynchronuous protocol).

Enters stream mode (asynchronuous protocol). The statements are sent to the back-end in one XML stream. Use this protocol mode when you have a large number of set operations and you don't expect an exception. Any exception raised during stream mode is reported when java_end_document() is called.

  • access: public
void java_begin_document ()
java_cast (line 253)

Converts the java object obj into a PHP value.

Converts the java object obj into a PHP value. This procedure converts the Java argument and then calls java_values() to fetch its content. Use java_values() if the conversion is not necessary. The second argument must be [s]tring, [b]oolean, [i]nteger, [f]loat or [d]ouble, [a]rray, [n]ull or [o]bject (which does nothing).
Example:

  1.  $str new java("java.lang.String""12");
  2.  echo is_string ($str"#t":"#f";
  3.  => #f
  4.  $phpString = (string)$str;
  5.  echo is_string ($phpString"#t":"#f";
  6.  => #t
  7.  $phpNumber = (integer)(string)$str;
  8.  echo $phpNumber;
  9.  => 12
  10.  $phpNumber2 java_cast($str"integer");
  11.  echo $phpNumber2;
  12.  => 12

void java_cast (object A $object, string $type)
  • object A $object: java object
  • string $type: A PHP type description, either [Ss]tring, [Bb]oolean, [Ll]ong or [Ii]nteger, [Dd]ouble or [Ff]loat, [Nn]ull, [Aa]rray, [Oo]bject.
java_closure (line 476)

Wraps a PHP environment.

Wraps a PHP environment. Closes over the php environment and packages it up as a java class. Use java_closure() to convert a PHP object into an equivalent Java object. Example:

  1.  function toString({return "helloWorld";};
  2.  $object java_closure();
  3.  echo "Java says that PHP says: $object\n";
When a php instance is supplied as an argument, the instance will be used instead. When a string or key/value map is supplied as a second argument, the java procedure names are mapped to the php procedure names. Example:
  1.  function hello({return "hello";};
  2.  echo (string)java_closure(null"hello");
When an array of java interfaces is supplied as a third argument, the environment must implement these interfaces. Example:
  1.  class Listener {
  2.    function actionPerformed($actionEvent{
  3.        ...
  4.      }
  5.  }
  6.  function getListener({
  7.      return java_closure(new Listener()nullarray(new Java("java.awt.event.ActionListener")));
  8.  }

void java_closure ()
java_context (line 411)

Returns the jsr223 script context handle.

Returns the jsr223 script context handle. Example which closes over the current environment and passes it back to java:

  1.  define ("ENGINE_SCOPE"100);
  2.  $ctx java_context();
  3.  if(java_is_false($ctx->call(java_closure()))) die "Script should be called from java";
A second example which shows how to invoke PHP methods without the JSR 223 getInterface() and invokeMethod() helper procedures:
  1.  String s = "<?php class Runnable function run({...} };
  2.             // example which captures an environment and
  3.             // passes it as a continuation back to Java
  4.             $Runnable java('java.lang.Runnable');
  5.             $closure java_closure(new Runnable()null$Runnable);
  6.             java_context()->setAttribute("kont"$closureENGINE_SCOPE);
  7.             java_context()->call($closure);
  8.             ?>";
  9.  ScriptEngine e = new ScriptEngineManager().getEngineByName("php-invocable");
  10.  e.eval (s);
  11.  Runnable r = e.get("kont");
  12.  new Thread(r).start();
It is possible to access implicit web objects (the session, the application store etc.) from the context. Please see the JSR223 documentation for details. Example:
  1.  $req $ctx->getHttpServletRequest();
  2.  $res $ctx->getHttpServletResponse();
Example which fetches the servlet-, config and context:
  1.  $config $ctx->getAttribute "php.java.servlet.ServletConfig",  ENGINE_SCOPE);
  2.  $context $ctx->getAttribute"php.java.servlet.ServletContext"ENGINE_SCOPE);
  3.  $servlet $ctx->getAttribute"php.java.servlet.Servlet"ENGINE_SCOPE);

void java_context ()
java_end_document (line 507)

Ends stream mode.

Ends stream mode. Fires a JavaException if any statement executed during stream mode raised an exception.

  • access: public
void java_end_document ()
java_inspect (line 151)

Returns the contents (public fields, public methods, public classes) of object as a string.

Returns the contents (public fields, public methods, public classes) of object as a string. Example:

  • access: public
void java_inspect (object A $object)
  • object A $object: java object or type.
java_instanceof (line 194)

Tests if object is an instance of clazz.

Tests if object is an instance of clazz. Example:

  1.  return($o instanceof Java && $c instanceof Java && java_instanceof($o$c));

  • access: public
void java_instanceof (object A $ob, object A $clazz)
  • object A $ob: java object
  • object A $clazz: java object or type.
java_require (line 281)

Set the library path.

Set the library path. Example:

  1.  java_require("foo.jar;bar.jar");
The .jar files should be stored in /usr/share/java or extension_dir/lib one of its sub-directories or under the PHP include_path/LIBNAME/LIBNAME.jar. However, it is also possible to fetch .jar files from a remote server, for example:
  1.  java_require("http://php-java-bridge.sf.net/kawa.jar;...");
Note that Java doesn't have a module system. Therefore libraries and their dependencies must be loaded by one and only one class loader; do not report a ClassCastException saying that a class is incompatible to itself or a NoClassDefFoundError to the PHP/Java Bridge mailing list.

void java_require (string $arg)
  • string $arg: The list of Java libraries.
java_reset (line 126)

Only for internal use.

Only for internal use.

  • access: public
void java_reset ()
java_server_name (line 357)

Returns the name of the back-end or null, if the back-end is not running.

Returns the name of the back-end or null, if the back-end is not running.O Example:

  1.  $backend java_server_name();
  2.  if(!$backendwakeup_administrator("back-end not running");
  3.  echo "Connected to the back-end: $backend\n";

  • access: public
void java_server_name ()
java_session (line 342)

Return a session handle.

Return a session handle. When java_session() is called without arguments, the session is shared with java. Example:

  1.  java_session()->put("key"new Java("java.lang.Object"));
  2.  [...]
The java components (jsp, servlets) can retrieve the value, for example with:
  1.  getSession().getAttribute("key");
When java_session() is called with a session name, the session is not shared with java and no cookies are set. Example:
  1.  java_session("myPublicApplicationStore")->put("key""value");
When java_session() is called with a second argument set to true, a new session is allocated, the old session is destroyed if necessary. Example:
  1.  java_session(nulltrue)->put("key""val");
The optional third argument specifies the default lifetime of the session, it defaults to
  1.  session.gc_maxlifetime
. The value 0 means that the session never times out.

void java_session ()
java_set_file_encoding (line 169)

Set the java file encoding, for example UTF-8 or ASCII.

Set the java file encoding, for example UTF-8 or ASCII. Needed because php does not support unicode. All string to byte array conversions use this encoding. Example:

  1.  java_set_file_encoding("ISO-8859-1");

  • access: public
void java_set_file_encoding (string $enc)
  • string $enc: A valid file.encoding string. Please see your Java
    1. file.encoding
    documentation for a list of valid encodings.
java_values (line 119)

Unwraps a Java object.

Unwraps a Java object. Evaluates the object and fetches its content, if possible. Use java_values() to convert a Java object into an equivalent PHP value. A java array, Map or Collection object is returned as a php array. An array, Map or Collection proxy is returned as a java array, Map or Collection object, and a null proxy is returned as null. All values of java types for which a primitive php type exists are returned as php values. Everything else is returned unevaluated. Please make sure that the values do not not exceed php's memory limit. Example:

  1.  $str new java("java.lang.String""hello");
  2.  echo java_values($str);
  3.  => hello
  4.  $chr $str->toCharArray();
  5.  echo $chr;
  6.  => [o(array_of-C):"[C@1b10d42"]
  7.  $ar java_values($chr);
  8.  print $ar;
  9.  => Array
  10.  print $ar[0];
  11.  => [o(Character):"h"]
  12.  print java_values($ar[0]);
  13.  => h

void java_values (object A $object)
  • object A $object: java object or type.

Documentation generated on Mon, 05 Jan 2009 21:10:56 +0100 by phpDocumentor 1.4.2