Oracle8i Enterprise JavaBeans and CORBA Developer's Guide
Release 8.1.5

A64683-01

Library

Product

Contents

Index

Prev  Chap Top Next

Basic Examples

Here is the README for the basic examples:

The examples in the basic/ directories demonstrate various CORBA 
programming techniques that you can use to write CORBA server 
objects, as well as the client code that calls the server object. 

The examples are short, and each example shows just one or two aspects
of Oracle8i CORBA programming. The examples come with either a
standard Makefile (UNIX) or a batch file (Windows NT) that will
perform all the steps required to compile, load, and run the example.

To run an example, you must have access to an Oracle8i database 
server that hosts the Oracle8i server-side Java VM, and that has 
the standard SCOTT demo schema installed. Some of the examples 
use the EMP and DEPT demo tables in the SCOTT schema. 

The SCOTT schema must also have write access to the CORBA name space
starting at the 'test' directory, which is true of the install database.
The tables that support the publishing directories are established when
your Oracle8i system with the Java option is built. You can use the
Session Shell to verify the presence of the test directory. See the
Oracle8i EJB and CORBA Developer's Guide for information about the
Session Shell.

You must also have the INIT.ORA, tnsnames.ora, and listener.ora files
configured properly to accept both standard listener and IIOP incoming
connections which is done for you in the install database. See the
Oracle8i Net8 Administrator's Guide for information about setting up
these files.

Each example publishes one or more objects in the database. To lookup
and activate the published object, the client uses the Oracle8i JNDI
interface to the CosNaming implementation. The examples all connect
using the SCOTT as the username, TIGER as the password, and for
simplicity, NON_SSL_LOGIN as the connection protocol.

The makefiles/batch files provided with the examples expect that you
have the java and javac programs from the Sun JDK 1.1.3 (beta) or JDK
1.1.6 (production) in your PATH.  They also expect that your CLASSPATH
contains the Java runtime classes (classes.zip) corresponding to your
java interpreter.  The UNIX makefiles abd NT batch files take care of
adding the ORACLE specific jar and zip files to your CLASSPATH.

For your reference here is a list of jar and zip files that the
makefiles/batch files use:

ORACLE_HOME/lib/aurora_client.jar       # Oracle 8i ORB runtime
ORACLE_HOME/lib/aurora.jar              # Oracle 8i in-the-database runtime
ORACLE_HOME/jdbc/lib/classes111.zip     # for JDBC examples
ORACLE_HOME/sqlj/lib/translator.zip     # for SQLJ examples
ORACLE_HOME/lib/vbjapp.jar              # Inprise VisiBroker library
ORACLE_HOME/lib/vbjorb.jar              # VisiBroker library
ORACLE_HOME/lib/vbj30ssl.jar            # required if you modify any
                                        # client code to use SSL


The example programs are:

helloworld - The CORBA version of {printf("Hello world!");}. Look at
             this example first

bank       - an Oracle8i-compatible version of the VisiBroker Bank
             example.

sqljimpl   - Uses server-side JDBC to retrieve data from a database
             server.  Uses the SQLJ preprocessor.  Demonstrates CORBA
             structs, sequences and exceptions.

jdbcimpl   - Like sqljimpl, but uses the more verbose JDBC syntax to retrieve
             the data.
             
factory    - Oracle8i implementation of the factory design pattern.

lookup     - Demonstrates one CORBA server object activating and
             calling an other CORBA object in its own session.
             Also demonstrates CORBA structs and sequences.
             
callback   - Shows how to call a client from a server object.

printback  - Shows how to print data from a server object 
             on the client console or screen.

tieimpl    - Demonstrates using the CORBA TIE (delegation) method
             instead of inheritance to code a CORBA object. This
             is the helloworld example done with TIE rather than 
             inheritance.
             

The code in the examples is not always commented, but each of the
examples has its own readme file. The readme explains what the code
does, and points out any special features used in the example.

Each of these examples has been tested on Solaris 2.6 and Windows 
NT 4.0. If you have problems compiling or running the examples on 
these or on another supported platform, please inform your Oracle 
support representative.

helloworld

readme.txt

Overview
========

This is a very simple CORBA example. The helloWorld server object merely
returns a greeting plus the Java VM version number to the client.

The purpose of the example is to show the minimum code needed to
lookup a published object, activate it by invoking a method on it, and
use the value that the method returns on the client side.

Note that the name of the object as published in the database is 'myHello',
and not the class name 'HelloImpl'. The name of the published object is
completely independent of its class name. In this and other examples, the only
place that the published object name is visible is in the Makefile or the
runit.bat batch file, in the publish and run targets.

Note also that the publish command passes in the name of the CORBA helper
class. The ORB on the server side uses the helper object to narrow the object
that it looks up to the appropriate type.


Source files
============

hello.idl
------------

The CORBA IDL for the example.  Defines a single interface Hello with a single
method helloWorld(). The interface is defined in the Module named 'hello',
which determines the name of the directory in which the idl2java compiler
places the generated files.

The helloWorld() method returns a CORBA wstring, which maps to a Java String
type:

module hello
  interface Hello
    wstring helloWorld()


Client.java
-----------


You invoke the client program from a command prompt, and pass it four
arguments, the

   - service URL (service ID, hostname, port, and SID if port is a listener)
   - name of the published bean to lookup and instantiate
   - username
   - password that authenticates the client to the Oracle8i database server

For example:
% java -classpath LIBs Client sess_iiop://localhost:2222 /test/myHello scott 
tiger

where LIBs is the classpath that must include

$ORACLE_HOME/lib/aurora_client.jar
$ORACLE_HOME/jdbc/lib/classes111.zip
$ORACLE_HOME/lib/vbjorb.jar
$ORACLE_HOME/lib/vbjapp.jar
$JAVA_HOME/lib/classes.zip

(Note: for NT users, the environment variables would be %ORACLE_HOME% and
%JAVA_HOME%.)

The client code performs the following steps:

   - gets the arguments passed on the command line
   - creates a new JNDI Context (InitialContext())
   - looks up the published CORBA server object to find and activate it
   - invokes the helloWorld() method on the hello object and prints the results

The printed output is:

Hello client, your javavm version is 8.1.5.



helloServer/HelloImpl.java
--------------------------

Implements the IDL-specified Hello interface. The interface has one
method, helloWorld(), that returns a String to the caller.

helloWorld() invokes System.getProperty("oracle.server.version") to get the
version number of the Java VM.

This object performs no database access.



Compiling and Running the Example
=================================


UNIX
----

Enter the command 'make all' or simply 'make' in the shell to compile,
load, and deploy the objects, and run the client program.  Other
targets are 'run' and 'clean'.

Make sure that a shell environment variable ORACLE_HOME is set to
point to the home location of the Oracle installation. This is
operating system dependent, so see the Installation documentation that
came with your system for the location. Also, review the README file
for the Oracle database, and the README file for the CORBA/EJB server
(the Oracle8i ORB), for additional up-to-date information.


Windows NT
----------

On Windows NT, run the batch file makeit.bat from a DOS command prompt
to compile, load, and deploy the objects. Run the batch file runit.bat
to run the client program, and see the results.


Make sure that the environment variables %ORACLE_HOME%, %CLASSPATH%,
and %SERVICE% are set appropriately for the DOS command window. You
can set these as either user or system environment variables from the
Control Panel. Double click on System in the Control Panel then on
the Environment tab to set these variables. Start a new DOS window
after setting environment variable values.


See the Installation documentation that came with your Oracle8i system
for the values of these variables. Also, review the README file for
the Oracle database, and the README file for the CORBA/EJB server (the
Oracle8i ORB), for additional up-to-date information.

You can also set an environment variable %JAVA_HOME% to point to the
root of your Java JDK. For example, SET JAVA_HOME=C:\JDK1.1.6.

hello.idl

module hello {
  interface Hello {
    wstring helloWorld ();
  };
};

Client.java

import hello.Hello;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class Client
{
  public static void main (String[] args) throws Exception {
    if (args.length != 4) {
      System.out.println("usage: Client serviceURL objectName user password");
      System.exit(1);
    }
    String serviceURL = args [0];
    String objectName = args [1];
    String user = args [2];
    String password = args [3];

    Hashtable env = new Hashtable();
    env.put(Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put(Context.SECURITY_PRINCIPAL, user);
    env.put(Context.SECURITY_CREDENTIALS, password);
    env.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    Context ic = new InitialContext(env);

    Hello hello = (Hello) ic.lookup(serviceURL + objectName);
    System.out.println(hello.helloWorld());
  }
}

helloServer/HelloImpl.java

package helloServer;

import hello.*;

public class HelloImpl extends _HelloImplBase {
  public String helloWorld() {
    String v = System.getProperty("oracle.server.version");
    return "Hello client, your javavm version is " + v + ".";
  }
}

sqljimpl

readme.txt

Overview
========

The example shows:

    - how to use the SQLJ translator on the server side to query data from the
        EMP table.
    - returning complex data to the client using an IDL struct/Java class

This example is a SQLJ version of the jdbcimpl example. It is useful to
compare the two examples.


Source files
============

employee.idl
------------

See the employee.idl description in ../jdbcimpl/readme.txt.


Client.java
-----------

Invoke the client program from a command prompt, and pass it four arguments,
the

   - service URL (service ID, hostname, port, and SID if port is a listener)
   - name of the published bean to lookup and instantiate
   - username
   - password that authenticates the client to the Oracle8i database server

For example:
% java -classpath LIBs Client sess_iiop://localhost:2222 /test/myHello scott 
tiger

where LIBs is the classpath that must include

$ORACLE_HOME/lib/aurora_client.jar
$ORACLE_HOME/jdbc/lib/classes111.zip
$ORACLE_HOME/lib/vbjorb.jar
$ORACLE_HOME/lib/vbjapp.jar
$JAVA_HOME/lib/classes.zip


The client code performs the following steps:

   - gets the arguments passed on the command line
   - creates a new JNDI Context (InitialContext())
   - looks up the published Employee CORBA server object to find and activate it
   - invokes the getEmployee() method, with the parameter "SCOTT", to
       return Scott's employee ID and salary
   - prints the result        
   - tries to use getEmployee("bogus") to return information about
       employee named bogus. This will fail, and return the SQLError
       exception, which is printed.

The printed output is:

SCOTT 7788 3000.0
Error retrieving employee "bogus": no rows found for select into statement


employeeServer/EmployeeImpl.java
--------------------------------

This class implements the Employee interface. The getEmployee() method
simply declares two variables to hold the empno and sal information
from the EMP table. The method then defines and calls a SQLJ statement
that selects information about the employee named in the input
parameter into the variables, constructs a new EmployeeInfo object
using the query information, and returns it to the invoker.

It is instructive to contrast this example with the jdbcimpl example,
which uses JDBC rather than SQLJ to query the database.

You can also contrast this example with the lookup example, which uses a SQLJ
iterator to retrieve a multi-row result set from the database.


Compiling and Running the Example
=================================

UNIX
----

Enter the command 'make all' or simply 'make' in the shell to compile,
load, and deploy the objects, and run the client program.  Other
targets are 'run' and 'clean'.

Make sure that a shell environment variable ORACLE_HOME is set to
point to the home location of the Oracle installation. This is
operating system dependent, so see the Installation documentation that
came with your system for the location. Also, review the README file
for the Oracle database, and the README file for the CORBA/EJB server
(the Oracle8i ORB), for additional up-to-date information.


Windows NT
----------

On Windows NT, run the batch file makeit.bat from a DOS command prompt
to compile, load, and deploy the objects. Run the batch file runit.bat
to run the client program, and see the results.


Make sure that the environment variables %ORACLE_HOME%, %CLASSPATH%,
and %SERVICE% are set appropriately for the DOS command window. You
can set these as either user or system environment variables from the
Control Panel. Double click on System in the Control Panel then on
the Environment tab to set these variables. Start a new DOS window
after setting environment variable values.


See the Installation documentation that came with your Oracle8i system
for the values of these variables. Also, review the README file for
the Oracle database, and the README file for the CORBA/EJB server (the
Oracle8i ORB), for additional up-to-date information.

You can also set an environment variable %JAVA_HOME% to point to the
root of your Java JDK. For example, SET JAVA_HOME=C:\JDK1.1.6.

employee.idl

module employee {
  struct EmployeeInfo {
    wstring name;
    long number;
    double salary; 
  };

  exception SQLError {
    wstring message;
  };

  interface Employee {
    EmployeeInfo getEmployee (in wstring name) raises (SQLError);
  };
};

Client.java

import employee.*;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class Client
{
  public static void main (String[] args) throws Exception {
    if (args.length != 4) {
      System.out.println ("usage: Client serviceURL objectName user password");
      System.exit (1);
    }
    String serviceURL = args [0];
    String objectName = args [1];
    String user = args [2];
    String password = args [3];

    Hashtable env = new Hashtable ();
    env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put (Context.SECURITY_PRINCIPAL, user);
    env.put (Context.SECURITY_CREDENTIALS, password);
    env.put (Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    Context ic = new InitialContext (env);

    try {
      Employee employee = (Employee)ic.lookup (serviceURL + objectName);
      EmployeeInfo info = employee.getEmployee ("SCOTT");
      System.out.println (info.name + " " + info.number + " " + info.salary);
      // This one will fail and raise a SQLError exception
      EmployeeInfo info2 = employee.getEmployee ("bogus");
      System.out.println (info.name + " " + info.number + " " + info.salary);
    } catch (SQLError e) {
      System.out.println ("Error retrieving employee \"bogus\": " + e.message);
    }
  }
}

employeeServer/employeeImpl.sqlj

package employeeServer;

import employee.*;
import oracle.aurora.AuroraServices.ActivatableObject;
import java.sql.*;

public class EmployeeImpl 
       extends _EmployeeImplBase 
       implements ActivatableObject 
{
  public EmployeeInfo getEmployee (String name) throws SQLError {
    try {
      int empno = 0;
      double salary = 0.0;
      #sql { select empno, sal into :empno, :salary from emp
	            where ename = :name };
      return new EmployeeInfo (name, empno, (float)salary);
    } catch (SQLException e) {
      throw new SQLError (e.getMessage ());
    }
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return this;
  }
}


jdbcimpl

readme.txt

Overview
========

This example demonstrates:

   - how to use JDBC calls on the server side to query
       data from the EMP table
   - how to return complex data to the client using an IDL struct/Java class.
   - handling SQLException exceptions on the server side and returning
       them as CORBA exceptions.


Source files
============

employee.idl
------------

The CORBA IDL for this example defines a struct, an exception, and one
interface.

module employee
  struct EmployeeInfo
    wstring name
    long number
    double salary

  exception SQLError
    wstring message

  interface Employee
    EmployeeInfo getEmployee (in wstring name) raises (SQLError)

The EmployeeInfo struct is defined to consist of a string for the
employee name, and two numerics for employee number and salary.

The SQLError exception returns SQL exceptions to the client
invoker.

The Employee interface defines a method that returns an EmployeeInfo
struct, and takes an employee name as its input parameter.


Client.java
-----------

Invoke the client program from a command prompt, and pass it four arguments,
the

   - service URL (service ID, hostname, port, and SID if port is a listener)
   - name of the published bean to lookup and instantiate
   - username
   - password that authenticates the client to the Oracle8i database server

For example:
% java -classpath LIBs Client sess_iiop://localhost:2222 /test/myHello scott 
tiger

where LIBs is the classpath that must include

$ORACLE_HOME/lib/aurora_client.jar
$ORACLE_HOME/jdbc/lib/classes111.zip
$ORACLE_HOME/lib/vbjorb.jar
$ORACLE_HOME/lib/vbjapp.jar
$JAVA_HOME/lib/classes.zip


The client code performs the following steps:

   - gets the arguments passed on the command line
   - creates a new JNDI Context (InitialContext())
   - looks up the published Employee CORBA server object to find and activate it
   - invokes the getEmployee() method, with the parameter "SCOTT", to
       return Scott's employee ID and salary
   - prints the result        
   - tries to use getEmployee("bogus") to return information about
       employee named bogus. This will fail, and return the SQLError
       exception, which is printed.

The printed output is:



employeeServer/EmployeeImpl.java
--------------------------------

This class implements the Employee interface. The getEmployee() method
gets access to the defatul server-side JDBC connection, then uses a
PreparedStatement to construct a query for EMPNO and SAL on the EMP
table. The query WHERE clause is constructed from the in parameter
ENAME.

The prepared statement is executed, and the information for the
(first) employee of that name is extracted from the result set, and
inserted into a new EmployeeInfo object, which is then returned to the
invoker.

Note the use of the finally {} clause to close the prepared statement,
which also closes the result set.



Client application output
=========================

The client application prints:

SCOTT 7788 3000.0
Error retrieving employee "bogus": no employee named bogus


Compiling and Running the Example
=================================



UNIX
----

Enter the command 'make all' or simply 'make' in the shell to compile,
load, and deploy the objects, and run the client program.  Other
targets are 'run' and 'clean'.

Make sure that a shell environment variable ORACLE_HOME is set to
point to the home location of the Oracle installation. This is
operating system dependent, so see the Installation documentation that
came with your system for the location. Also, review the README file
for the Oracle database, and the README file for the CORBA/EJB server
(the Oracle8i ORB), for additional up-to-date information.


Windows NT
----------

On Windows NT, run the batch file makeit.bat from a DOS command prompt
to compile, load, and deploy the objects. Run the batch file runit.bat
to run the client program, and see the results.


Make sure that the environment variables %ORACLE_HOME%, %CLASSPATH%,
and %SERVICE% are set appropriately for the DOS command window. You
can set these as either user or system environment variables from the
Control Panel. Double click on System in the Control Panel then on
the Environment tab to set these variables. Start a new DOS window
after setting environment variable values.


See the Installation documentation that came with your Oracle8i system
for the values of these variables. Also, review the README file for
the Oracle database, and the README file for the CORBA/EJB server (the
Oracle8i ORB), for additional up-to-date information.

You can also set an environment variable %JAVA_HOME% to point to the
root of your Java JDK. For example, SET JAVA_HOME=C:\JDK1.1.6.

employee.idl

module employee {
  struct EmployeeInfo {
    wstring name;
    long number;
    double salary; 
  };

  exception SQLError {
    wstring message;
  };

  interface Employee {
    EmployeeInfo getEmployee (in wstring name) raises (SQLError);
  };
};

Client.java

import employee.*;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class Client
{
  public static void main (String[] args) throws Exception {
    if (args.length != 4) {
      System.out.println ("usage: Client serviceURL objectName user password");
      System.exit (1);
    }
    String serviceURL = args [0];
    String objectName = args [1];
    String user = args [2];
    String password = args [3];

    Hashtable env = new Hashtable ();
    env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put (Context.SECURITY_PRINCIPAL, user);
    env.put (Context.SECURITY_CREDENTIALS, password);
    env.put (Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    Context ic = new InitialContext (env);

    try {
      Employee employee = (Employee)ic.lookup (serviceURL + objectName);
      EmployeeInfo info = employee.getEmployee ("SCOTT");
      System.out.println (info.name + " " + info.number + " " + info.salary);
      // This one will fail and raise a SQLError exception
      EmployeeInfo info2 = employee.getEmployee ("bogus");
    } catch (SQLError e) {
      System.out.println ("Error retrieving employee \"bogus\": " + e.message);
    }
  }
}

employeeServer/EmployeeImpl.java

package employeeServer;

import employee.*;
import oracle.aurora.AuroraServices.ActivatableObject;
import java.sql.*;

public class EmployeeImpl 
       extends _EmployeeImplBase 
       implements ActivatableObject 
{
  public EmployeeInfo getEmployee (String name) throws SQLError {
    try {
      Connection conn =
	new oracle.jdbc.driver.OracleDriver().defaultConnection ();
      PreparedStatement ps =
	conn.prepareStatement ("select empno, sal from emp where ename = ?");
      try {
	ps.setString (1, name);
	ResultSet rset = ps.executeQuery ();
	if (!rset.next ())
	  throw new SQLError ("no employee named " + name);
	return new EmployeeInfo (name, rset.getInt (1), rset.getFloat (2));
      } finally {
	ps.close ();
      }
    } catch (SQLException e) {
      throw new SQLError (e.getMessage ());
    }
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return this;
  }
}

factory

readme.txt

Overview
========

This example demonstrates a CORBA factory design pattern for a simple object.
It uses the orb.connect() method to register the transient (i.e. unnamed)
object created by the factory.


Source files
============

factory.idl
----------

The CORBA IDL that defines the server-side objects. It defines two interfaces:

interface Hello
  wstring helloWorld ()

interface HelloFactory {
  Hello create (in wstring message)

HelloFactory is used to create new Hello objects. The Hello object is
just the simple object, as in the helloworld example in this set, that
returns a greeting String to the client invoker. In this example, the
factory creates the object with a specified content.


Client.java
-----------

Invoke the client program from a command prompt, and pass it four arguments,
the

   - service URL (service ID, hostname, port, and SID if port is a listener)
   - name of the published bean to lookup and instantiate
   - username
   - password that authenticates the client to the Oracle8i database server

For example:
% java -classpath LIBs Client sess_iiop://localhost:2222 /test/myHello scott 
tiger

where LIBs is the classpath that must include

$ORACLE_HOME/lib/aurora_client.jar
$ORACLE_HOME/jdbc/lib/classes111.zip
$ORACLE_HOME/lib/vbjorb.jar
$ORACLE_HOME/lib/vbjapp.jar
$JAVA_HOME/lib/classes.zip


The client code performs the following steps:

   - gets the arguments passed on the command line
   - creates a new JNDI Context (InitialContext())
   - looks up the published HelloFactory CORBA server object to find and 
activate it
   - invokes the factory create() method twice to create two separate objects
       in the session. The create() method sets the greeting that is returned
   - on each object, invokes the helloWorld() method
   - prints the result        

The printed output is:

Hello World!
Goodbye World!



factoryServer/HelloFactoryImpl.java
-----------------------------------

This class implements the HelloFactory interface. It creates a new
Hello object (compare the Hello interface), and registers the new
object with the server-side Basic Object Adapter (BOA) using the
connect() method. connect() is the portable version of obj_is_ready().

The created object reference is then returned to the invoker.


factoryServer/HelloImpl.java
----------------------------

This class implements the Hello interface. It contains a public
constructor that saves the message, and one method, helloWorld(),
that returns the message passed in the constructor to the invoker.


Compiling and Running the Example
=================================


UNIX
----

Enter the command 'make all' or simply 'make' in the shell to compile,
load, and deploy the objects, and run the client program.  Other
targets are 'run' and 'clean'.

Make sure that a shell environment variable ORACLE_HOME is set to
point to the home location of the Oracle installation. This is
operating system dependent, so see the Installation documentation that
came with your system for the location. Also, review the README file
for the Oracle database, and the README file for the CORBA/EJB server
(the Oracle8i ORB), for additional up-to-date information.


Windows NT
----------

On Windows NT, run the batch file makeit.bat from a DOS command prompt
to compile, load, and deploy the objects. Run the batch file runit.bat
to run the client program, and see the results.


Make sure that the environment variables %ORACLE_HOME%, %CLASSPATH%,
and %SERVICE% are set appropriately for the DOS command window. You
can set these as either user or system environment variables from the
Control Panel. Double click on System in the Control Panel then on
the Environment tab to set these variables. Start a new DOS window
after setting environment variable values.


See the Installation documentation that came with your Oracle8i system
for the values of these variables. Also, review the README file for
the Oracle database, and the README file for the CORBA/EJB server (the
Oracle8i ORB), for additional up-to-date information.

You can also set an environment variable %JAVA_HOME% to point to the
root of your Java JDK. For example, SET JAVA_HOME=C:\JDK1.1.6.

factory.idl

module factory {
  interface Hello {
    wstring helloWorld ();
  };
  interface HelloFactory {
    Hello create (in wstring message);
  };
};

Client.java

import factory.*;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class Client
{
  public static void main (String[] args) throws Exception {
    if (args.length != 4) {
      System.out.println ("usage: Client serviceURL objectName user password");
      System.exit (1);
    }
    String serviceURL = args [0];
    String objectName = args [1];
    String user = args [2];
    String password = args [3];

    Hashtable env = new Hashtable ();
    env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put (Context.SECURITY_PRINCIPAL, user);
    env.put (Context.SECURITY_CREDENTIALS, password);
    env.put (Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    Context ic = new InitialContext (env);

    HelloFactory factory = (HelloFactory)ic.lookup (serviceURL + objectName);
    Hello hello = factory.create ("Hello World!");
    Hello hello2 = factory.create ("Goodbye World!");
    System.out.println (hello.helloWorld ());
    System.out.println (hello2.helloWorld ());
  }
}

factoryServer/HelloImpl.java

package factoryServer;

import factory.*;

public class HelloImpl extends _HelloImplBase
{
  String message;

  public HelloImpl (String message) {
    this.message = message;
  }

  public String helloWorld () {
    return message;
  }
}

factoryServer/HelloFactoryImpl.java

package factoryServer;

import factory.*;
import oracle.aurora.AuroraServices.ActivatableObject;

public class HelloFactoryImpl 
       extends _HelloFactoryImplBase 
       implements ActivatableObject 
{
  public Hello create (String message) {
    HelloImpl hello = new HelloImpl (message);
    _orb().connect (hello);
    return hello;
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return this;
  }
}

lookup

readme.txt

Overview
========

This example demonstrates:

    - using CORBA structs and sequences
    - one CORBA object invoking and calling another in the same session, 
        using 'thisSession' in the URL.
    - using the SQLJ translator for ease in implementing static SQL DML
        statements.
    - exception handling.


Source files
============

employee.idl
------------

The CORBA IDL for the example.  Defines:

EmployeeInfo struct
sequence of EmployeeInfo
DepartmentInfo struct, containing the sequence
SQLError CORBA exception
Employee interface
  getEmployees()
Department interface
  getDepartment()
 
The SQLError exception is used so that SQLException messages can 
be passed back to the client.  


Client.java
-----------

Invoke the client program from a command prompt, and pass it four arguments,
the

   - service URL (service ID, hostname, port, and SID if port is a listener)
   - name of the published bean to lookup and instantiate
   - username
   - password that authenticates the client to the Oracle8i database server

For example:
% java -classpath LIBs Client sess_iiop://localhost:2222 /test/myHello scott 
tiger

where LIBs is the classpath that must include

$ORACLE_HOME/lib/aurora_client.jar
$ORACLE_HOME/jdbc/lib/classes111.zip
$ORACLE_HOME/lib/vbjorb.jar
$ORACLE_HOME/lib/vbjapp.jar
$JAVA_HOME/lib/classes.zip


The client code performs the following steps:

   - gets the arguments passed on the command line
   - creates a new JNDI Context (InitialContext())
   - looks up the published Employee CORBA server object to find and activate it
   - looks up the published Department CORBA server object to find and activate 
it
   - invokes the getDepartment() method on it, passing in a department
       number. This method returns a DepartmentInfo struct (class), which
       contains information about the department plus a Java vector of
       employee names, ID numbers, and salaries for each employee in
       the specified department.
   - prints the returned information in a for(;;) loop, one iteration
       for each employee in the department

For the standard demo EMP and DEPT tables, the client prints:

RESEARCH 20 DALLAS
  SMITH 800.0
  JONES 2975.0
  SCOTT 3000.0
  ADAMS 1100.0
  FORD 3000.0


employeeServer/DepartmentImpl.sqlj
----------------------------------

Implements the IDL-specified Department interface.  The interface 
has one method, getDepartment(), that returns the information 
about the department and each of the employees in it.  The most 
interesting thing to note about this method is that it looks up 
and activates a second CORBA server object, that was published in 
the database as /test/myEmployee, and calls a method on it.  

Note that the employee object is activated *in the same session* 
through the use of the thisServer literal in the URL.

This method returns a DepartmentInfo struct.


employeeServer/EmployeeImpl.sqlj
--------------------------------

Implements the Employee interface.  There is one method -- 
getEmployees(). This method queries the EMP table, using a 
SQLJ named iterator, and returns an array of EmployeeInfo structs.
The caller (getDepartment()) combines the array returned by 
getEmployees() with the results of its own query for the 
department attributes, and returns all the information to the 
client program.

If the SQLJ code throws a SQLException, it is caught, and a 
CORBA-defined SQLError is thrown. This in turn would be 
propagated back to the client, where it is handled.



Compiling and Running the Example
=================================

Enter the command 'make all' or simply 'make' in the shell to compile,
load, and deploy the objects, and run the client program.  Other
targets are 'run' and 'clean'.

Make sure that a shell environment variable ORACLE_HOME is set to
point to the home location of the Oracle installation. This is
operating system dependent, so see the Installation documentation that
came with your system for the location. Also, review the README file
for the Oracle database, and the README file for the CORBA/EJB server
(the Oracle8i ORB), for additional up-to-date information.


Windows NT
----------

On Windows NT, run the batch file makeit.bat from a DOS command prompt
to compile, load, and deploy the objects. Run the batch file runit.bat
to run the client program, and see the results.


Make sure that the environment variables %ORACLE_HOME%, %CLASSPATH%,
and %SERVICE% are set appropriately for the DOS command window. You
can set these as either user or system environment variables from the
Control Panel. Double click on System in the Control Panel then on
the Environment tab to set these variables. Start a new DOS window
after setting environment variable values.


See the Installation documentation that came with your Oracle8i system
for the values of these variables. Also, review the README file for
the Oracle database, and the README file for the CORBA/EJB server (the
Oracle8i ORB), for additional up-to-date information.

You can also set an environment variable %JAVA_HOME% to point to the
root of your Java JDK. For example, SET JAVA_HOME=C:\JDK1.1.6.

employee.idl

module employee {
  struct EmployeeInfo {
    long empno;
    wstring ename;
    double sal; 
  };

  typedef sequence <EmployeeInfo> employeeInfos;

  struct DepartmentInfo {
    long deptno;
    wstring dname;
    wstring loc;
    EmployeeInfos employees;
  };

  exception SQLError {
    wstring message;
  };

  interface Employee {
    EmployeeInfos getEmployees (in long deptno) raises (SQLError);
  };

  interface Department {
    DepartmentInfo getDepartment (in long deptno) raises (SQLError);
  };
};

Client.java

import employee.*;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class Client
{
  public static void main (String[] args) throws Exception {
    if (args.length != 4) {
      System.out.println ("usage: Client serviceURL objectName user password");
      System.exit (1);
    }
    String serviceURL = args [0];
    String objectName = args [1];
    String user = args [2];
    String password = args [3];

    Hashtable env = new Hashtable ();
    env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put (Context.SECURITY_PRINCIPAL, user);
    env.put (Context.SECURITY_CREDENTIALS, password);
    env.put (Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    Context ic = new InitialContext (env);

    Department department = (Department) ic.lookup (serviceURL + objectName);
    DepartmentInfo info = department.getDepartment (20);
    System.out.println (info.dname + " " + info.deptno + " " + info.loc);

    EmployeeInfo[] infos = info.employees;
    int i;
    for (i = 0; i < infos.length; i++)
      System.out.println ("  " + infos[i].ename + " " + infos[i].sal);
  }
}

employeeServer/DepartmentImpl.sqlj

package employeeServer;

import employee.*;
import oracle.aurora.jndi.sess_iiop.ServiceCtx;
import oracle.aurora.AuroraServices.ActivatableObject;
import javax.naming.*;
import java.sql.*;
import java.util.*;

public class DepartmentImpl 
       extends _DepartmentImplBase 
       implements ActivatableObject 
{
  Employee employee = null;

  public DepartmentInfo getDepartment (int deptno) throws SQLError {
    try {
      if (employee == null) {
	Hashtable env = new Hashtable ();
	env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
	Context ic = new InitialContext (env);
	employee =
	  (Employee)ic.lookup ("sess_iiop://thisServer/test/myEmployee");
      }

      EmployeeInfo[] employees = employee.getEmployees (deptno);
      String dname;
      String loc;
      #sql { select dname, loc into :dname, :loc from dept
                    where deptno = :deptno };

      return new DepartmentInfo (deptno, dname, loc, employees);
    } catch (SQLException e) {
      throw new SQLError (e.getMessage ());
    } catch (NamingException e) {
      throw new SQLError ("Naming Exception: " + e.getMessage ());
    } 
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return this;
  }
}

employeeServer/EmployeeImpl.sqlj

package employeeServer;

import employee.*;
import oracle.aurora.AuroraServices.ActivatableObject;
import java.sql.*;
import java.util.Vector;

#sql iterator EmpIterator (int empno, String ename, double sal);

public class EmployeeImpl extends _EmployeeImplBase {
  public EmployeeInfo[] getEmployees (int deptno) throws SQLError {
    try {
      Vector vector = new Vector ();
      EmpIterator empit;
      #sql empit = { select empno, ename, sal from emp 
		            where deptno = :deptno };
      while (empit.next ())
	vector.addElement (new EmployeeInfo (empit.empno(), empit.ename(),
					     empit.sal()));
      empit.close ();
      EmployeeInfo[] result = new EmployeeInfo[vector.size ()];
      vector.copyInto (result);
      return result;
    } catch (SQLException e) {
      throw new SQLError (e.getMessage ());
    }
  }
}

callback

readme.txt

Overview
========

callback shows a CORBA server object that calls back to the client-side
object. It works by activating a new object in the client-side ORB, using the
Basic Object Adapter (BOA), and boa.obj_is_ready(), and sending a reference to
that object to the CORBA server object.



Source files
============

client.idl
----------

The CORBA IDL that defines the client-side object, that will be called
from the server.

interface Client
  wstring helloBack()


server.idl
----------

The CORBA IDL that defines the server-side object, that will be called
from the client, and that will in turn call back to the client.

interface Server
  wstring hello (in client::Client object)

Since the object is registered on the client side, and is not
published in the database, to perform a callback the server object
must have a reference to the client-side object. In this example, the
server is called with a reference to the object that has been
registered with the client-side Basic Object Adapter (BOA) as a
parameter.


Client.java
-----------

Invoke the client program from a command prompt, and pass it four arguments,
the

   - service URL (service ID, hostname, port, and SID if port is a listener)
   - name of the published bean to lookup and instantiate
   - username
   - password that authenticates the client to the Oracle8i database server

For example:

% java -classpath LIBs Client sess_iiop://localhost:2222 \
    /test/myHello scott tiger

where LIBs is the classpath that must include

$ORACLE_HOME/lib/aurora_client.jar
$ORACLE_HOME/jdbc/lib/classes111.zip
$ORACLE_HOME/lib/vbjorb.jar
$ORACLE_HOME/lib/vbjapp.jar
$JAVA_HOME/lib/classes.zip

The client code performs the following steps:

   - gets the arguments passed on the command line
   - creates a new JNDI Context (InitialContext())
   - looks up the published CORBA 'Server' object to find and activate it
   - starts up the ORB on the client system (ORB.init())
   - gets the basic object adapter object (BOA)
   - instantiates a new client callback object (new ClientImpl()), and
       registers it with the object adapater (boa.obj_is_ready(client))
   - invokes the hello() method on the server object, passing it the
       reference to the client callback object

It is important to do the lookup() before initializing the ORB on the Client
side: The lookup call initializes the ORB in a way that's compatible with
Oracle 8i.  The following org.omg.CORBA.ORB.init() call does not initialize a
new ORB instance but just returns the orb that was initialized by the lookup
call.

The client prints:

I Called back and got: Hello Client World!

which is the concatenation of the strings returned by the server
object, and the called-back client-side object.


serverServer/ServerImpl.java
----------------------------

This class implements the server interface. The code has one method, hello(),
which returns its own String ("I called back and got: ") plus the
String that it gets as the return from the callback to the client.


clientServer/ClientImpl.java
----------------------------

This class implements the client interface. It has a public constructor, which
is required, and a single method, helloBack(), which simply returns the String
"Hello Client World!" to the client that called it (the server object 'server'
in this case).



Compiling and Running the Example
=================================


UNIX
----

Enter the command 'make all' or simply 'make' in the shell to compile,
load, and deploy the objects, and run the client program.  Other
targets are 'run' and 'clean'.

Make sure that a shell environment variable ORACLE_HOME is set to
point to the home location of the Oracle installation. This is
operating system dependent, so see the Installation documentation that
came with your system for the location. Also, review the README file
for the Oracle database, and the README file for the CORBA/EJB server
(the Oracle8i ORB), for additional up-to-date information.


Windows NT
----------

On Windows NT, run the batch file makeit.bat from a DOS command prompt
to compile, load, and deploy the objects. Run the batch file runit.bat
to run the client program, and see the results.


Make sure that the environment variables %ORACLE_HOME%, %CLASSPATH%,
and %SERVICE% are set appropriately for the DOS command window. You
can set these as either user or system environment variables from the
Control Panel. Double click on System in the Control Panel then on
the Environment tab to set these variables. Start a new DOS window
after setting environment variable values.


See the Installation documentation that came with your Oracle8i system
for the values of these variables. Also, review the README file for
the Oracle database, and the README file for the CORBA/EJB server (the
Oracle8i ORB), for additional up-to-date information.

You can also set an environment variable %JAVA_HOME% to point to the
root of your Java JDK. For example, SET JAVA_HOME=C:\JDK1.1.6.

client.idl

module client {
  interface Client {
    wstring helloBack ();
  };
};

Client.java

import server.*;
import client.*;
import clientServer.*;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class Client
{
  public static void main (String[] args) throws Exception {
    if (args.length != 4) {
      System.out.println ("usage: Client serviceURL objectName user password");
      System.exit (1);
    }
    String serviceURL = args [0];
    String objectName = args [1];
    String user = args [2];
    String password = args [3];

    Hashtable env = new Hashtable ();
    env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put (Context.SECURITY_PRINCIPAL, user);
    env.put (Context.SECURITY_CREDENTIALS, password);
    env.put (Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    Context ic = new InitialContext (env);

    // Get the server object before preparing the client object
    // You have to do it in that order to get the ORB initialized correctly
    Server server = (Server)ic.lookup (serviceURL + objectName);

    // Create the client object and publish it to the orb in the client
    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init ();
    org.omg.CORBA.BOA boa = orb.BOA_init ();
    ClientImpl client = new ClientImpl ();
    boa.obj_is_ready (client);

    // Pass the client to the server that will call us back
    System.out.println (server.hello (client));
  }
}

server.idl

#include <client.idl>

module server {
  interface Server {
    wstring hello (in client::Client object);
  };
};

clientServer/ClientImpl.java

package clientServer;

import client.*;
import oracle.aurora.AuroraServices.ActivatableObject;

public class ClientImpl extends _ClientImplBase implements ActivatableObject 
{
  public String helloBack () {
    return "Hello Client World!";
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return this;
  }
}

serverServer/ServerImpl.java

package serverServer;

import server.*;
import client.*;
import oracle.aurora.AuroraServices.ActivatableObject;

public class ServerImpl extends _ServerImplBase implements ActivatableObject 
{
  public String hello (Client client) {
    return "I Called back and got: " + client.helloBack ();
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return this;
  }
}

printback

readme.txt

Overview
========

This example demonstrates how to write output to a file descriptor on the
client side from a CORBA server object.

This is a very handy technique for making output from a server object appear
on the console of the client. You can use it for debugging as well as other
informational purposes.


Source files
============

printer.idl
-----------

The IDL defines a byteArray as a sequence of octets, and one
interface, ByteStream, with write(), flush(), and close() methods.


interface ByteStream
  oneway void write(in byteArray bytes)
  oneway void flush()
  oneway void close()

Note that the methods are oneway, that is non-blocking.


hello.idl
---------

IDL to define the Hello interface.

interface Hello
  oneway void setup (in printer::ByteStream stream)
  void helloWorld ();


Client.java
-----------

The client code looks up and activates the CORBA server object
(hello), then initializes the client-side ORB and BOA, and registers a
new ByteStreamImpl object with the BOA.

The parameter for the ByteStreamImpl constructor is a FileOutputStream
object, with the out handle as its target.

The client then invokes the hello.setup() method, with the
BOA-registered ByteStream object as the parameter. This essentially
resets 'out' to point to the RemoteOutputStream class, which overrides
the write() and close() methods of the standard PrintStream that is
normally attached to 'out'. Now, when the a server object writes to
'out', the output is redirected to the client-side ByteStream object,
where it can be printed on the client console.

To test this, the client then invokes hello.helloWorld(), which prints
back to the client-side ByteStream.


printerServer/ByteStreamImpl.java
---------------------------------

This class implements the client-side printer service. It implements
write() method that gets invoked by the server-side CORBA object, and
writes to the client console.


helloServer/HelloImpl.java
--------------------------

This class implements the methods directly called by the client:
setup() and helloWorld().


printerClient/RemoteOutputStream.java
-------------------------------------

This class implements methods that override the standard PrintStream
write(), flush(), and close() methods, for use by the
HelloImpl.setup() method.


Client application output
=========================

The client application prints:

Hello World!
counting 0
counting 1
counting 2
counting 3
counting 4
counting 5
counting 6
counting 7
counting 8
counting 9
counting 10
counting 11
counting 12
counting 13
counting 14
counting 15
counting 16
counting 17
counting 18
counting 19

...(repeated 3 times, once for each client call to hello.helloWorld().



Compiling and Running the Example
=================================

UNIX
----

Enter the command 'make all' or simply 'make' in the shell to compile,
load, and deploy the objects, and run the client program.  Other
targets are 'run' and 'clean'.

Make sure that a shell environment variable ORACLE_HOME is set to
point to the home location of the Oracle installation. This is
operating system dependent, so see the Installation documentation that
came with your system for the location. Also, review the README file
for the Oracle database, and the README file for the CORBA/EJB server
(the Oracle8i ORB), for additional up-to-date information.


Windows NT
----------

On Windows NT, run the batch file makeit.bat from a DOS command prompt
to compile, load, and deploy the objects. Run the batch file runit.bat
to run the client program, and see the results.


Make sure that the environment variables %ORACLE_HOME%, %CLASSPATH%,
and %SERVICE% are set appropriately for the DOS command window. You
can set these as either user or system environment variables from the
Control Panel. Double click on System in the Control Panel then on
the Environment tab to set these variables. Start a new DOS window
after setting environment variable values.


See the Installation documentation that came with your Oracle8i system
for the values of these variables. Also, review the README file for
the Oracle database, and the README file for the CORBA/EJB server (the
Oracle8i ORB), for additional up-to-date information.

You can also set an environment variable %JAVA_HOME% to point to the
root of your Java JDK. For example, SET JAVA_HOME=C:\JDK1.1.6.

printer.idl

module printer {
  typedef sequence<octet> byteArray;
  interface ByteStream {
    oneway void write (in byteArray bytes);
    oneway void flush ();
    oneway void close ();
  };
};

hello.idl

#include <printer.idl>

module hello {
  interface Hello {
    oneway void setup (in printer::ByteStream stream);
    void helloWorld ();
  };
};

Client.java

import hello.*;
import printerServer.*;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;
import java.io.*;

public class Client
{
  public static void main (String[] args) throws Exception {
    if (args.length != 4) {
      System.out.println ("usage: Client serviceURL objectName user password");
      System.exit (1);
    }
    String serviceURL = args [0];
    String objectName = args [1];
    String user = args [2];
    String password = args [3];

    Hashtable env = new Hashtable ();
    env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put (Context.SECURITY_PRINCIPAL, user);
    env.put (Context.SECURITY_CREDENTIALS, password);
    env.put (Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    Context ic = new InitialContext (env);

    // Get the server object before preparing the client object
    // You have to do it in that order to get the ORB initialized correctly
    Hello hello = (Hello)ic.lookup (serviceURL + objectName);

    // Create the client object and publish it to the orb in the client
    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init ();
    org.omg.CORBA.BOA boa = orb.BOA_init ();
    ByteStreamImpl byte_stream =
      new ByteStreamImpl (new FileOutputStream (FileDescriptor.out));
    boa.obj_is_ready (byte_stream);

    // Pass the client to the server that will call us back
    hello.setup (byte_stream);
    hello.helloWorld ();
    hello.helloWorld ();
    hello.helloWorld ();
  }
}

printerClient/RemoteOutputStream.java

package printerClient;

import printer.ByteStream;

import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;

public class RemoteOutputStream extends OutputStream
{
  ByteStream remote;

  // Static entrypoint to make System.out and System.err use the
  // remote stream.
  public static void setStreams (ByteStream remote) {
    OutputStream os = new RemoteOutputStream (remote);
    PrintStream p = new PrintStream (os, true);
    System.setOut (p);
    System.setErr (p);
  }

  public RemoteOutputStream (ByteStream remote) {
    this.remote = remote;
  }

  public void write (int b) { 
    byte[] buf = { (byte)b };
    write (buf);
  }

  public void write (byte b[]) {
    remote.write (b);
  }

  public void write (byte buf[], int off, int count) {
    if (off == 0 && count == buf.length)
      write (buf);
    else if (off >= 0 && off < buf.length && count > 0) {
      byte[] temp = new byte [count];
      System.arraycopy (buf, off, temp, 0, count);
      write (temp);
    }
  }

  public void flush () {
    //    remote.flush ();
  }

  public void close () {
    remote.close ();
  }
}

helloServer/HelloImpl.java

package helloServer;

import hello.*;
import printer.*;
import printerClient.*;
import java.io.PrintStream;

import oracle.aurora.AuroraServices.ActivatableObject;

public class HelloImpl extends _HelloImplBase implements ActivatableObject 
{
  PrintStream out;
  ByteStream remote;

  public HelloImpl () {
    super ();
    out = null;
  }

  public void setup (ByteStream remote) {
    this.remote = remote;
    out = new PrintStream (new RemoteOutputStream (remote));
  }

  public void helloWorld () {
    if (out != null){
      out.println ("Hello World!");
      int i;
      for (i = 0; i < 20; i++)
	out.println ("counting " + i);
    }
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return this;
  }
}

printerServer/ByteStreamImpl.java

package printerServer;

import java.io.OutputStream;
import java.io.IOException;

public class ByteStreamImpl extends printer._ByteStreamImplBase
{
  OutputStream stream;

  public ByteStreamImpl (OutputStream stream) {
    super ();
    this.stream = stream;
  }

  public void write (byte[] bytes) {
    try {
      stream.write (bytes);
    } catch (IOException e) {}
  }

  public void flush () {
    try {
      stream.flush ();
    } catch (IOException e) {}
  }

  public void close () {
    try {
      stream.close ();
    } catch (IOException e) {}
  }
}

tieimpl

readme.txt

Overview
========

This is a CORBA TIE (delegation) implementation of the helloworld example. See
the readme for that example for more information. It uses the
_initializeAuroraObject() method to return a class delegate, rather than the
object itself.


Source files
============

hello.idl
------------

(See the helloworld example readme file.)


Client.java
-----------

(See the helloworld example readme file.)


helloServer/HelloImpl.java
--------------------------

Implements the IDL-specified Hello interface. The interface has one
method, helloWorld(), that returns a String to the caller.

Note that the class definition *implements* the IDL-generated
HelloOperations interface, rather than extending _HelloImplBase, as in
the helloworld example.

The class also implements the Aurora ActivateableObject
interface. ActivatableObject has only one method:
_initializeAuroraObject(), which returns the class to be activated by
the BOA.

This class performs no database access.


Client-side output
==================

The client prints the returned String "Hello World!" and then exits
immediately.


Compiling and Running the Example
=================================


UNIX
----

Enter the command 'make all' or simply 'make' in the shell to compile,
load, and deploy the objects, and run the client program.  Other
targets are 'run' and 'clean'.

Make sure that a shell environment variable ORACLE_HOME is set to
point to the home location of the Oracle installation. This is
operating system dependent, so see the Installation documentation that
came with your system for the location. Also, review the README file
for the Oracle database, and the README file for the CORBA/EJB server
(the Oracle8i ORB), for additional up-to-date information.


Windows NT
----------

On Windows NT, run the batch file makeit.bat from a DOS command prompt
to compile, load, and deploy the objects. Run the batch file runit.bat
to run the client program, and see the results.


Make sure that the environment variables %ORACLE_HOME%, %CLASSPATH%,
and %SERVICE% are set appropriately for the DOS command window. You
can set these as either user or system environment variables from the
Control Panel. Double click on System in the Control Panel then on
the Environment tab to set these variables. Start a new DOS window
after setting environment variable values.


See the Installation documentation that came with your Oracle8i system
for the values of these variables. Also, review the README file for
the Oracle database, and the README file for the CORBA/EJB server (the
Oracle8i ORB), for additional up-to-date information.

You can also set an environment variable %JAVA_HOME% to point to the
root of your Java JDK. For example, SET JAVA_HOME=C:\JDK1.1.6.

hello.idl

module hello {
  interface Hello {
    wstring helloWorld ();
  };
};

Client.java

import hello.Hello;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class Client
{
  public static void main (String[] args) throws Exception {
    if (args.length != 4) {
      System.out.println ("usage: Client serviceURL objectName user password");
      System.exit (1);
    }
    String serviceURL = args [0];
    String objectName = args [1];
    String user = args [2];
    String password = args [3];

    Hashtable env = new Hashtable ();
    env.put (Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put (Context.SECURITY_PRINCIPAL, user);
    env.put (Context.SECURITY_CREDENTIALS, password);
    env.put (Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);
    Context ic = new InitialContext (env);

    Hello hello = (Hello)ic.lookup (serviceURL + objectName);
    System.out.println (hello.helloWorld ());
  }
}

helloServer/HelloImpl.java

package helloServer;

import hello.*;
import oracle.aurora.AuroraServices.ActivatableObject;

public class HelloImpl implements HelloOperations, ActivatableObject 
{
  public String helloWorld () {
    return "Hello World!";
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return new _tie_Hello (this);
  }
}

bank

readme.txt

bank demonstrates:

This is an Oracle8i-compatible version of the VisiBroker Bank
example. The major differences from the Vb example are:

(1) There is no server main loop. For Oracle8i the
"wait-for-activation" loop is part of the IIOP presentation (MTS
server).

(2) _boa.connect(object) is used instead of the less portable
 _boa_obj_is_ready(object) in the server object implementation to
register the new Account objects.

(3) The client program contains the code necessary to lookup the
AccountManager object (published under /test/myBank) and activate it,
and to authenticate the client to the server. (Note that object
activation and authentication, via NON_SSL_LOGIN, happen "under the
covers" so to speak on the lookup() method invocation.)

(4) There is also a tie implementation of this example, with the
server being AccountManagerImplTie.java.

Bank.idl

// Bank.idl

module Bank {
  interface Account {
    float balance();
  };
  interface AccountManager {
    Account open(in string name);
  };
};
		  

Client.java

// Client.java

import bankServer.*;
import Bank.*;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class Client
{
  public static void main (String[] args) throws Exception {
    if (args.length != 5) {
      System.out.println("usage: Client serviceURL objectName user password "
			 + "accountName");
      System.exit(1);
    }
    String serviceURL = args [0];
    String objectName = args [1];
    String user = args [2];
    String password = args [3];
    String name = args [4];

    Hashtable env = new Hashtable();
    env.put(Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put(Context.SECURITY_PRINCIPAL, user);
    env.put(Context.SECURITY_CREDENTIALS, password);
    env.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);

    Context ic = new InitialContext(env);

    AccountManager manager =
      (AccountManager)ic.lookup (serviceURL + objectName);

    // Request the account manager to open a named account.
    Bank.Account account = manager.open(name);

    // Get the balance of the account.
    float balance = account.balance();

    // Print out the balance.
    System.out.println
      ("The balance in " + name + "'s account is $" + balance);
  }
}

bankServer/AccountImpl.java

// AccountImpl.java
package bankServer;

public class AccountImpl extends Bank._AccountImplBase {
  public AccountImpl(float balance) {
    _balance = balance;
  }
  public float balance() {
    return _balance;
  }
  private float _balance;
}

bankServer/AccountManagerImpl.java

package bankServer;

import java.util.*;

public class AccountManagerImpl
  extends Bank._AccountManagerImplBase {

  public synchronized Bank.Account open(String name) {

    // Lookup the account in the account dictionary.
    Bank.Account account = (Bank.Account) _accounts.get(name);

    // If there was no account in the dictionary, create one.
    if(account == null) {

      // Make up the account's balance, between 0 and 1000 dollars.
      float balance = Math.abs(_random.nextInt()) % 100000 / 100f;

      // Create the account implementation, given the balance.
      account = new AccountImpl(balance);

      _orb().connect(account);

      // Print out the new account.
      // This just goes to the system trace file for Oracle 8i.
      System.out.println("Created " + name + "'s account: " + account);

      // Save the account in the account dictionary.
      _accounts.put(name, account);
    }
    // Return the account.
    return account;
  }

  private Dictionary _accounts = new Hashtable();
  private Random _random = new Random();

}

bankServer/AccountManagerImplTie.java

package bankServer;

import java.util.*;
import oracle.aurora.AuroraServices.ActivatableObject;


public class AccountManagerImplTie
  implements Bank.AccountManagerOperations, 
  ActivatableObject {


  public synchronized Bank.Account open(String name) {

    // Lookup the account in the account dictionary.
    Bank.Account account = (Bank.Account) _accounts.get(name);

    // If there was no account in the dictionary, create one.
    if(account == null) {

      // Make up the account's balance, between 0 and 1000 dollars.
      float balance = Math.abs(_random.nextInt()) % 100000 / 100f;

      // Create the account implementation, given the balance.
      account = new AccountImpl(balance);

      org.omg.CORBA.ORB.init().BOA_init().obj_is_ready(account);

      // Print out the new account.
      // This just goes to the system trace file for Oracle 8i.
      System.out.println("Created " + name + "'s account: " + account);

      // Save the account in the account dictionary.
      _accounts.put(name, account);
    }
    // Return the account.
    return account;
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    return new Bank._tie_AccountManager(this);
  }

  private Dictionary _accounts = new Hashtable();
  private Random _random = new Random();

}

pureCorba

Bank.idl

// Bank.idl

module Bank {
  interface Account { float balance(); };
  interface AccountManager { Account open(in string name); };
};
		  

Client.java

import java.lang.Exception;

import org.omg.CORBA.Object;
import org.omg.CORBA.SystemException;
import org.omg.CosNaming.NameComponent;

import oracle.aurora.client.Login;
import oracle.aurora.AuroraServices.LoginServer;
import oracle.aurora.AuroraServices.LoginServerHelper;
import oracle.aurora.AuroraServices.PublishedObject;
import oracle.aurora.AuroraServices.PublishingContext;
import oracle.aurora.AuroraServices.PublishedObjectHelper;

import Bank.Account;
import Bank.AccountManager;
import Bank.AccountManagerHelper;

public class Client {
  public static void main(String args[]) throws Exception {
    // Parse the args
    if (args.length != 5) {
      System.out.println ("usage: Client host port sid username password");
      System.exit(1);
    }
    String host = args[0];
    int    port = Integer.parseInt (args[1]);
    String sid  = args[2];
    String username = args[3];
    String password = args[4];

    // Declarations for an account and manager
    Account account = null;
    AccountManager manager = null;

    // access the Aurora Names Service
    try {
      // Get the Name service Object reference (Only ORB specific thing)
      PublishingContext rootCtx = null;
      rootCtx = VisiAurora.getNameService (host, port, sid);
      
      // Get the pre-published login object reference
      PublishedObject loginPubObj = null;    
      LoginServer serv = null;
      NameComponent[] nameComponent = new NameComponent[2];
      nameComponent[0] = new NameComponent ("etc", "");
      nameComponent[1] = new NameComponent ("login", "");

      // Lookup this object in the Name service
      Object loginCorbaObj = rootCtx.resolve (nameComponent);

      // Make sure it is a published object
      loginPubObj = PublishedObjectHelper.narrow (loginCorbaObj);

      // create and activate this object (non-standard call)
      loginCorbaObj = loginPubObj.activate_no_helper ();
      serv = LoginServerHelper.narrow (loginCorbaObj);
      
      // Create a client login proxy object and authenticate to the DB
      Login login = new Login (serv);
      login.authenticate (username, password, null);
      
      // Now create and get the bank object reference
      PublishedObject bankPubObj = null;
      nameComponent[0] = new NameComponent ("test", "");
      nameComponent[1] = new NameComponent ("bank", "");

      // Lookup this object in the name service
      Object bankCorbaObj = rootCtx.resolve (nameComponent);

      // Make sure it is a published object
      bankPubObj = PublishedObjectHelper.narrow (bankCorbaObj);

      // create and activate this object (non-standard call)
      bankCorbaObj = bankPubObj.activate_no_helper ();
      manager = AccountManagerHelper.narrow (bankCorbaObj);
      
      account = manager.open ("Jack.B.Quick");

      float balance = account.balance ();
      System.out.println ("The balance in Jack.B.Quick's account is $" 
                          + balance);      
    } catch (SystemException e) {
      System.out.println ("Caught System Exception: " + e);
      e.printStackTrace ();            
    } catch (Exception e) {
      System.out.println ("Caught Unknown Exception: " + e);
      e.printStackTrace ();            
    }
  }
}

VisiAurora.java

import java.lang.Exception;
import java.net.UnknownHostException;
import java.net.InetAddress;
import java.util.Properties;

// CORBA specific imports
import org.omg.CORBA.Object;
import org.omg.CORBA.InitialReferences;
import org.omg.CORBA.InitialReferencesHelper;
import org.omg.CORBA.SystemException;

// Visigenic specific imports
import com.visigenic.vbroker.orb.ORB;
import com.visigenic.vbroker.orb.GiopOutputStream;
import com.visigenic.vbroker.GIOP.Version;
import com.visigenic.vbroker.IOP.IOR;
import com.visigenic.vbroker.IOP.TaggedComponent;
import com.visigenic.vbroker.IOP.TaggedProfile;
import com.visigenic.vbroker.IOP.TAG_INTERNET_IOP;
import com.visigenic.vbroker.IIOP_1_1.ProfileBody;
import com.visigenic.vbroker.IIOP_1_1.ProfileBodyHelper;

// Oracle specific imports
import oracle.aurora.AuroraServices.PublishingContext;
import oracle.aurora.AuroraServices.PublishingContextHelper;
import oracle.aurora.sess_iiop.orb_dep.TAG_SESSION_IOP;
import oracle.aurora.sess_iiop.orb_dep.ComponentBody;
import oracle.aurora.sess_iiop.orb_dep.ComponentBodyHelper;

public class VisiAurora {
  public static PublishingContext getNameService (String host, int port, 
						  String sid) 
  {
    PublishingContext nameServiceCtx = null;
    try {
      // Get the Boot service object reference
      Object initRefObj = getBootIOR (host, port, sid);
      InitialReferences initRef = InitialReferencesHelper.narrow (initRefObj);
      
      // get the oracle CosName service reference
      Object nsObj = initRef.get ("NameService");
      nameServiceCtx = PublishingContextHelper.narrow (nsObj);
    } catch (SystemException e) {
      System.out.println ("Caught System Exception: " + e);
      e.printStackTrace ();		  	    
    } catch (Exception e) {
      System.out.println ("Caught Unknown Exception: " + e);
      e.printStackTrace ();		  	    
    }
    return nameServiceCtx;
  }

  public static Object getBootIOR (String host, int port, String sid) 
       throws UnknownHostException 
  {
    // NOTE: 1. if you wish to use sess_iiop then comment-out pt.#2, 
    //          and #4 below and initialize the ORB using the following:
    Properties props = new Properties ();
    props.put ("ORBServices", "oracle.aurora.sess_iiop.orb_dep");
    ORB visiORB = (ORB) org.omg.CORBA.ORB.init ((String[]) null, props);

    // NOTE: 2. if you wish to use iiop then comment-out pt.#1 and #3 
    //          and initialize the ORB using the following line:
    // ORB visiORB = (ORB) org.omg.CORBA.ORB.init ();

    // common to both (sess_iiop and iiop)
    String ipAddr = InetAddress.getByName (host).getHostAddress ();
    Version version = new Version ((byte)1, (byte)1);

    ComponentBody sessionBody =
      new ComponentBody ("ORCL", 0, visiORB.getLocalHost (), 
			 new byte[] {});
    GiopOutputStream output = visiORB.newGiopOutputStream ();

    output.byteOrder (visiORB.JAVA_ENDIAN);
    output.write_boolean (visiORB.JAVA_ENDIAN);
    ComponentBodyHelper.write (output, sessionBody);

    TaggedComponent component =
      new TaggedComponent (TAG_SESSION_IOP.value, output.toByteArray ());
    TaggedComponent[] taggedComponents = { component };

    byte[] objectKey = getObjectKey (sid);

    ProfileBody profileBody = new 
      ProfileBody (version, ipAddr, (short)port, objectKey, 
		   taggedComponents);

    output.offset (0);
    output.byteOrder (visiORB.JAVA_ENDIAN);
    output.write_boolean (visiORB.JAVA_ENDIAN);

    ProfileBodyHelper.write (output, profileBody);
    byte[] profileData = output.toByteArray ();
    TaggedProfile  profile = 
      new TaggedProfile (TAG_INTERNET_IOP.value, profileData);
    TaggedProfile[] taggedProfiles = { profile };

    return visiORB.iorToObject (new IOR ("IDL:CORBA/InitialReferences:1.0", 
					 taggedProfiles));
  }

  public static byte [] getObjectKey (String sid) 
  {
    String preSID = new String ("ORCL(CONNECT_DATA=(SID=");

    // NOTE: 3. if you wish to use sess_iiop then comment out pt.#1
    //          and #4, and use the following postSID:
    String postSID = new String (")(SESSION_ID=0))");
    // NOTE: 4. if you wish to use iiop then comment out pt.#1 and #3
    //          above and use the following postSID:
    // String postSID = new String ("))");
    
    // common to both (sess_iiop and iiop)
    String preINIT = new String (preSID + sid + postSID);

    byte[] b1 = new byte [preINIT.length () + 1];

    System.arraycopy (preINIT.getBytes (), 0, b1, 0, preINIT.length ());
    b1 [preINIT.length ()] = 0;

    String initString = new String ("INIT");
    byte[] objectKey = new byte [b1.length + initString.length ()];
    System.arraycopy (b1, 0, objectKey, 0, b1.length);
    System.arraycopy (initString.getBytes (), 0, objectKey, b1.length, 
		      initString.length ());

    return objectKey;
  }
}

bankServer/AccountImpl.java

package bankServer;

import Bank.*;

public class AccountImpl extends _AccountImplBase {
  private float _balance;

  public AccountImpl () { _balance = (float) 100000.00; }
  public AccountImpl (float balance) { _balance = balance; }        
  public float balance () { return _balance; }        
}

bankServer/AccountManagerImpl.java

package bankServer;

// import the idl-generated classes
import Bank.*;

import java.util.Dictionary;
import java.util.Random;
import java.util.Hashtable;

// Corba specific imports
import org.omg.CORBA.Object;

// Aurora-orb specific imports
import oracle.aurora.AuroraServices.ActivatableObject;

public class AccountManagerImpl
       extends _AccountManagerImplBase
       implements ActivatableObject
{
  private Dictionary _accounts = new Hashtable ();
  private Random _random = new Random ();

  // Constructors
  public AccountManagerImpl () { super (); }        
  public AccountManagerImpl (String name) { super (name); }        

  public Object  _initializeAuroraObject () {
    return new AccountManagerImpl ("BankManager");
  }

  public synchronized Account open (String name) {
    // Lookup the account in the account dictionary.
    Account account = (Account) _accounts.get (name);

    // If there was no account in the dictionary, create one.
    if (account == null) {
      // Make up the account's balance, between 0 and 1000 dollars.
      float balance = Math.abs (_random.nextInt ()) % 100000 / 100f;

      // Create the account implementation, given the balance.
      account = new AccountImpl (balance);

      // Make the object available to the ORB.
      _orb ().connect (account);

      // Print out the new account.
      System.out.println ("Created " + name + "'s account: " + account);

      // Save the account in the account dictionary.
      _accounts.put (name, account);
    }

    // Return the account.
    return account;
  }
}






Prev

Top

Next
Oracle
Copyright © 1999 Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index