Portable Bank
The Portable Bank example has a simple Bank interface to open a
bank account and to query the balance in a bank account. It illustrates
basic communication using the ORB and how to write portable CORBA applications
in Java. The OMG IDL/Java language mapping specifies a source and
binary compatiblity layer between user applications and ORB implementations.
By writing applications and applets which use only the standard APIs the
application's byte code will run on any compliant ORB implementation such
as VisiBroker for Java or JavaIDL from JavaSoft.
NOTE: This example makes use of new classes in the java.io package
of JDK 1.1.x and will not run in a JDK 1.0.x environment.
From this example, you will learn how to:
-
Implement a simple interface
-
Implement a portable server using the inheritance mechanism
-
Implement a portable client application and applet
Directory Contents
-
Bank.idl
IDL interface for the Bank object.
-
Server.java
Bank server. Creates an instance of the Bank and calls org.omg.CORBA.ORB.connect()to
make this object available to client programs. The Bank Server implementation
implements two methods: open, which opens a bank account, and
balance, which returns the balance in a person's account whose
name is provided as input (by generating a random number).
-
AccountImpl.java
Account Object implementation. This program contains the implementation
of the Account object and is part of the Bank Server described above.
-
AccountManagerImpl.java
Account Manager Implementation. This program contains the implementation
of the Account Manager object and is part of the Bank Server described
above.
-
Client.java
This is the Bank client. It binds to the AccountManager object
and invokes open() to open a bank account. It then invokes balance()
on the account object reference obtained to query the balance.
-
ClientApplet.java
This is the Bank Client Applet.
-
ClientApplet.html
This is the html file to download the ClientApplet.
-
Makefile (vbmake.bat on Windows): Used to build all the test targets.
Building this example
Typing make (or vbmake on Windows) in the portable_bank
subdirectory will cause the Bank.idl to be run through
the idl2java compiler. It will also build the following classes for the
examples described above:
-
Server.class
-
Client.class
-
ClientApplet.class
Compilation Warnings
You will see the following compilation errors when you type make
(vbmake on Windows) in the bank subdirectory
or when you explicitly compile Client.java
using JDK1.0.2:
prompt>javac ClientApplet.java
Client.java:13: Class LineNumberReader not found in type declaration.
LineNumberReader input =
^
Client.java:14: Class FileReader not found in new.
new LineNumberReader(new FileReader("bank.ior"));
^
Client.java:15: Class LineNumberReader not found in void main(java.lang.String[]).
org.omg.CORBA.Object object = orb.string_to_object(input.readLine());
^
Client.java:18: Exception java.io.IOException is never thrown in the body of the corresponding try statement.
catch(java.io.IOException e) {
^
The above errors occur because the class that is being used by this example
is not part of JDK1.0.2. The solution to this problem is to upgrade to
JDK1.1.0 or higher.
Running this example
To run the examples, first make sure that the VisiBroker Smart Agent (osagent
executable) is running on your network. Then start the bank server using
the command:
prompt> vbj Server &
(start vbj Server on Windows)
// make the server run in the background
Next, open a user's bank account and query the balance in the account using
the command
prompt> vbj Client john
or
prompt> vbj Client
// uses a default name
or you could use a Java-enabled browser and load ClientApplet.html
Return to the top-level examples page.