Menu

[r411]: / trunk / php-java-bridge / examples / j2ee / documentClient.php4  Maximize  Restore  History

Download this file

123 lines (101 with data), 3.8 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
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
define("JBOSS",1);
define("WEBSPHERE",2);
define("SUN",3);
define("ORACLE",4);
// -------------- adjust these variables, if necessary
$server=array_key_exists(1, $argv)? $argv[1] : JBOSS;
$WAS_HOME=array_key_exists(2, $argv)? $argv[2]: "/opt/IBM/WebSphere/AppServer";
$JBOSS_HOME=array_key_exists(2, $argv)? $argv[2] : "/opt/jboss-4.0.2/";
$app_server=array_key_exists(2, $argv)? $argv[2] : getenv("HOME")."/SUNWappserver";
// ---------------
$System = new JavaClass("java.lang.System");
$props = $System->getProperties();
echo "Using java VM from: ${props['java.vm.vendor']}\n";
echo "connecting to server: ";
$clientJar = getcwd() . "/documentBeanClient.jar";
switch($server) {
case JBOSS:
echo "jboss. Loading $JBOSS_HOME/lib \n";
$vendor=new java("java.lang.String", strtolower($props['java.vm.vendor']));
if(!$vendor->startsWith("sun"))
echo "WARNING: You need to run this example with the SUN VM\n";
if(!is_dir($JBOSS_HOME)) die("ERROR: Incorrect $JBOSS_HOME.");
$name = "DocumentEJB";
java_require("$JBOSS_HOME/client/;$clientJar");
$server=array("java.naming.factory.initial"=>
"org.jnp.interfaces.NamingContextFactory",
"java.naming.provider.url"=>
"jnp://127.0.0.1:1099");
break;
case WEBSPHERE:
echo "websphere. Loading $WAS_HOME/lib/\n";
$vendor=new java("java.lang.String", strtolower($props['java.vm.vendor']));
if(!$vendor->startsWith("ibm"))
echo "WARNING: You need to run this example with the IBM VM\n";
if(!is_dir($WAS_HOME)) die("ERROR: Incorrect $WAS_HOME.");
$name = "RMIdocument";
java_require("$WAS_HOME/lib/;$clientJar");
$server=array("java.naming.factory.initial"=>
"com.ibm.websphere.naming.WsnInitialContextFactory",
"java.naming.provider.url"=>
"iiop://localhost:2809");
break;
case SUN:
echo "sun. Loading: $app_server/lib\n";
$vendor=new java("java.lang.String", strtolower($props['java.vm.vendor']));
if(!$vendor->startsWith("sun"))
echo "WARNING: You need to run this example with the SUN VM\n";
if(!is_dir($app_server)) die("ERROR: Incorrect $app_server.");
$name = "RMIdocument";
java_require("$app_server/lib/;$clientJar");
$server=array("java.naming.factory.initial"=>
"com.sun.jndi.cosnaming.CNCtxFactory",
"java.naming.provider.url"=>
"iiop://localhost:3700");
break;
}
java_last_exception_clear();
$doc=@createDocument($name, $server);
$e=java_last_exception_get();
if($e) {
echo "Could not create remote document. Have you deployed documentBean.jar?\n";
echo $e->getCause() ."\n";
exit (1);
}
/* add pages to the remote document */
$doc->addPage(new java ("Page", 0, "this is page 1"));
$doc->addPage(new java ("Page", 0, "this is page 2"));
/* and print a summary */
print $doc->analyze() . "\n";
destroyDocument($doc);
/* 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 java("javax.naming.InitialContext", $serverArgs);
// find the service
$objref = $initial->lookup("$jndiname");
// access the home interface
$DocumentHome = new JavaClass("DocumentHome");
$PortableRemoteObject = new JavaClass("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
* @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.