Menu

[r641]: / trunk / php-java-bridge / examples / php+jsp / documentClient.php  Maximize  Restore  History

Download this file

78 lines (64 with data), 2.1 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php require_once("java/Java.inc");
$session = java_session();
java_autoload();
/* The name of the remote document */
$name = "RMIdocument";
/* continue session? */
if(!java_values($doc=$session->get("$name")))
$session->put("$name", $doc=createDocument("$name", array()));
try {
/* add pages to the remote document */
$doc->addPage(new Page(0, "this is page 1"));
$doc->addPage(new Page(0, "this is page 2"));
/* and print a summary */
print java_values($doc->analyze()) . "\n";
} catch (JavaException $ex) {
$cause = $ex->getCause();
echo "Could not access remote document. <br>\n";
echo "$cause <br>\nin file: {$ex->getFile()}<br>\nline:{$ex->getLine()}\n";
$session->destroy();
exit (2);
}
/* destroy the remote document and remove the session */
if($_GET['logout']) {
echo "bye...\n";
destroyDocument($doc);
$session->destroy();
}
/* Utility procedures */
/*
* convenience function which connects to the AS server using the URL
* $url, looks up the service $jndiname and returns a new remote
* document.
* @param jndiname The name of the remote document, see sun-ejb-jar.xml
* @param serverArgs An array describing the connection parameters.
*/
function createDocument($jndiname, $serverArgs) {
// find initial context
$initial = new javax_naming_InitialContext($serverArgs);
try {
// find the service
$objref = $initial->lookup("$jndiname");
// access the home interface
$home = javax_rmi_PortableRemoteObject::type()->narrow($objref,
DocumentHome::type());
if(is_null(java_values($home))) throw new Exception("home");
// create a new remote document and return it
$doc = $home->create();
} catch (JavaException $ex) {
$cause = $ex->getCause();
echo "Could not create remote document. Have you deployed documentBean.jar?<br>\n";
echo "$cause <br>\nin file: {$ex->getFile()}<br>\nline:{$ex->getLine()}\n";
exit (1);
}
return $doc;
}
/*
* convenience function which destroys the reference to the remote
* document
* @param 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.