Menu

[r248]: / trunk / php-java-bridge / examples / j2ee / globals.php  Maximize  Restore  History

Download this file

50 lines (40 with data), 1.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
// please adjust the following line if your server runs on a different host
$app_url="iiop://localhost:3700"; // e.g.: "iiop://192.168.5.1:3700";
$here=trim(`pwd`);
$client="$here/documentBeanClient.jar";
$j2ee_jar="$here/j2ee.jar";
java_set_library_path("$client;$j2ee_jar");
/*
* convenience function which connects to the AS server using the URL
* $url, looks up the service $jndiname and returns a new remote
* document.
*/
function createDocument($url, $jndiname) {
/*
* Set up the initial context. The following code is AS
* specific, WebLogic for example uses a different URL.
* Please consult your AS documentation for details.
*/
$env = new java("java.util.Properties");
$env->put("java.naming.factory.initial", "com.sun.jndi.cosnaming.CNCtxFactory");
$env->put("java.naming.provider.url", $url);
$initial = new java("javax.naming.InitialContext", $env);
// find the service
$objref = $initial->lookup($jndiname);
// access the home interface
$DocumentHome = new java_class("DocumentHome");
$PortableRemoteObject = new java_class("javax.rmi.PortableRemoteObject");
$home = $PortableRemoteObject->narrow($objref, $DocumentHome);
// create a new remote document and return it
$doc = $home->create();
return $doc;
}
/*
* convenience function which destroys the reference to the remote
* document
*/
function destroyDocument($doc) {
$doc->remove();
}
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.