Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 

Dynamic Stock Example


by MageLang Institute

[Magercise | API Docs | Short Course| Magercises]

Help is available for each task.



    Task 1

    [Modify IDL file] First edit the IDL file. The StockObjects module in the IDL file defines the interface to a stock object. But there is currently no way for a client to create stock objects. You need to add another interface, StockFactory that has a single operation to create a stock and return a reference to the created stock. The create operation should take two string parameters: one giving the stock symbol and the other giving a description of the company.


    The interface to add is:

    interface StockFactory {
        Stock create_stock(
                in string symbol,
                in string description
        );
    };
    

    Task 2

    [Run IDL Compiler] At the command line, run the IDL compiler to generate Java code from the IDL file.
    Sun JavaIDL idltojava -fno-cpp stock.idl
    Inprise VisiBroker idl2java stock.idl

    Task 3

    [Compile the generated Java code] Now compile the generated Java code using the standard Java compiler. Compile it in the generated StockObjects directory.

    Sun JavaIDL javac *.java
    Inprise VisiBroker vbjc *.java


    Task 4

    [Examine the generated Java files] All the files will be generated into the StockObjects directory because the IDL file defines a module StockObjects. (The purpose of each file is described in more detail in the course notes.)

    Look carefully at the file StockFactory.java - - this is the interface that you will have to implement.

    Task 5

    [Implement the stock factory] The skeleton code file we have given you, StockFactoryImpl.java has most of the implementation you will need. To finish, add a body to the method create_stock.


    An appropriate method body for the create_stock operation is:
    public Stock create_stock(
        String symbol,String description){
        StockImpl newStock = 
          new StockImpl(symbol, description);
        return newStock;
    }
    

    Task 6

    [Create Server Class] Now look at the file DynamicStockServer.java. This class is a java application that starts up the orb, instantiates a StockFactoryImpl instance, connects it to the ORB, and prints out a stringified reference to it.

    There is nothing for you to do except look at the file. Look carefully at each line.

    Task 7

    [Create Client Class] In the file DynamicStockClient.java, you will find code to instantiate the orb, read in a stringified reference to the remote factory, and call the create_stock operation on it. Again, there is nothing for you to do except look at the file. Look carefully at each line.

    Task 8

    [Compile the program] Now compile the program using the standard Java compiler.

    Sun JavaIDL javac -classpath . *.java
    Inprise VisiBroker vbjc *.java


    Task 9

    [Run the Server program]

    The server needs to run as a separate process. In DOS/Windows, you will use the start command. In UNIX, you will use the & (ampersand).

    The Server outputs an IOR (or stringified reference) to a file and to the console for the Stock factory object it creates. The name of the file is passed as the first argument to the server.

    To run the server, use the normal java command. If you are using VisiBroker, you can use the vbj command instead. vbj is just like java, except it sets up the CLASSPATH variables automatically.

    Putting it all together:
    Sun JavaIDL java -cp . DynamicStockServer stockfactory.ior
    Inprise VisiBroker vbj DynamicStockServer stockfactory.ior


    Task 10

    [Run the Client program]

    The client reads the stringified object reference of the stock factory object created by your server. An file containing the stringified object reference is passed as the first argument to the client. The second and third arguments passed to the client is the stock symbol and company description of the stock to be created. Note the following commands are each on a single line.

    Sun JavaIDL java -cp . DynamicStockClient stockfactory.ior gii "Global Industries Inc."
    Inprise VisiBroker vbj DynamicStockClient stockfactory.ior gii "Global Industries Inc."


    Task 11

    [Kill the Server] Don't forget to kill the server.


Copyright © 1998-1999 MageLang Institute. All Rights Reserved.


[ This page was updated: 3-Dec-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.